Thread: Restoring DirectX interface after alt+tab

  1. #1
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195

    Restoring DirectX interface after alt+tab

    I am writing a DirectX class to wrap my graphics interface, but I need to be able to restore the interface after it is lost due to the user alt+tabbing to another application. I can detect the situation, and I am going to simply release the existing interface and create a new one, but I was wonderig if there is a better way.

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You must recreate the device and reset the device. Then you must re-create all managed assets. If you have a texture manager or a resource manager that will load from disk if the resource is not loaded then this process is nearly automatic. As the game engine requests textures and meshes your resource system hands them out and eventually everything that is needed for the game is slowly built back up.



    Code:
    ...
    ...
    GetApp()->getDevice()->SetTexture(0,GetApp()->getResMgr()->getTexture(MAIN_CHARACTER_MODEL);
    ...
    ...
    Now if getTexture() has code in it to load the texture from disk if it has not been loaded then all is well and you don't have to change any render code to handle lost devices. The only thing you have to do is write the code that actually catches the lost device condition and responds to it.
    Last edited by VirtualAce; 09-15-2008 at 04:45 PM.

  3. #3
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    well I tried
    Code:
    switch(this->device->Present(0 , 0 , 0 , 0)){
       case D3DERR_DEVICELOST: // application lost focus, reset
    
          while(this->device->Reset(&this->d3d_parameters) == D3DERR_DEVICELOST) Sleep(0);
          this->device->Release();
          this->d3d->Release();
          this->d3d = Direct3DCreate9(D3D_SDK_VERSION);
          this->d3d->CreateDevice(D3DADAPTER_DEFAULT , D3DDEVTYPE_HAL , hwnd , this->VertexProcessingMethod , &this->d3d_parameters , &this->device);
          break;
      default:
          break;
    }
    which does retake the screen, but there seems to be a conflict, as i get flashing pieces of the desktop or other appications. Right now all my application
    is doing is clearing the back buffer, there are no other resources created, I want to get the alt tab thing figured out before i start adding code to handle
    the meshes etc, so that i can add that into the alt tab handlign code as well where appropriate.
    Last edited by abachler; 09-16-2008 at 02:20 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get RSSI value, send to sensor, sensor receive package, repackage it?
    By techissue2008 in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-04-2009, 10:13 AM
  2. D3DX - ALT + TAB / Drawing stuff
    By Tonto in forum Game Programming
    Replies: 8
    Last Post: 10-31-2006, 09:04 PM
  3. Visual C++
    By Golffor1 in forum C++ Programming
    Replies: 1
    Last Post: 08-04-2003, 04:30 PM
  4. code for Alt + Tab keys
    By Sumir in forum Windows Programming
    Replies: 2
    Last Post: 10-12-2002, 03:49 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM