Page 1 of 1

Method Coordinate::isDependent(const SimTK::State& s) segfault

Posted: Wed May 09, 2018 9:24 am
by p4t0u
Hi, I've been using the OpenSim API for a while, but the method Coordinate::isDependent(const SimTK::State& s) segfaults because it can't find the definition for the method get_is_free_to_satisfy_constraints(). By doing a quick search, get_is_free_to_satisfy_constraints() is defined in the OpenSim GUI. Any thoughts?

Re: Method Coordinate::isDependent(const SimTK::State& s) segfault

Posted: Wed May 09, 2018 9:38 am
by chrisdembia
That function is defined in a macro in opensim-core: https://github.com/opensim-org/opensim- ... nate.h#L88

Can you provide:

- version of OpenSim
- interface (C++, Java, Matlab, Python)
- snippet of your code

A segfault is usually caused by trying to use a invalid memory address. Perhaps the Coordinate has been deleted.

Re: Method Coordinate::isDependent(const SimTK::State& s) segfault

Posted: Wed May 09, 2018 11:02 am
by p4t0u
Hi, I'm using OpenSim Release 3.3.0-win64VC13P on a C++ interface. I'll simplify my code to keep the major parts. Maybe there's some additional initialization required? Here's a simplified version of my OpenSim model parser.


Code: Select all

#include <OpenSim\OpenSim.h>
#include <OpenSim\Common\PropertyObjPtr.h>
#include <OpenSim\Simulation\SimbodyEngine\Coordinate.h>

// Read Model
OpenSim::Model osimModel = OpenSim::Model(absoluteFilePath, true);

// Initialize model and state
SimTK::State& modelState = osimModel.initSystem();

OpenSim::BodySet modelBodySet = osimModel.getBodySet();

for (int i = 0; i < modelBodySet.getSize(); ++i)
{
   OpenSim::Body ithModelBody = modelBodySet.get(i);

   if (ithModelBody.hasJoint())
   {
      for (int j = 0; j < ithModelBody.getJoint().getCoordinateSet().getSize(); ++j)
      {
          OpenSim::Coordinate ithJointCoordinate = ithModelBody.getJoint().getCoordinateSet().get(j);

          if (!ithJointCoordinate.isDependent(modelState)) // <---- here
             {
                ...
             }
        } 
    }
}    

Thank you,
Patrick Laurin

Re: Method Coordinate::isDependent(const SimTK::State& s) segfault

Posted: Wed May 09, 2018 11:06 am
by chrisdembia
The following line makes a copy:

Code: Select all

OpenSim::Body ithModelBody = modelBodySet.get(i);
You should instead assign to a const reference:

Code: Select all

const OpenSim::Body& ithModelBody = modelBodySet.get(i);
The same goes for the Coordinate.

If you are only reading information from the model, using getBodySet() and getCoordinateSet() is correct. If you plan on making changes to the model, use updBodySet() and updCoordinateSet() instead of the "get" variants.

Re: Method Coordinate::isDependent(const SimTK::State& s) segfault

Posted: Wed May 09, 2018 11:19 am
by p4t0u
Oh gosh... Sorry for wasting your time. Thank you very much though.


Patrick Laurin