Method Coordinate::isDependent(const SimTK::State& s) segfault
- Patrick Laurin
- Posts: 6
- Joined: Tue Mar 06, 2018 12:41 pm
Method Coordinate::isDependent(const SimTK::State& s) segfault
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?
- Christopher Dembia
- Posts: 506
- Joined: Fri Oct 12, 2012 4:09 pm
Re: Method Coordinate::isDependent(const SimTK::State& s) segfault
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.
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.
- Patrick Laurin
- Posts: 6
- Joined: Tue Mar 06, 2018 12:41 pm
Re: Method Coordinate::isDependent(const SimTK::State& s) segfault
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.
Thank you,
Patrick Laurin
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
- Christopher Dembia
- Posts: 506
- Joined: Fri Oct 12, 2012 4:09 pm
Re: Method Coordinate::isDependent(const SimTK::State& s) segfault
The following line makes a copy:
You should instead assign to a const reference:
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.
Code: Select all
OpenSim::Body ithModelBody = modelBodySet.get(i);
Code: Select all
const OpenSim::Body& ithModelBody = modelBodySet.get(i);
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.
- Patrick Laurin
- Posts: 6
- Joined: Tue Mar 06, 2018 12:41 pm
Re: Method Coordinate::isDependent(const SimTK::State& s) segfault
Oh gosh... Sorry for wasting your time. Thank you very much though.
Patrick Laurin
Patrick Laurin