Skip to main content
GameDev.net gamedev.net
🔒 Locked

Texture release problem

Started by borso Feb 15, 2012 at 11:01 AM 2 replies 3.3k views
Original Post
borso
borso
Hi!

I'm writing a directx 9 renderer and I've run into this problem: when a IDirect3D9Texture9 object is bound to an ID3DXEffect with SetTexture and the context is lost after a device reset, I can't release the texture successfully. Some unreleased memory block still stay and I can't reset the device. However, if I set the texture to NULL, I'm able to release it and everything works fine.

Is this a known thing, or I'm doing something horrible?

Thanks in advance!
borso
borso
I forgot to mention that the texture is a render target. I've the same problem with normal 2D textures and cube maps.
Evil Steve
Evil Steve
ID3DXEffect::SetTexture() increases the reference count of any texture set on it, so yes - you'll need to set the texture to NULL if you want to Release() it.

EDIT: You should also be calling ID3DXEffect::OnLostDevice() and ID3DXEffect::OnResetDevice(), which probably internally sets the textures to NULL anyway.
21st Century Moose
21st Century Moose
With render targets there is a second thing to be careful of - if you ever call GetSurfaceLevel on the texture (e.g. to use the texture in a SetRenderTarget call) you also need to Release the obtained surface interface when done otherwise that too will leak.
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.