Jump to content
  • Advertisement
Sign in to follow this  
TheSeb

"access violation" when i want to display an empty fullscreen(problem with device)

This topic is 4838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, when i put these lines in commentary i haven't this error : "Unhandled exception at 0x0040126e in loader3ds DX 9.0c.exe: 0xC0000005: Access violation reading location 0x00000000." this is the code which is indicated by visual c++ 7(do you think it really comes from here ?) : the line: myDirect3dApp->rendering();
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	myWindow = new manageWindow() ;
	direct3dApp *myDirect3dApp = new direct3dApp() ;

	myWindow->createWindow(hInstance);
	ShowCursor(FALSE);
	myDirect3dApp->deviceCreation();

	while(1)
	{
		MSG msg;
		if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		
		myDirect3dApp->rendering();


		if( myWindow->getCloseWindow() )
			return 0;
	}
}



void direct3dApp::rendering()
{
	myIDirect3DDevice9->Clear(0,  //Number of rectangles to clear, we're clearing everything so set it to 0
                          NULL, //Pointer to the rectangles to clear, NULL to clear whole display
                          D3DCLEAR_TARGET|D3DCLEAR_STENCIL|D3DCLEAR_ZBUFFER,   //What to clear.  We don't have a Z Buffer or Stencil Buffer
                          0x000000EE, //Colour to clear to (AARRGGBB)
                          1.0f,  //Value to clear ZBuffer to, doesn't matter since we don't have one
                          0 ); 
	myIDirect3DDevice9->BeginScene() ;
	myIDirect3DDevice9->EndScene() ;
	myIDirect3DDevice9->Present(NULL, NULL, NULL, NULL);
}




[Edited by - TheSeb on August 17, 2005 5:33:08 PM]

Share this post


Link to post
Share on other sites
Advertisement
In addition to checking that the device is valid as ProgrammingNerd suggests, I'd put a breakpoint on the "myDirect3dApp->rendering();" line and run the application in the debugger.

When the breakpoint fires, check what the value of "myDirect3dApp" is in the Autos window (or by hovering the cursor over the word); if the value of myDirect3dApp is 0, then something between the "new direct3dApp" and the first frame of rendering has set the myDirect3dApp pointer to 0.

If that's the case, I'd single step debug from the program start until that point to see where the problem is.


Without us seeing more code or you debugging the program some more, it's impossible to do any more than make guesses. I'll make two completely random guesses:

1) something in the window procedure does "delete myDirect3dApp" and "myDirect3dApp = NULL;" (or equivilent) in response to window message. It's doing it for the wrong messages or you have a missing break; statement.

2) something in deviceCreation(); sets myDirect3dApp to NULL upon failure to create device or something similar.

Share this post


Link to post
Share on other sites
If you are using vc++, you can set a breakpoint, and the hover the mouse cursor over the variable to see if it is valid, ie a non-null value. You can also use the FAILED and SUCCEEDED macros to determine if a function failed or not.

if(FAILED(...))
return E_FAIL;

Share this post


Link to post
Share on other sites
can you explain me how to see the datas of a break point ?


here is some code:


class direct3dApp
{
private :
//manageWindow myWindow ;
IDirect3D9 *D3dDevice ;//cré un device
IDirect3DDevice9 *myIDirect3DDevice9 ;
public:
direct3dApp();
void deviceCreation();
void rendering();
void freeD3d();//mettre un destructeur a la place

};

direct3dApp::direct3dApp()
{
D3dDevice=NULL;
myIDirect3DDevice9=NULL ;
D3dDevice = Direct3DCreate9(D3D_SDK_VERSION);
/*if(!D3dDevice)
{
//Handle error
}*/

}

void direct3dApp::deviceCreation()
{

D3DFORMAT format=D3DFMT_A8R8G8B8;//D3DFMT_R5G6B5;
D3DPRESENT_PARAMETERS presentParameters;
//IDirect3DDevice9 *d3dDevice=NULL;
HRESULT hResult;

//met à zéro tout les champs du pointeur sur structure
ZeroMemory(&presentParameters,sizeof(D3DPRESENT_PARAMETERS));

presentParameters.BackBufferCount= 1; //We only need a single back buffer
presentParameters.MultiSampleType=D3DMULTISAMPLE_NONE; //No multi-sampling
presentParameters.MultiSampleQuality=0; //No multi-sampling
presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD; // Throw away previous frames, we don't need them
presentParameters.hDeviceWindow = hWnd; //This is our main (and only) window
presentParameters.Flags=0; //No flags to set
presentParameters.FullScreen_RefreshRateInHz=D3DPRESENT_RATE_DEFAULT; //Default Refresh Rate
presentParameters.PresentationInterval=D3DPRESENT_INTERVAL_IMMEDIATE; // D3DPRESENT_INTERVAL_DEFAULT; limite le frame rate au refresh rate
presentParameters.BackBufferFormat=format; //Display format
presentParameters.EnableAutoDepthStencil=FALSE; //No depth/stencil buffer

hResult=D3dDevice->CreateDevice(D3DADAPTER_DEFAULT, //The default adapter, on a multi-monitor system
//there can be more than one.
D3DDEVTYPE_HAL, //Use hardware acceleration rather than the software renderer
//Our Window
hWnd,
//Process vertices in software. This is slower than in hardware,
//But will work on all graphics cards.
D3DCREATE_HARDWARE_VERTEXPROCESSING,
//Our D3DPRESENT_PARAMETERS structure, so it knows what we want to build
&presentParameters,//mettre le & si ça marche pas
//This will be set to point to the new device
&myIDirect3DDevice9);//mettre le & si ça marche pas
if(FAILED(hResult))
{}


/*if(is_app_fullscreen){
pp.Windowed = FALSE;
pp.BackBufferWidth = 640;
pp.BackBufferHeight = 480;
}else{
pp.Windowed = TRUE;
}*/


}

void direct3dApp::rendering()
{
myIDirect3DDevice9->Clear(0, //Number of rectangles to clear, we're clearing everything so set it to 0
NULL, //Pointer to the rectangles to clear, NULL to clear whole display
D3DCLEAR_TARGET|D3DCLEAR_STENCIL|D3DCLEAR_ZBUFFER, //What to clear. We don't have a Z Buffer or Stencil Buffer
0x000000EE, //Colour to clear to (AARRGGBB)
1.0f, //Value to clear ZBuffer to, doesn't matter since we don't have one
0 );
myIDirect3DDevice9->BeginScene() ;
myIDirect3DDevice9->EndScene() ;
myIDirect3DDevice9->Present(NULL, NULL, NULL, NULL);
}


Share this post


Link to post
Share on other sites
Quote:
Original post by TheSeb
can you explain me how to see the datas of a break point ?


Use the Watches functionality in VC (in the Debug menu, IIRC).

Share this post


Link to post
Share on other sites
IIRC ? i have inserted my breakpoint and after i don't know where to click (i don't see IIRC in the debug menu)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!