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;
}