Texture Release Problems
when I release mipmaped texture, need I traverse all the surface and release them?or just call: texture->release();
this puzzle comes from dx sdk on the [Texture Filtering with Mipmaps]page.
it provides a example:
--------------------------------------------------------------------------
IDirect3DSurface9 * pSurfaceLevel;
for (int iLevel = 0; iLevel < pMipMap->GetLevelCount(); iLevel++)
{
pMipMap->GetSurfaceLevel(iLevel, &pSurfaceLevel);
// Process this level
pSurfaceLevel->Release();
}
---------------------------------------------------------------------------
and some src I download from internet only release the texture directly.
so what is right?
thx in advance.
All the DX interfaces are MS COM interfaces; this standard defines how interfaces can be obtained and released. The basic rule is that you need to release any interface you obtain. In your case: if you do not obtain explicit interfaces to a texture's mipmaps, you don't have to release those.
For example: using just the texture without accessing its surfaces:
For example: using the texture and its mipmaps:
So for each call to GetSurfaceLevel(), which obtains an IDirect3DSurface9 interface, you need to call Release() on the interface. As long as Create/Get/AddRef and Release come in pairs you're ok.
Greetz,
Illco
For example: using just the texture without accessing its surfaces:
IDirect3DTexture9* texture = NULL;device->CreateTexture( ..., &texture );// do stufftexture->Release();texture = NULL;
For example: using the texture and its mipmaps:
IDirect3DTexture9* texture = NULL;device->CreateTexture( ..., &texture );IDirect3DSurface9 * pSurfaceLevel;for (int iLevel = 0; iLevel < texture ->GetLevelCount(); iLevel++){ texture->GetSurfaceLevel(iLevel, &pSurfaceLevel); // Process this level pSurfaceLevel->Release();}texture->Release();texture = NULL;
So for each call to GetSurfaceLevel(), which obtains an IDirect3DSurface9 interface, you need to call Release() on the interface. As long as Create/Get/AddRef and Release come in pairs you're ok.
Greetz,
Illco
I think the release means:
1st: refCount--;
2nd: if(refCount==0) delete obj;
right?
my question is :if I just release the texture when there is 1 ref to the texture(so it's deleted), will all the mipmap be released(deleted) either?
1st: refCount--;
2nd: if(refCount==0) delete obj;
right?
my question is :if I just release the texture when there is 1 ref to the texture(so it's deleted), will all the mipmap be released(deleted) either?
Quote:Original post by ccanan
I think the release means:
1st: refCount--;
2nd: if(refCount==0) delete obj;
right?
Yes. Kind of at least (i.e. I don't know what else they do but this is the right way to think about it).
Quote:Original post by ccanan
my question is :if I just release the texture when there is 1 ref to the texture(so it's deleted), will all the mipmap be released(deleted) either?
Well: no if you didn't obtain their interfaces (through GetSurfaceLevel() or other); otherwise (usual case) yes.
Illco
I think you're trying to work too hard, ccanan. If you didn't ever access the mipmap surfaces directly, they will take care of themselves. A good rule of thumb is to call Release() for each object you Create(), Get() or Load(). On destruction, a COM object will release everything it created, so unless you made it your business at any point, there's nothing to lose sleep over.
If you're unsure what to release and what not to, then run your app through under the debug runtime. Any attempts to release a dead object will give a runtime error, and any unreleased objects upon termination will be reported as a memory leak.
Regards
Admiral
If you're unsure what to release and what not to, then run your app through under the debug runtime. Any attempts to release a dead object will give a runtime error, and any unreleased objects upon termination will be reported as a memory leak.
Regards
Admiral
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement