Very odd one this.
Whenever the window of my program is fiddled with (i.e. resized, maximised, etc), it goes through a typical message processor to do all of that.
The problem I'm having is that when my program is running a certain part of the code, it crashes whenever I do anything to the window that requires the D3D device to be reset (specific crash details down below). The most irritating thing is that I can't work out what part of that section of the program causes this.
The program won't crash if I fiddle with the window when it first starts up - at this point, all I'm doing is looping a draw function that draws text on the screen using the regular DirectX DrawText() function of the ID3DXFont type, nothing else.
Once some controller setup is done, my program loops a different draw function that I'm working on now, drawing a single sprite onscreen using the Draw() function of the ID3DXSprite type, and that's
all it's drawing.
That's also the only difference in what code is being run between the point when resizing won't crash it and when it will. The same code to check and change the size of the window runs in either situation.
Here's a snippet. It's only part of it (specifically, the part that deals with minimising or maximising the window):
LRESULT D3DApp::msgProc(UINT msg, WPARAM wParam, LPARAM lParam)
{
// Is the application in a minimized or maximized state?
static bool minOrMaxed = false;
RECT clientRect = {0, 0, 0, 0};
switch( msg )
{
// WM_SIZE is sent when the user resizes the window
case WM_SIZE:
if( gd3dDevice )
{
md3dPP.BackBufferWidth = LOWORD(lParam);
md3dPP.BackBufferHeight = HIWORD(lParam);
if( wParam == SIZE_MINIMIZED )
{
mAppPaused = true;
minOrMaxed = true;
}
else if( wParam == SIZE_MAXIMIZED )
{
mAppPaused = false;
minOrMaxed = true;
onLostDevice();
gd3dDevice->Reset(&md3dPP);
onResetDevice();
}
To be more specific, the exact line it crashes on is (where gd3dDevice is a global pointer to the device itself, and md3dPP is the pointer to the presentation parameters):
gd3dDevice->Reset(&md3dPP);
And it crashes out with:
Quote:File:
Line: [whatever]
Error Code: D3DERR_INVALIDCALL (0x08876086c) <-- could be important to note this doesn't change
Calling: gd3dDevice->Reset(&md3dPP)
If I click No and make the program progess, it continues to stop in the same way at every single line where gd3dDevice is being called, with exactly the same error - and only those lines where gd3dDevice is being called.
I don't know why, all of a sudden, trying to reset or indeed do anything else to the device at the point where I'm drawing sprites onscreen makes for an invalid call. This is pretty much my 'learning DirectX' project, and I haven't got a clue why it's doing this, so any help at all would be appreciated.
This post is pretty long already, but I can post both the draw functions I mentioned above if anyone wants to see them, or indeed any other part of the code if it'll help. I'm not sure how much detail I need to give here.