Sign in to follow this  

Resizing and LPD3DXFONT causing BeginScene to fail every other time

This topic is 4692 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm making a game w/ DirectX 9 and C++. I just added some code to use some directx fonts along the lines of:
void Game::InitializeFonts() {
	HRESULT hr;

	HDC hDC;
	int nHeight;
	int nPointSize = 18;

	hDC = GetDC( NULL );

	nHeight = -( MulDiv( nPointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72 ) );
	hr = D3DXCreateFont( g_pd3dDevice, nHeight, 0, FW_BOLD, 0, FALSE, 
		                 DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 
		                 DEFAULT_PITCH | FF_DONTCARE, TEXT("Arial"), 
		                 &m_pd3dxFont );

}
and
RECT destRect1;
SetRect( &destRect1, 300, 300, 0, 0 );
m_pd3dxFont->DrawText( NULL,TEXT("Game Over. Press Any Key To Restart"), -1, &destRect1, DT_NOCLIP, D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f) );
but when I would resize, the BeginScene would fail with an error code of D3DERR_INVALIDCALL. But the really weird thing was that if I resized again, everything would go back to normal. My resize handling code is reseting the device and reinitializing the fonts and whatnot. So I finally tried adding a second call to the device's reset function and that fixed it.
g_pd3dDevice->Reset( &d3dpp );
g_pd3dDevice->Reset( &d3dpp );
InitializeRenderStates();
game->InitializeLights();
game->InitializeFonts();
game->Render();
But it's a total hack. Does anybody have an idea of why this might happen?

Share this post


Link to post
Share on other sites

This topic is 4692 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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