Skip to content
0
  • Recent
  • Tags
  • Popular
  • SAMSON Connect
  • Get SAMSON
  • Recent
  • Tags
  • Popular
  • SAMSON Connect
  • Get SAMSON
Collapse
SAMSON Forum
  1. Home
  2. Develop
  3. Simulation
  4. Bug in SBMInteractionModelParticleSystem?

Bug in SBMInteractionModelParticleSystem?

Scheduled Pinned Locked Moved Simulation
4 Posts 2 Posters 4.5k Views
  • 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
    K
    Khoa
    wrote on last edited by Khoa
    #1

    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
    0
    • StephaneS
      StephaneS
      Stephane
      wrote on last edited by Stephane
      #2

      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
      0
      • StephaneS 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
        K
        Khoa
        wrote on last edited by
        #3

        @stephane-redon It works. Thanks.

        1 Reply Last reply
        0
        • StephaneS
          StephaneS
          Stephane
          wrote on last edited by
          #4

          ok great!

          1 Reply Last reply
          0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Login or register to search.
          • First post
            Last post