Sign in to follow this  
dbh

Lost Device Recovery

Recommended Posts

dbh    166
Ah yes, another question about the infamous fun of reacquiring lost DX devices :x I've done my research, so I really just need confirmation from someone. This MSDN Link says that:
Quote:
If the device can be restored, the application prepares the device by destroying all video-memory resources and any swap chains. Then, the application calls the IDirect3DDevice9::Reset method. Reset is the only method that has an effect when a device is lost, and is the only method by which an application can change the device from a lost to an operational state. Reset will fail unless the application releases all resources that are allocated in D3DPOOL_DEFAULT, including those created by the IDirect3DDevice9::CreateRenderTarget and IDirect3DDevice9::CreateDepthStencilSurface methods.
I am allocating 3 things using D3DPOOL_DEFAULT: 1. D3DXSPRITE objects. 2. Billboards (Quad Sprites created with a vertex buffer). 3. Point Sprites (also created with a vertex buffer). Are these the ONLY things I need to recreate in order to reset the lost device? What about my model class which contains a mesh with a LPDIRECT3DTEXTURE9, and several materials? Do I need to destroy those and recreate them as well? Thank you for any direction you can add to the subject, -dbh

Share this post


Link to post
Share on other sites
Armadon    1091
Good day dbh,
How are you doing?

The Problem
Device lost recovery of resources.

The Solution
Any and every resource created with the D3DPOOL_DEFAULT flag should be recreated on device reset.
The SDK docs are very clear on this.

"All video memory must be released before a device can be reset from a lost state to an operational state. This means that the application should release any swap chains created with CreateAdditionalSwapChain and any resources placed in the D3DPOOL_DEFAULT memory class."

I hope this helps buddy.
Take care.

Share this post


Link to post
Share on other sites
Nypyren    12074
The order goes something like this:

- Your code notices that the device is lost
- You have to release almost everything (some things aren't lost, but if you aren't sure, try releasing them anyway) that was created based on that device.
- You can NOW reset your device. If it fails, you probably forgot to release something you needed to.
- You now have to recreate all of those things you released ;_; If you can come up with a good resource management system, it will take a lot of the nightmare out of this.

You *don't* have to release/recreate anything that you created in the Managed pool. Some things don't have the option to be created in the managed pool, though :/

In my app, I load my textures and meshes in the managed pool, so I only have to release and recreate my Effects (shader-related objects).

Share this post


Link to post
Share on other sites
dbh    166
Right, I have all of that code no problem. And in response to Armadon: I can read. I posted the exact same information you responded with. I am aware of everything you said.

What I am still in the dark about is *WHAT* exactly to release and reload. Nypyren, you said-- if in doubt-- release and reload. Do you have any idea on what is counted in this category at all, or where I could go to do some more research?

I have put all of my explicitly created objects (D3DXSprites, and pointsprites which use a vertex buffer) in the D3DPOOL_MANAGED category, effectively ruling them out of the objects that need to be release/recreated.

But what about the creation of objects that are NOT explicitly placed in D3DPOOL_DEFAULT or D3DPOOL_MANAGED? Like LPDIRECT3DTEXTURE9 objects. You aren't given the choice of where these are stored... so does that mean they are automatically put into video memory, and therefore must be handled before and after resetting the D3DDevice?

I know how to release these objects, and I know how to recreate them. My resource manager can do it pretty quickly too without too much editing... I just would hate to have to release EVERYTHING and reload EVERYTHING, if all I really needed to do was, for example, free all my LPDIRECT3DTEXTURE9 resources and start again.

Can anyone shed some more detailed light on what I need to be releasing here?

-dbh

Share this post


Link to post
Share on other sites
dbh    166
As an example of what I mean...


// Load the mesh and check for errors:
hResult = D3DXLoadMeshFromX(filename.c_str(),
D3DXMESH_SYSTEMMEM,
device,
NULL,
&m_matBuffer,
NULL,
&m_numMaterials,
&m_mesh);


The above line is what I am using to load a .x mesh file with texture(s). Because I am using the SYSTEMMEM flag, it doesn't need to be released/recreated, does it?

Are there any other things I should look for? As it stands now, when I minimize my game and attempt to restore it-- the game doesn't ever get an D3D_OK from the reset call attempts, which means I am not releasing/recreating something that should be, right?

-dbh

Share this post


Link to post
Share on other sites
Muhammad Haggag    1358
Quote:
Original post by dbh
But what about the creation of objects that are NOT explicitly placed in D3DPOOL_DEFAULT or D3DPOOL_MANAGED? Like LPDIRECT3DTEXTURE9 objects. You aren't given the choice of where these are stored...

You are. IDirect3DDevice9::CreateTexture accepts a D3DPOOL parameter. D3DXCreateTextureFromFile is equivalent to a D3DXCreateTextureFromFileEx with D3DPOOL_MANAGED for the pool parameter.

Quote:
The above line is what I am using to load a .x mesh file with texture(s). Because I am using the SYSTEMMEM flag, it doesn't need to be released/recreated, does it?

Yes, the buffers won't need to be released and recreated. The function doesn't load textures, IIRC, only texture names - you have to load textures yourself. You should be creating the mesh in the managed pool, too, for better performance.

Share this post


Link to post
Share on other sites
dbh    166
Thanks for the info, Coder-- I wasn't aware of that default usage.

Hm... so it sounds to me like all of my resources (I've listed just about everything in this thread) are in the MANAGED pool...

so any idea why it isn't resetting?

-dbh

Share this post


Link to post
Share on other sites
Muhammad Haggag    1358
Quote:
Original post by dbh
Hm... so it sounds to me like all of my resources (I've listed just about everything in this thread) are in the MANAGED pool...

so any idea why it isn't resetting?

- A common cause for this is using ID3DXFont or similar D3DX functionality. Make sure you call OnLostDevice before resetting.
- Another one that is rather obvious is to make sure you can restore the device: TestCooperativeLevel returning NOTRESET.

Share this post


Link to post
Share on other sites
dbh    166
Okay, thanks again for your suggestions, Coder. I appreciate it :) I'm going to go back under the hood now and see what I can tinker with.

-dbh

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this