[Closed] SDK: Help with GW memory leaking?
This is a pretty obscure problem but I’ll ask anyways, in case someone has dealt with this before.
I have an SDK plugin that takes an input Bitmap Texture and draws it onto a triangle using a viewport Graphics Window object.
I get a BITMAPINFO* pointer by calling bi = tex->GetVPDisplayDIB(..);
Then I get a DWORD_PTR handle to that texture by calling texHandle = gw->getTextureHandle(bi);
Then when I'm done using the handle, I call gw->freeTextureHandle(texHandle );
.....but no matter when/where/how/why I call "freeTextureHandle", the memory allocated by "getTextureHandle" is never cleared. Since my plugin updates every frame, memory usage crawls up to many GBs within seconds.
Any SDK experts have an idea what's going on? The memory leak doesn't occur anywhere except when I make calls to 'getTextureHandle'. I clean up the BITMAPINFO object elsewhere and its memory gets cleared just fine.
if you use GetVPDisplayDIB you should have TexHandleMaker. by using MakeHandle you get TexHandle. to free TexHandle just use DeleteThis
(it’s an idea only. sorry, i can’t try it)
Unfortunately all of my code is running outside of typical display functionality…all the TexHandleMakers that get passed through normal display functions like GetVPDisplayDIB are custom inaccessible classes created by the max core that merely subclass the TexHandleMaker class. By default, all TexHandleMaker functions are pure virtual functions so I have no idea what their internal code is doing when they make handles.
Thanks anyways for the idea!
Edit: I forgot to mention, the TexHandleMaker I pass to GetVPDisplayDIB is a custom class that subclasses TexHandleMaker. All of its functions return NULL except for the BitmapToDIB function, whose code I got from another file in the SDK. Unfortunately none of the code for making/creating texture handles is found in the SDK…only converting a bitmap to a DIB. So while my TexHandleMaker performs fine in grabbing a DIB from a Texmap, it has no other functionality.
looking in the sdk the DIB function is called like this
texHandle = thmaker.MakeHandle(GetVPDisplayDIB(t,thmaker,texHandleValid));
return texHandle->GetHandle();
then cleaned up with
texHandle->DeleteThis();
Right, but the GraphicsWindow API doesn’t return a TexHandle*. It returns a DWORD_PTR.
I’m assuming since a TexHandle can create a DWORD_PTR itself, that internally that’s what the GraphicsWindow API is doing. But unfortunately it doesn’t return the TexHandle pointer, only the resulting DWORD_PTR.
So basically, the TexHandle that could be cleaned up with the DeleteThis function is never accessible by the person using the SDK, and the “freeTextureHandle” function doesn’t delete it properly.
that’s the trouble with bitmaps nothing is easy and always more work than you expect and boy do they eat memory !!!