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

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Patrick Laurin
Posts: 6
Joined: Tue Mar 06, 2018 12:41 pm

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

Post by Patrick Laurin » Wed May 09, 2018 9:24 am

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?

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

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

Post by Christopher Dembia » Wed May 09, 2018 9:38 am

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.

User avatar
Patrick Laurin
Posts: 6
Joined: Tue Mar 06, 2018 12:41 pm

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

Post by Patrick Laurin » Wed May 09, 2018 11:02 am

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

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

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

Post by Christopher Dembia » Wed May 09, 2018 11:06 am

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.

User avatar
Patrick Laurin
Posts: 6
Joined: Tue Mar 06, 2018 12:41 pm

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

Post by Patrick Laurin » Wed May 09, 2018 11:19 am

Oh gosh... Sorry for wasting your time. Thank you very much though.


Patrick Laurin

POST REPLY