Skip to main content
gamedev.net
🔒 Locked

Help me debug please!!!

Started by pdstatha Jul 22, 2002 at 9:15 AM 7 replies 1.3k views
Original Post
pdstatha
pdstatha
Can someone help me with this, I''m trying to debug my app and when I come to call the DrawScene method in WinMain i get "Unhandled exception in 000000xC: Access Violation" It then jumps to a line of code in "Direct3D.cpp"
void CDirect3D::Clear(DWORD dwColor)
{
	pDevice->Clear( 0, NULL, D3DCLEAR_TARGET, dwColor, 1.0f, 0);  //Points to this line!!!
} 
Heres what the relevant part of the main cpp file looks like
  void DrawScene()
{
	d3dWindow.Clear(D3DCOLOR_XRGB(0, 0, 0));
	d3dWindow.BeginScene();

	d3dWindow.EndScene();
	d3dWindow.Present();
}
int WINAPI WinMain(	HINSTANCE hInstance, 
					HINSTANCE hPrevInstance, 
					LPSTR lpCmdLine, 
					int nCmdShow) 
{

	window.makeWindow(hInstance,"Hardball","Hardball",0,0,800,600);
	
	Direct3DInit();

	while(1)
	{
		if (window.checkMsgs()==-1)
			break;

		// Quit if the users presses escape

		if (GetAsyncKeyState(VK_ESCAPE))
			PostQuitMessage(0);

		// Update the scene each frame

		UpdateScene();

		// Draw the scene each frame

		DrawScene();  //Crashes after next step over

	} 

	// Release Direct3D

	Direct3DRelease();


	return 0;
}   
What is the reason for this????
S1CA
S1CA
Use the debug Direct3D runtime and check your debug output (search the DirectX forum for how to do that).

My guess is the D3D device creation failed and the pDevice pointer is NULL (or set to 0xCCCCCCCC, 0xCDCDCDCD, 0xFDFDFDFD depending on which memory manager you''re using and how pDevice is stored).

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
pdstatha
pdstatha
I have th 8.1 SDK installed on my WinXP Pro machine, except I can't seem to find the DirectX debugger tool anywhere.

And when I select the following

Start->All Programs->Microsoft DirectX 8.1 SDK->Runtime Installs->Install Debug

It says that it completed succesfully (seems to do it instaneously) but I still can't find the tool!!!

And yes I have looked at the utilities!!!

EDIT: Well I do find one DxDiag.exe, but that seems to be for reporting problems to do with the actual DirectX Drivers, i.e. not my code.

[edited by - pdstatha on July 22, 2002 10:58:59 AM]
SuperMike
SuperMike
How are you trying to debug your code? If you are using MSDev, then after you compile ( F7 ), press ( F5 ). This will start you debugging. You may want to set a break point ( F9 ), on the first line of your DrawScene() function, before hitting F5. I agree with S1CA, that you most likely will see that pDevice is invalid.

edit: sorry, but d3dWindow will be invalid.

[edited by - supermike on July 22, 2002 11:08:33 AM]
pdstatha
pdstatha
You seem to be right about the Direct3DInit not succeeding, but why??? Small update


  bool Direct3DInit()
{
if(d3dWindow.Create(&window))
return true;
else
return false;
}

int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{

window.makeWindow(hInstance,"Hardball","Hardball",0,0,800,600);

if(!Direct3DInit())
MessageBox(NULL,"UHOH!","Error", NULL);
else
{
while(1)
{
if (window.checkMsgs()==-1)
break;

// Quit if the users presses escape

if (GetAsyncKeyState(VK_ESCAPE))
PostQuitMessage(0);

// Update the scene each frame

UpdateScene();

// Draw the scene each frame

DrawScene();
}

// Release Direct3D

Direct3DRelease();
}

return 0;
}


Heres my create function


  bool CDirect3D::Create(CWindow* fp_pWindow)
{
HRESULT hr;

pWindow = fp_pWindow;

// Create the IDirect3D object

pDirect3D = Direct3DCreate8(D3D_SDK_VERSION);
if (pDirect3D == NULL)
return false;

// Set up a structure for fullscreen

D3DDISPLAYMODE displayMode;
displayMode.Width = pWindow->getWidth();
displayMode.Height = pWindow->getHeight();
displayMode.RefreshRate = 0;
displayMode.Format = D3DFMT_R5G6B5;

// Setup the present parameters

D3DPRESENT_PARAMETERS presentParameters;
memset(&presentParameters, 0, sizeof(D3DPRESENT_PARAMETERS));

presentParameters.Windowed = FALSE;
presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
presentParameters.BackBufferFormat = displayMode.Format;
presentParameters.BackBufferWidth = displayMode.Width;
presentParameters.BackBufferHeight = displayMode.Height;

// Create the device

hr = pDirect3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
pWindow->getHandle(),D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&presentParameters, &pDevice);

if (FAILED(hr))
return false;

return true;
}


And the CDirect3D class


  class CDirect3D
{
public:
//Get functions

CWindow* getWindow();
IDirect3D8* getD3D();
IDirect3DDevice8* getD3DDevice();

//Set functions

void setWindow(CWindow* fp_Window);
void setD3D(IDirect3D8* fp_Direct3D);
void setD3DDevice(IDirect3DDevice8* fp_Device);

//Create objects

bool Create(CWindow *fp_pWindow);

//Release objects

bool Release();

//Clears the screen

void Clear(DWORD dwColor);

//Flips between the front and back buffers

void Present();

//Begins the scene

void BeginScene();

//Ends the scene

void EndScene();
protected:
CWindow* pWindow;

IDirect3D8* pDirect3D;
IDirect3DDevice8* pDevice;
};
SuperMike
SuperMike
Did you step into CDirect3D::Create() and see where you were returning?
pdstatha
pdstatha
Yup heres what happens in Create()


  
presentParameters.Windowed = FALSE; //Break point inserted here

presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
presentParameters.BackBufferFormat = displayMode.Format;
presentParameters.BackBufferWidth = displayMode.Width;
presentParameters.BackBufferHeight = displayMode.Height;


Steps over all of that just fine.


  
hr = pDirect3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
pWindow->getHandle(),D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&presentParameters, &pDevice);

if (FAILED(hr))
return false;
else
return true;
}


It seems to return false. After the return it steps to this piece of code.


  if(d3dWindow.Create(&window))
return true;
else
return false;


This also returns false indicating that the CreateDevice did not work correctly!!!

Thing I can''t figure out is why not???
S1CA
S1CA
Hmm, since you''re asking D3D to run fullscreen, then there are a few members of the PRESENT_PARAMETERS you''ve not filled in!

In particular, check:

FullScreen_RefreshRateInHz
FullScreen_PresentationInterval


Also ensure the window handle you''re passing to D3D is valid, and the window actually exists!


--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
pdstatha
pdstatha
DOH!!!!!!!!!!!!!!!!!!!

Me just realised me do something very dumb indeed.

I forgot to register the window class with RegisterClassEx

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.