Sign in to follow this  
Hannesnisula

D3D keeps running after I've terminated the thread + released the D3D stuff?

Recommended Posts

I noticed I got the error from D3D9: Direct3D9: (ERROR) :GetClientRect Failed ? It was trying to call LPDIRECT3DDEVICE9's function Present(); But my window has terminated. I have a function called Main() that looks like this
void Main()
{
	InitGame();

	//Main loop
	while(MsgCheck())
	{
		Input();
		Logic();
		Render();
	}

	QuitGame();

	return;
}
Which is called from WinMain(). MsgCheck looks like this
bool MsgCheck()
{
	while(PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE))
	{
		if(msg.message==WM_QUIT)
			return false;
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return true;
}

If I press the X button in the right cornor of the window, shouldn't it send a WM_QUIT message to the window and then it checks for WM_QUIT in the MsgCheck() function and if the message is WM_QUIT it returns false which causes the loop in Main() to fail thus running QuitGame() ? Where am I wrong?

Share this post


Link to post
Share on other sites
What does your message handler look like? When you close a window, you don't get WM_QUIT right away. You first get WM_CLOSE to indicate that the window is closing. If you pass it through to DefWindowProc, it will call DestroyWindow to destroy the window. If you don't call DefWindowProc, you'll have to do it yourself.

Once DestroyWindow is called, the window is actually destroyed. When this happens, you get the WM_DESTROY to indicate that your window is being destroyed. If you want your app to quit at this point, then you need to call PostQuitMessage(0) to indicate that your message loop should terminate. Only then will you get the WM_QUIT message you're waiting for.

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