Jump to content
  • Advertisement
Sign in to follow this  
stringa

Lost Device....everything works except for fonts

This topic is 3817 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

My device comes back after a lost device and the textures are rendered correctly. I treat the fonts just like I treat the sprite and for some reason, the game will not recover from the lost device when I'm drawing fonts. here's some code and I'm doing something wrong in one of these parts DirectX9

bool GraphicsRenderer::Update()
{
  // I will have to check for the lost device here
  // these all have return values that I'm not checking right now

  if(!RecoverFromLostDevice()) return false;

  m_SPM->ClearAndResort();

  m_hr = Clear();  
  if( FAILED( m_hr ) ) return false;

  m_hr = BeginRender();
  if( FAILED( m_hr ) ) return false;

  m_hr = RenderSpriteList();
  if( FAILED( m_hr ) ) return false;

  if( m_drawFPS ) DrawString();

  RenderText();

  //RenderWireRects();

  m_hr = EndRender();
  if( FAILED( m_hr ) ) return false;

  m_hr = Present();
  if( FAILED( m_hr ) ) return false;

  return true; // for now
}

bool GraphicsRenderer::Present()
{
  m_hr = m_device->Present(0, 0, 0, 0);

  if( FAILED( m_hr ) ) 
  {
    if(m_hr == D3DERR_DEVICELOST)
    {
      m_deviceLost = true;
      return false;
    }
  }
  return true;
}


bool GraphicsRenderer::RecoverFromLostDevice()
{
  //if( !m_deviceLost ) return true;

  // Lets check to see if we are ready to recover from the Lost Device
  if( m_deviceLost )
  {
    if(FAILED( m_hr = m_device->TestCooperativeLevel() ))
    {
      // The device is lost and cannot be reset
      if( m_hr == D3DERR_DEVICELOST )
      {
        m_sprite->OnLostDevice();
        m_line->OnLostDevice();
        m_d3dFont_small->OnLostDevice();
        m_d3dFont_medium->OnLostDevice();
        m_d3dFont_large->OnLostDevice();
        m_d3dFont_hearts->OnLostDevice();

        return false;
      }
        
      if( m_hr == D3DERR_DEVICENOTRESET )
      {
        // Nowe we need to invalidate the device object

        m_TM->InvalidateTextures(); // deletes all the current textures

        m_device->Reset( &m_d3dpp );
        
        m_sprite->OnResetDevice();
        
        m_line->OnResetDevice();

        m_d3dFont_small->OnResetDevice();
        m_d3dFont_medium->OnResetDevice();
        m_d3dFont_large-> OnResetDevice();
        m_d3dFont_hearts->OnResetDevice();
        
        m_TM->RecoverTextures( m_device ); // reallocates all the textues

        // Now we will setup the projections  for the camera
        SetupDeviceResources();
        
        return false;
      }
    }
  }
  else
    m_deviceLost = false;

  return true;

}

Share this post


Link to post
Share on other sites
Advertisement
This bit here looks strange:


m_TM->InvalidateTextures(); // deletes all the current textures


If you have any resources in D3DPOOL_DEFAULT, they should be releases before calling TestCooperativeState.

Share this post


Link to post
Share on other sites
I know I've had trouble with fonts and a lost device in the past. A solution I found that works is to call Release() on the LPD3DXFONT object and then recreate it once the device has been restored. Hope this helps...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!