Texture release problem

Started by
2 comments, last by 21st Century Moose 12 years, 2 months ago
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!
Advertisement
I forgot to mention that the texture is a render target. I've the same problem with normal 2D textures and cube maps.
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.
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.

This topic is closed to new replies.

Advertisement