Resizing and LPD3DXFONT causing BeginScene to fail every other time

Started by
0 comments, last by xyzzy00 19 years, 2 months ago
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?
Advertisement
Call pFont->OnLostDevice() before you call Reset(), and pFont->OnResetDevice() afterwards.

xyzzy

This topic is closed to new replies.

Advertisement