Sign in to follow this  
johnnyBravo

What to do with LPDIRECT3DTEXTURE9 and LPDIRECT3DSURFACE9 on lost device?

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
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

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