Bug in SBMInteractionModelParticleSystem?
-
I have
- MyInteractionModel which inherits SBMInteractionModelParticleSystem, and
- MyInteractionModelFactory which inherits SBGInteractionModelParticleSystemFactory
In MyInteractionModelFactory, I have a function which overrides the parent class function as follows:
MyInteractionModel * MyInteractionModelFactory ::create(SBParticleSystem* particleSystem) { MyInteractionModel *interactionModel = new MyInteractionModel(particleSystem); interactionModel->initializeInteractions(); if (!interactionModel->setupOK) { delete interactionModel; return NULL; } return interactionModel; }
I had a crash at 'delete interactionModel;'
When debugging, I got "Access violation reading ...." exception. And the final break point is at the end of the destructor of MyInteractionModel. The destructor of MyInteractionModel is empty, i.e.
MyInteractionModel ::~MyInteractionModel () { }
It seems there is an attempt to delete a memory location which had not been allocated inside one of the parent classes of **MyInteractionModel **.
At the top of my stack, i see SBCReference. Perhaps, it is where the error comes from.
-
Can you please try with a SAMSON pointer (
SBPointer
) and let me know how it goes?Normally, any node that is a reference target (i.e. that directly or indrectly derives from
SBCReferenceTarget
) should be pointed at with a SAMSON pointer, and deleted with thedeleteReferenceTarget
function (cf this page).It should thus be:
MyInteractionModel * MyInteractionModelFactory::create(SBParticleSystem* particleSystem) { SBPointer<SBNode> interactionModel = new MyInteractionModel(particleSystem); interactionModel->initializeInteractions(); if (!interactionModel->setupOK) { interactionModel.deleteReferenceTarget(); return NULL; } return interactionModel(); }
-
@stephane-redon It works. Thanks.
-
ok great!