What to do with LPDIRECT3DTEXTURE9 and LPDIRECT3DSURFACE9 on lost device?

Started by
0 comments, last by Namethatnobodyelsetook 17 years, 1 month ago
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
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.

This topic is closed to new replies.

Advertisement