Page 1 of 1

GetDisplay cause a crash? Help!

PostPosted: Mar 30, 2003 @ 10:25pm
by telamon
I've been fiddling with PocketFrog over spring break, writing a little moon lander game. Overall I love the library - it's powerful and easy to use.

In my game I have a main menu screen and a game play scene and I think my state management between the two is buggy. Sometimes when the game is initializing the new level (which is randomly generated), it will crash when trying to get the display pointer. This, I don't really understand. Is there anytime after GameInit has been called that GetDisplay won't return a valid pointer? Has anyone run into similar problems? I'm hoping that a refactoring of the state management code will fix everything, but this has been one hell of a bug to track down - so any suggestions would be greatly appreciated. Thanks!!!

For reference

In my code, I'm trying to execute:
DisplayDevice* display = GetDisplay();
display->SetRenderTarget(m_landscape);
display->Clear( Color(0,0,0) );

Which sometimes will cause an exception here (and deeper in the display driver internals):
DisplayDevice* Game::GetDisplay()
{
DisplayDevice* display = m_display.get();

if (display)
display->BeginScene();

return display;
}

PostPosted: Mar 30, 2003 @ 11:02pm
by adde
You got to give us more to go on.. For instance, what sort of exception is thrown? And what line (action/function) caused this..

If I understood your post correctly, it's the display->Clear() that causes the exception, and that could be because the rendered target (m_landscape) is not valid.

I'm pretty shure it's not the GetDisplay() function that causes the error because all it does is return the pointer to the DisplayDevice object (and calls BeginScene() if the pointer is valid).

ARG...

PostPosted: Mar 31, 2003 @ 8:42am
by telamon
Actually, does appear that the GetDisplay function is the thing throwing the exception (it's a "first-chance exception" - an access violation). I took another crack at it today with the debugger, and when I openned up the Game object that my game inherits from, the m_display pointer in it was invalid! (The debugger had garbage information in all the m_display fields - I set a breakpoint at the place where the program crashes (it's only invalid sometimes) and when it doesn't crash, the m_display pointer in the Game object points to a valid DisplayDevice). In fact, the entire Game object that the this pointer in my code points to is bad. So it would seem that I somehow corrupted the internal state of the Game object. How could this possibly happen?

The actual thing that it doesn't like is the if test in:
void DisplayDevice::BeginScene()
{
if (!m_bInScene)
{
Pixel* pixels = m_driver->BeginScene();

// We set the video pointer each frame. Currently, I don't know of any
// device where the pointer can change while running, but you never
// know what will appear (ex: DMA transfers with multiple buffers).
m_GAPIBuffer->SetVideo( pixels );

m_bInScene = true;
}
}

PostPosted: Mar 31, 2003 @ 12:24pm
by adde