DrawText problem
I''ve added a frame rate to my app and I use ID3DXFont to display it. When I run the program it runs fine, but when I minimize the program by pressing alt+tab, then restore it it immediately crashes. If I take out the DrawText line then it works fine, so thats where the problem is. I''ve tried a couple different things, but I''m pretty new to DirectX so they were mostly guesses which never seem to work. Any ideas?
Thanks,
-Steve
This is my render functions:
[sourcee]
int Render()
{
HRESULT r = 0;
// Make sure the device is valid
if( !g_pDevice )
{
return E_FAIL;
}
// Return if the device is not ready;
r = ValidateDevice();
if( FAILED( r ) )
{
return E_FAIL;
}
g_pDevice->Clear( 0, 0, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0, 0, 0, 0 ), 1.0f, 0 );
FrameCount();
if( SUCCEEDED( g_pDevice->BeginScene() ) )
{
char string[4]; // String to hold the frame rate
ZeroMemory( &string, sizeof( string ) );
itoa( g_FrameRate, string, 10 );
RECT rc;
SetRect( &rc, 10, 10, 100, 500 );
g_pFont->DrawText( string, -1, &rc, DT_WORDBREAK, D3DCOLOR_ARGB(255, 255, 255, 255) );
g_pDevice->EndScene();
}
r = g_pDevice->Present( NULL, NULL, NULL, NULL );
return S_OK;
}
[/source]
If I take out g_pFont->DrawText( string, -1, &rc, DT_WORDBREAK, D3DCOLOR_ARGB(255, 255, 255, 255) );
then I can minimize and restore fine.
Thanks
[sourcee]
int Render()
{
HRESULT r = 0;
// Make sure the device is valid
if( !g_pDevice )
{
return E_FAIL;
}
// Return if the device is not ready;
r = ValidateDevice();
if( FAILED( r ) )
{
return E_FAIL;
}
g_pDevice->Clear( 0, 0, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0, 0, 0, 0 ), 1.0f, 0 );
FrameCount();
if( SUCCEEDED( g_pDevice->BeginScene() ) )
{
char string[4]; // String to hold the frame rate
ZeroMemory( &string, sizeof( string ) );
itoa( g_FrameRate, string, 10 );
RECT rc;
SetRect( &rc, 10, 10, 100, 500 );
g_pFont->DrawText( string, -1, &rc, DT_WORDBREAK, D3DCOLOR_ARGB(255, 255, 255, 255) );
g_pDevice->EndScene();
}
r = g_pDevice->Present( NULL, NULL, NULL, NULL );
return S_OK;
}
[/source]
If I take out g_pFont->DrawText( string, -1, &rc, DT_WORDBREAK, D3DCOLOR_ARGB(255, 255, 255, 255) );
then I can minimize and restore fine.
Thanks
Check the thing Endurion said, but if that does not work, try to create a bigger buffer for the string.
[How To Ask Questions|STL Programmer''s Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
[How To Ask Questions|STL Programmer''s Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
Make sure you are calling pFont->OnLostDevice when your device gets lost, and pFont->OnResetDevice when you successfully reset the device.
xyzzy
xyzzy
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement