Memory leak by with Gradient.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/10/2003 at 21:46, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 8.200
Platform: Windows ;
Language(s) : C++ ;---------
I implemented the Material plugin with Gradient.( code is written below )
Starting C4D, I created MyMaterial and then removed some knot from
the MyMaterial.s Gradient parameter.
After this, the Debug console showed memory leaks when closing C4D.
What's wrong?
/*Debug output messeage.
ge_mtl.cpp,57 -> 8 Bytes!
res_basecontain,2005 -> 24 Bytes!
2Blocks
*** Potential Memory Leak Detected ***
*/
class MyMaterial : public MaterialData
{
INSTANCEOF(MyMaterial,MaterialData)
private:
Gradient *m_grad;
public:
virtual Bool Init(GeListNode *node);
virtual void Free ( GeListNode *node ){};
virtual void CalcSurface(PluginMaterial *mat, VolumeData *vd);
virtual LONG InitRender(PluginMaterial *mat, InitRenderStruct *irs);
virtual void FreeRender(PluginMaterial *mat );
static NodeData *Alloc(void) { return gNew MyMaterial; }
};
Bool MyMaterial::Init( GeListNode *node )
{
BaseContainer* bc = ((PluginMaterial* )node)->GetDataInstance();
Gradient* gradient;
GradientKnot knot;
gradient = Gradient::Alloc();
for( LONG i = 0; i < 4; i++ )
{
knot.col = i * 1.0f / 3.0f;
knot.brightness = 1.0;
knot.pos = i * 1.0f / 3.0f;
knot.bias = 0.5;
knot.index = i;
gradient->InsertKnot( knot );
}
bc->SetData( M_GRADIENT, GeData( CUSTOMDATATYPE_GRADIENT, *gradient ) );
Gradient::Free( gradient );
return TRUE;
}
LONG MyMaterial::InitRender(PluginMaterial *mat, InitRenderStruct *irs)
{
BaseContainer *bc = mat->GetDataInstance();
if( m_grad = (Gradient* )bc->GetCustomDataType( M_GRADIENT, CUSTOMDATATYPE_GRADIENT ) )
if( !m_grad->InitRender() )
m_grad = NULL;
return LOAD_OK;
}
void MyMaterial::FreeRender(PluginMaterial *mat )
{
if( m_grad )
m_grad->FreeRender();
}
void MyMaterial::CalcSurface(PluginMaterial *mat, VolumeData *vd)
{
Vector color = 0.0;
if( m_grad )
color = m_grad->CalcGradientPixel( vd->n.x );
vd->col = color;
} -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/10/2003 at 11:55, xxxxxxxx wrote:
Hi,
first I would use AutoAlloc<Gradient> gradient1; It´s easier and you don´t have to care about memory freeing yourself. (and it works fine But I don´t really see anything that might cause a memory leak, so it might not be the part you have posted. Sometimes during rendering (and probably other situations) Cinema 4D cannot free up everything it allocated, so this might be it. ´
But it´s kinda late, so if I have overseen anything, do not kill me -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/10/2003 at 03:37, xxxxxxxx wrote:
Thanks for your quick response.
If it were not for wrong point in may code, maybe C4D
dose not free Memory. and I have to think alternative
method.
This Link is VC project file include Description file.
http://homepage3.nifty.com/nekoyama/plugin/MLTest.zip
MLTest.zip 212,992byte.