SAMSON Forum
    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • SAMSON Connect
    • Get SAMSON

    Bug in SBMInteractionModelParticleSystem?

    Simulation
    2
    4
    3148
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      Khoa last edited by Khoa

      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.

      1 Reply Last reply Reply Quote 0
      • Stephane
        Stephane last edited by Stephane

        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 the deleteReferenceTarget 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();
        }
        
        K 1 Reply Last reply Reply Quote 0
        • K
          Khoa @Stephane last edited by

          @stephane-redon It works. Thanks.

          1 Reply Last reply Reply Quote 0
          • Stephane
            Stephane last edited by

            ok great!

            1 Reply Last reply Reply Quote 0
            • First post
              Last post