Lost devices with meshes and textures

Started by
3 comments, last by cozzie 11 years, 2 months ago

Hi everyone,

I've managed to get some code running to handle lost devices - it works, in that the fullscreen program reloads and renders again, but it also causes the scene to look very strange (flat and disjointed with no alpha blending and a limited draw distance). So my question is - what exactly do I need to do with my mesh and texture resources when I reset the device? Fonts and things like that are OK because you can just use font->OnLostDevice() and font->OnResetDevice() to fix them. Do I need to release() the meshes and textures? How do I reload them?

Thanks a lot!

Advertisement

OK, never mind - I don't think I was resetting enough stuff! I made it so that my onResetDevice() function resets everything to the state it's set to when the device is created in the first place. i.e. I release() all the textures, meshes, etc... and I reload them again, reset the render states, lighting and the projection matrix - it all works fine!

Your solution is probably an overkill. You don't have to release and recreate any resource besides those placed in D3DPOOL_DEFAULT. Your meshes and textures will most probably be D3DPOOL_MANAGED and so you don't have to take care of them anyhow.

From your first post it's clear that your reset actually worked (in a way). That means you released all resources that had to be released, otherwise you wouldn't be able to reset the device at all, you would be getting errors.

From your explanation it's also quite clear that your only problem were transform matrices (SetTransform), which caused the geometry problems; and render states (SetRenderState) which caused non working alpha blending etc. And also lights (SetLight).

All these values must be set by you again because they are in the default state after device reset.

Setting these values after each device reset is very easy and fast. This hovewer isn't true for textures and models, creating them again can take a lot of time and IMHO it's not optimal to do it even if you really don't have to.

Thanks for the advice - I changed it as you suggested and it still works fine. Anything to increase efficiency! Thanks!

I agree on the possibility you're going in overkill.
I remember finding this ou and in the end all i had to do was;

When lost:
- release vertex declaration
- font.OnLostDevice
- d3dxeffects.OnLostDevice

Reset, and afterwards:
- Create and set vertex declaration
- recreate font
- d3dxeffects.OnResetDevice

Assuming your textures are in the managed pool.
I also first reloaded all my non d3d data/ objects of own classes which wasn't necessary.
Good luck,

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

This topic is closed to new replies.

Advertisement