Sign in to follow this  
Dospro

Debug vs Release with DirectX

Recommended Posts

Hi. I have a weird problem. I have a d3d application which draws a square using verts. The really strange thing is that if i run it in debug mode it works, it shos the square, but when i quit the program, it crashes in the device release() member. In the other hand if i run it in release mode the square just isnt showed, nothing appears. Why does it has different conducts in the realease and debug mode? Im obiously working with Vidual Studio .net 2002(but VS 6 gives me the same result.) Ill put some code where the misyake could be. This is the routine which frees DirectX objects: void do_finish(void) { if(d3dvb != NULL) d3dvb->Release(); if(d3ddev != NULL) d3ddev->Release(); if(d3dobj != NULL) d3dobj->Release(); } This is what happens each frame. I still cant make materials to work so im using vertex colors. void do_frame(void) { D3DMATERIAL9 d3dmat; memset(&d3dmat, 0, sizeof(d3dmat)); d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_RGBA(0xFF,0xFF,0xFF,255), 1.0f, 0); d3dmat.Diffuse.r=d3dmat.Ambient.r=1.0f; d3dmat.Diffuse.g=d3dmat.Ambient.g=1.0f; d3dmat.Diffuse.b=d3dmat.Ambient.b=0.0f; d3dmat.Diffuse.a=d3dmat.Ambient.a=1.0f; // Begin scene if(SUCCEEDED(d3ddev->BeginScene())) { // Set the vertex stream, shader, and texture d3ddev->SetStreamSource(0, d3dvb, 0, sizeof(sVertex)); d3ddev->SetFVF(VertexFVF); d3ddev->SetMaterial(&d3dmat); // Draw the vertex buffer d3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); // End the scene d3ddev->EndScene(); } // Display the scene d3ddev->Present(NULL, NULL, NULL, NULL); } There is also a common init routine which i think its not very important(if it is, tell me to post it). And here are my square verts. sVertex Verts[5] = { { 50.0f, 50.0f, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0, 0xFF, 0xFF)}, { 100.0f, 50.0f, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0, 0xFF,0xFF)}, { 50.0f, 100.0f, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0, 0xFF,0xFF)}, { 100.0f, 100.0f, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0,0xFF,0xFF)}, };

Share this post


Link to post
Share on other sites
Go ahead and post the init code. How are you closing the program? Does it behave differently if you click the X in the top right corner from when you hit ALT F4?

You're a step ahead of most in that you know how to change from debug to release, so this will be a stupid question, but did you have the output level on max debug?

EDIT: One other suggestion. Just to make sure that the device doesn't have any outstanding references, do this:
DWORD numRefLeft = d3ddev->Release();

Then step through that in the debugger and make sure the number is 0.

Chris

Share this post


Link to post
Share on other sites
Thanks for the suggestion.
Here is the init code, please tell me if there is an error, remember i still cant make materials to work.



void do_init(void)
{
D3DDISPLAYMODE d3ddm;
D3DPRESENT_PARAMETERS d3dpp;
unsigned char *ptr=NULL;
sVertex Verts[5] = {
{ 50.0f, 50.0f, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0, 0xFF, 0xFF)},
{ 100.0f, 50.0f, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0, 0xFF, 0xFF)},
{ 50.0f, 100.0f, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0, 0xFF, 0xFF)},
{ 100.0f, 100.0f, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0, 0xFF, 0xFF)},
};
d3dobj=Direct3DCreate9(D3D_SDK_VERSION);//Create the object
memset(&d3ddm, 0, sizeof(d3ddm));
d3dobj->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm);
memset(&d3dpp, 0, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.EnableAutoDepthStencil = FALSE;
d3dobj->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
d3ddev->CreateVertexBuffer(sizeof(sVertex)*4, 0, VertexFVF, D3DPOOL_DEFAULT, &d3dvb, NULL);
d3dvb->Lock(0, 0, (void**)&ptr, 0);
memcpy(ptr, Verts, sizeof(Verts));
d3dvb->Unlock();
}


Share this post


Link to post
Share on other sites
I think the 2 problems are unrelated. But as far as the square showing and not showing, I had a similar problem. Weird thing was when in release mode I couldnt see the triangles, untill I moved the camera, for some reason the starting location for debug and release mode was different for me. Try moving the square back some, or rotating it...

Also, you could just do a SAFE_RELEASE(...) on them, its the same thing essentially just looks nicer :). Also..

void do_finish(void)
{
if(d3dvb != NULL)
d3dvb->Release();
if(d3ddev != NULL)
d3ddev->Release();
if(d3dobj != NULL)
d3dobj->Release();
}


What are these? How do you declare them?

Share this post


Link to post
Share on other sites
Here are the declarations.

IDirect3D9 *d3dobj=NULL;
IDirect3DDevice9 *d3ddev=NULL;
IDirect3DVertexBuffer9 *d3dvb=NULL;
typedef struct {
FLOAT x, y, z, rhw;
D3DCOLOR dif;
}sVertex;
#define VertexFVF (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)

And still cant resolve any of the 2 problems.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this