Release/Restore D3DXSprite, textures on alt-tab

Started by
2 comments, last by roger_hq 19 years, 2 months ago
Hi, I'm developing an app with D3D9 and I'm encountering a little trouble with restoring the app after doing alt-tab. Currently, I have a wrapper for a D3D9Device called D3D9Graphics, and a wrapper for IDirect3DTexture9 called D3D9Texture, and a wrapper for D3DXSprite called D3D9Sprite. I initialize the graphics, a texture, and the sprite wrapper classes no problem. The draw to the screen in both full screen and windowed mode, everyone's happy. Now, D3D9Graphics has the ability to add observer objects, so that those observer objects can be notified when the D3D9Graphics object has lost or regained its device (OnGraphicsDeviceLost(), OnGraphicsDeviceRestored()). Observers can add themselves to the list of objects to be notified when the D3D9Graphics object has lost or gained its device, and the D3D9Texture object and D3D9Sprite object implement that interface, and add themselves as listeners to receive those events. So now, when I test cooperative level on EndScene() in D3D9Graphics, if I get a device lost, I notify all of my listeners (D3D9Texture and D3D9Sprite) that the device is lost, and when the device is regained, D3D9Texture and D3D9Sprite receive another notification that the device has been regained. So this is all well and good, both the D3D9Sprite and D3D9Texture do receive the notifications. Thats when I run into trouble. I am not certain on how to "correctly" release the sprite and texture classes and then "correctly" reset them. Currently, in the OnGraphicsDeviceLost() method, on the sprite object, I call m_D3DXSprite->OnLostDevice() and in the OnGraphicsDeviceRestored() method in the sprite object, I call m_D3DXSprite->OnResetDevice(), like this:

void D3D9Sprite::OnGraphicsDeviceLost()
{
   m_D3DXSprite->OnLostDevice();
}

void D3D9Sprite::OnGraphicsDeviceRestored(D3D9Graphics* g) 
{
   // g param is newly restored graphics wrapper
   m_D3DXSprite->OnResetDevice();
   
   // RxINC: do I release and null out the 
   // m_D3DXSprite pointer here and then re-init it?
   // m_D3DXSprite->Release();
   // m_D3DXSprite = NULL;
   // Init();  // Inits the sprite interface, also initially
               // called from the constructor
}
I do something similar for the D3D9Texture object, but IDirect3DTexture9 does not have a OnLost/ResetDevice function. So I'm a bit lost on how to reset that one properly. So I run the app, alt-tab, then try to re-alt-tab into it, and I get a lock-up. I check logs that I write out, and I'm getting into both my lost and restored handlers, but when I try to reset the device in the sprite class, I get the lock up. So my question is this: does this paradigm seem reasonable? How/why am I not restoring the D3DXSprite interface correctly? Is it important to restore the textures the sprite uses _before_ you restore the sprite (or vice versa)? whats the correct way to restore these objects after the graphics device has been restored? Thanks for any and all help?
_____________________________http://www.deepbluefuture.com"Set Phasers to neuter...""2+2=5 for sufficiently large values of 2."
Advertisement
The way you reset the sprite looks ok.
To make a texture reset itself after the device has been reset, you should pass D3DPOOL_MANAGED to the D3DXCreateTextureFromFile function (or whatever function you are using), or you could just pass D3DPOOL_DEFAULT, but you would have to release/re-init the texture yourself, plus it is slower.
So, are you saying that I DON'T have to do anything more than just say m_D3DXSprite->OnResetDevice()? I don't have to release and re-init it? And for the texture, if I use D3DPOOL_MANAGED, I don't have to do anything on my reset handler? That doesn't seem quite right... how does it know that it needs to be reloaded? How does it know where to find the bitmap for the texture?

Confused,

roger_hq
_____________________________http://www.deepbluefuture.com"Set Phasers to neuter...""2+2=5 for sufficiently large values of 2."

Ok, changing the pool to D3DPOOL_MANAGED definately fixed the issue. Thanks.

roger_hq
_____________________________http://www.deepbluefuture.com"Set Phasers to neuter...""2+2=5 for sufficiently large values of 2."

This topic is closed to new replies.

Advertisement