views:

50

answers:

3

I am just beginning to learn how to program DirectX 9 applications in C++, so I'm still not very good, and I'm messing it around quite a bit.

When I reopen the program after it crashes, the D3D Device fails to create with the result being D3DERR_INVALIDCALL. I am compiling with G++ in MinGW, using the DirectX August 2009 SDK. I'm guessing it's because I didnt release all the Devices and Textures etc when it crashes, and it still thinks I'm using them. It re-opens on a restart. Would someone be able to point me in the right direction as to how to sortof "reset" DirectX?

Here is what I am using to create the device:

D3D = Direct3DCreate9(D3D_SDK_VERSION);

D3DPRESENT_PARAMETERS D3DPP;
ZeroMemory(&D3DPP, sizeof(D3DPP));
D3DPP.Windowed = TRUE;
D3DPP.SwapEffect = D3DSWAPEFFECT_DISCARD;
D3DPP.hDeviceWindow = hWnd;
D3DPP.BackBufferFormat = D3DFMT_X8R8G8B8;
D3DPP.BackBufferWidth = WIDTH;
D3DPP.BackBufferHeight = HEIGHT;
D3DDevice = 0; //Null pointer to make sure I can check it
HRESULT hr = D3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &D3DPP, &D3DDevice);

if (!D3DDevice) {
    MessageBox(NULL,"Device could not be created","error",0);
    switch (hr) {
    case D3DERR_DEVICELOST: 
    MessageBox(NULL,"1","error",0);
    break;
    case D3DERR_INVALIDCALL: 
    MessageBox(NULL,"2","error",0);
    break;
    case D3DERR_NOTAVAILABLE: 
    MessageBox(NULL,"3","error",0);
    break;
    case D3DERR_OUTOFVIDEOMEMORY:
    MessageBox(NULL,"4","error",0);
    break;
    };
    return 1;
};
return 0;

Thanks.

A: 

Give us some code to look at and we might be able to help...

Mark Ingram
Sure, Some code has been added
A: 

Well I have to ask. Do you have a valid hWnd before you make the call?

Make sure it's valid and good things might happen. :-)

JustBoo
Sure, the hWnd exists. As I said, It works once, just when I open it again after it has "encountered a problem", it wont work.
And the hWnd is _still_ valid then?
JustBoo
A: 

It seems something in the MsgProc was causing the window to fail for the device, and my program to crash. Thanks anyway.