Destroy/Create instead of Reset

Started by
5 comments, last by sirob 18 years, 5 months ago
Hi, I'm using Direct3D 9 and I'm just setting myself up a system to restore a lost device. With the way that my system is built, it'd save time, effort and code if I just destroyed the device then recreated it, rather than calling Reset(). Is this ok to do, or does it have any disadvantages? Also, let's say that I have a D3DPOOL_DEFAULT image that I edit the pixels of by hand (with GetRenderTargetData/LockRect). Is there any way to stop the new image being lost when the device is lost? I thought about using D3DPOOL_MANAGED but it seems like there's a lot of stuff I can't do with it. Preferably I need some way to catch the device loss preliminarily, so I can transfer all of the images to system memory, then restore them when the device is restored. Cheers, Kris
Advertisement
Free the resources, reset the device, recreate the resources. It boggles my mind, because I never even thought of doing it any other way.

Second part, save the data into a texture file of some sort.
Insufficent Information: we need more infromationhttp://staff.samods.org/aiursrage2k/
Quote:Original post by Aiursrage2kIt boggles my mind, because I never even thought of doing it any other way.


don't be completely boggled. recreating the device actually does have some advantages. there are so many driver and system bugs with lost and resetting devices. for example check out the directx readme and you will see there is a bug with windows 2000 where after a lost device you can lock a buffer in agp and get back a bad pointer. this will crash your app if you don't try/except around it.

Quote:Original post by Kris_AIs there any way to stop the new image being lost when the device is lost? I thought about using D3DPOOL_MANAGED but it seems like there's a lot of stuff I can't do with it.
Preferably I need some way to catch the device loss preliminarily, so I can transfer all of the images to system memory, then restore them when the device is restored.


unfortunately no. once you find out the device is lost, all your resources are already gone. the only thing you can do is to keep a system memory copy of your texture. this winds up being just what the managed textures are though so you should take a second look at them.

Aha, thanks. I'll have another look at them, then.
So I take it, if I use managed textures then I won't be able to do use the destroy/create method?

Another thing : Can managed textures be drawn on?
well you could still destroy and recreate all the managed textures when you destroy and recreate the device, but resetting is really much more efficient. yeah you can update managed textures. just call LockRect. it's more expensive having to update the system mem copy and then having the vid mem copy updated also, but that's what you need in this case (and in most cases). for just about everything managed textures are the way to go.
Important notice though, that render targets can only be in the default pool.

If you plane on rendering to managed textures, you're either going to have to use LockRect() or find a different solution (default pool).
Sirob Yes.» - status: Work-O-Rama.

This topic is closed to new replies.

Advertisement