Jump to content
  • Advertisement
Sign in to follow this  
johnnyBravo

What to do with LPDIRECT3DTEXTURE9 and LPDIRECT3DSURFACE9 on lost device?

This topic is 4156 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've got my app to handle resizing or a lost d3d device, except I started rendering to a texture and now when i resize the screen it just stops drawing. I've tried releasing these and recreating them, but it crashes saying an access violation, and apart from that it still just stops rendering:
LPDIRECT3DTEXTURE9 pRenderTexture;
d3dDevice->CreateTexture(256,256,1,D3DUSAGE_RENDERTARGET,D3DFMT_R5G6B5,D3DPOOL_DEFAULT,&pRenderTexture,NULL);

LPDIRECT3DSURFACE9 pBackBuffer;
d3dDevice->GetRenderTarget(0,&pBackBuffer);

LPDIRECT3DSURFACE9 pRenderSurface;
pRenderTexture->GetSurfaceLevel(0,&pRenderSurface);

So is there some specific way of handling these types? Thanks

Share this post


Link to post
Share on other sites
Advertisement
You should release the render surface, release the render target, and SetRenderTarget back to the backbuffer, and release your backbuffer surface pointer.

I always release surfaces before releasing the textures that hold the surfaces. The API most likely keeps the reference counts nicely such that it doesn't matter about the order, but I've never actually tested that.

I'm not sure if you need to put the backbuffer back as the active render target, but I always do. This will ensure we don't have a stray reference to the rendertarget's surface, and that the backbuffer refcount is at it's expected values.

Aside from that, I'd use GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer), not GetRenderTarget.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!