Segfault on initSystem
- Matthew Millard
- Posts: 25
- Joined: Fri Aug 01, 2008 7:17 am
Segfault on initSystem
Hello,
I would like to use an OpenSim model with an optimal control code. The OpenSim header file and the header file of the optimal control code do not play nicely together. In an effort to isolate the two codes from each other I've made a separate class for the OpenSim model (OpenSimPendulum) and used forward referencing so that I can keep the call to include OpenSim.h in OpenSimPendulum.cc. The class only needs to do 2 things: make the model, and calculate its state derivative. The problem is that when I call initSystem() I get a segfault at line 948 of State.cpp in the function CacheEntryInfo::registerWithPrerequisites(StateImpl& stateImpl).
As a note, I've used this approach to successfully isolate a Simbody pendulum from this optimal control code. Finally, I'm working in Ubuntu 14.04 in case that makes any difference.
With kind regards,
Matt
I would like to use an OpenSim model with an optimal control code. The OpenSim header file and the header file of the optimal control code do not play nicely together. In an effort to isolate the two codes from each other I've made a separate class for the OpenSim model (OpenSimPendulum) and used forward referencing so that I can keep the call to include OpenSim.h in OpenSimPendulum.cc. The class only needs to do 2 things: make the model, and calculate its state derivative. The problem is that when I call initSystem() I get a segfault at line 948 of State.cpp in the function CacheEntryInfo::registerWithPrerequisites(StateImpl& stateImpl).
As a note, I've used this approach to successfully isolate a Simbody pendulum from this optimal control code. Finally, I'm working in Ubuntu 14.04 in case that makes any difference.
With kind regards,
Matt
- Attachments
-
- isolatedOpenSimPendulum.zip
- (3.58 KiB) Downloaded 95 times
- Michael Sherman
- Posts: 807
- Joined: Fri Apr 01, 2005 6:05 pm
Re: Segfault on initSystem
Matt, can you clarify which versions of Simbody and OpenSim you are using? From the error message I presume that is Simbody 3.6 (the master branch) -- is that right? What source did you use for OpenSim?
Thanks, Sherm
Thanks, Sherm
- Matthew Millard
- Posts: 25
- Joined: Fri Aug 01, 2008 7:17 am
Re: Segfault on initSystem
I pulled from the master branches of both OpenSim and Simbody on git hub, so I should have:
OpenSim 4.0
Simbody 3.6
As a double check I looked at the version numbers mentioned in doxygen, and everything is consistent.
Cheers, Matt
OpenSim 4.0
Simbody 3.6
As a double check I looked at the version numbers mentioned in doxygen, and everything is consistent.
Cheers, Matt
- Michael Sherman
- Posts: 807
- Joined: Fri Apr 01, 2005 6:05 pm
Re: Segfault on initSystem
Hi, Matt. I built your program on Windows using OpenSim 4.0 and Simbody 3.6 Debug builds and it blew up on line 128 of OpenSimPendulum.cc:
At that point "modelState" is an uninitialized pointer so this doesn't make sense. I replaced it with
which ran to completion with this output:
Although that seems to fix the problem, I don't think "modelState" should be a pointer at all -- you should just declare it
so that you can write
Regards,
Sherm
Code: Select all
*modelState = model->initSystem();
Code: Select all
modelState = new SimTK::State(model->initSystem());
Code: Select all
createOpenSimPendulum:
:Adding gravity
:Adding link 0
:getDefaultState
:Number of model states: NU: 1, NQ: 1, NZ: 2
createStateDerivative:
position velocity activation
0.000000e+00 0.000000e+00 1.000000e+00
Copying state over
realize to acceleration
getUDot
0: 0.005000
Code: Select all
SimTK::State modelState;
Code: Select all
modelState = model->initSystem()
Sherm
- Matthew Millard
- Posts: 25
- Joined: Fri Aug 01, 2008 7:17 am
Re: Segfault on initSystem
Thank you for the detailed responses Sherm! Though now our two systems behave differently. When I update line 128 to this I get a segfault at this line when the program is run. In addition, when I change modelState from a pointer to an object the compiler complains that
Cheers,
Matt
Code: Select all
modelState = new SimTK::State(model->initSystem());
Code: Select all
SimTK::State modelState;
. I'll keep digging - that you were able to fix this in VS (I'm assuming) gives me hope that a fix is around the corner.field 'modelState' has incomplete type
Cheers,
Matt
- Michael Sherman
- Posts: 807
- Joined: Fri Apr 01, 2005 6:05 pm
Re: Segfault on initSystem
The "incomplete type" is because no definition of SimTK::State is available; for a pointer SimTK::State* only a declaration is needed, not a definition. If you include Simbody.h you'll have the definition; if that is a problem you could keep the pointer.
I don't understand the seg fault -- might be more info in a Debug build.
Sherm
I don't understand the seg fault -- might be more info in a Debug build.
Sherm
- Matthew Millard
- Posts: 25
- Joined: Fri Aug 01, 2008 7:17 am
Re: Segfault on initSystem
Indeed I do have to keep the pointers: putting Simbody.h in the header causes conflicts with the other libraries I'm using.
I've built OpenSim and Simbody in debug and rebuilt the project in debug. Oddly it looks like my program is linking against the non-debug versions of the OpenSim libraries. This line in the CMakeFile yields
I do get some new errors on. At the output console I see
Does anything spring to mind?
I've built OpenSim and Simbody in debug and rebuilt the project in debug. Oddly it looks like my program is linking against the non-debug versions of the OpenSim libraries. This line in the CMakeFile
Code: Select all
message("OpenSim_LIBRARIES = " ${OpenSim_LIBRARIES})
but not oSimTools_d. Any idea why? Note I'm using ccmake incase this makes a difference.OpenSim_LIBRARIES = oSimTools
I do get some new errors on
Code: Select all
modelState = new SimTK::State(model->initSystem());
which seems odd to me. The stack trace is even stranger:getDefaultState
EXCEPTION: createOpenSimPendulum: SimTK Exception thrown at StateImpl.h:1198:
Error detected by Simbody method State::allocateCacheEntryWithPrerequisites(): Prerequisite cache entry (2,3) has depends-on stage Time but this one would have lower depends-on stage Instance. That would mean the prerequisite could get invalidated without invalidating this one; not good.
(Required condition 'prereq.getDependsOnStage() <= earliest' was not met.)
(keep in mind that the regular OpenSim libraries are being linked against).1 ?? 0x21
2 SimTK::CollisionDetectionAlgorithm::AlgorithmMap::~AlgorithmMap CollisionDetectionAlgorithm.cpp 41 0x7ffff5d2dc47
3 __cxa_finalize cxa_finalize.c 56 0x7ffff47925ea
4 __do_global_dtors_aux 0x7ffff336d183
5 ?? 0x7fffffffe310
6 _dl_fini dl-fini.c 252 0x7ffff7dea73a
Does anything spring to mind?
- Michael Sherman
- Posts: 807
- Joined: Fri Apr 01, 2005 6:05 pm
Re: Segfault on initSystem
Mixing debug with non-debug libraries is a fatal problem.
Hopefully Chris Dembia can quickly spot what's wrong.
Hopefully Chris Dembia can quickly spot what's wrong.
- Christopher Dembia
- Posts: 506
- Joined: Fri Oct 12, 2012 4:09 pm
Re: Segfault on initSystem
The fact that `OpenSim_LIBRARIES` is `osimTools` does not mean you are using debug libraries. In fact, `OpenSim_LIBRARIES` is set to `osimTools` no matter what. In this context, `osimTools` is the name of a CMake target (in any of its configurations), not of a specific library file. You have to look at the link command that is actually executed by your linker, or perhaps using Dependency Walker on Windows.
- Matthew Millard
- Posts: 25
- Joined: Fri Aug 01, 2008 7:17 am
Re: Segfault on initSystem
Thank you for the explanation Chris - that helps a lot. Using the command 'ldd' in linux I got a list of the dependencies - see below (I've built the target in Debug).
Do you see a similar list when you run dependency walker? Should I be concerned that it appears that both the release and debug versions of the libSimTK libraries appear to be dependencies? If thoughts on how to fix it?
In case this is relevant, initSystem is now working just fine, but the program later dies when I try to set the state. Details below.
Thank you again for your help!
Matt
----------------------------------------
Seemingly duplicated dependencies
----------------------------------------
libSimTKsimbody.so.3.6 libSimTKsimbody_d.so.3.6
libSimTKcommon.so.3.6 libSimTKsimbody_d.so.3.6
libSimTKmath.so.3.6 libSimTKmath_d.so.3.6
libSimTKsimbody.so.3.6 libSimTKsimbody_d.so.3.6
----------------------------------------
Full list of dependencies
----------------------------------------
linux-vdso.so.1 => (0x00007ffc2b5f2000)
libosimTools_d.so => /home/mjhmilla/dev/opensim-core-install/lib/x86_64-linux-gnu/libosimTools_d.so (0x00007f5c24469000)
libosimAnalyses_d.so => /home/mjhmilla/dev/opensim-core-install/lib/x86_64-linux-gnu/libosimAnalyses_d.so (0x00007f5c24159000)
libosimActuators_d.so => /home/mjhmilla/dev/opensim-core-install/lib/x86_64-linux-gnu/libosimActuators_d.so (0x00007f5c23d58000)
libosimSimulation_d.so => /home/mjhmilla/dev/opensim-core-install/lib/x86_64-linux-gnu/libosimSimulation_d.so (0x00007f5c23369000)
libosimCommon_d.so => /home/mjhmilla/dev/opensim-core-install/lib/x86_64-linux-gnu/libosimCommon_d.so (0x00007f5c22f16000)
libSimTKcommon.so.3.6 => /home/mjhmilla/dev/opensim-core-install/lib/x86_64-linux-gnu/libSimTKcommon.so.3.6 (0x00007f5c229bd000)
libSimTKmath.so.3.6 => /home/mjhmilla/dev/opensim-core-install/lib/x86_64-linux-gnu/libSimTKmath.so.3.6 (0x00007f5c223b4000)
libSimTKsimbody.so.3.6 => /home/mjhmilla/dev/opensim-core-install/lib/x86_64-linux-gnu/libSimTKsimbody.so.3.6 (0x00007f5c21d29000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f5c219fd000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f5c216f7000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f5c214e0000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5c2111b000)
libSimTKsimbody_d.so.3.6 => /home/mjhmilla/dev/opensim-core-install/lib/x86_64-linux-gnu/libSimTKsimbody_d.so.3.6 (0x00007f5c204eb000)
libSimTKmath_d.so.3.6 => /home/mjhmilla/dev/opensim-core-install/lib/x86_64-linux-gnu/libSimTKmath_d.so.3.6 (0x00007f5c1fb36000)
libSimTKcommon_d.so.3.6 => /home/mjhmilla/dev/opensim-core-install/lib/x86_64-linux-gnu/libSimTKcommon_d.so.3.6 (0x00007f5c1f392000)
liblapack.so.3 => /usr/lib/liblapack.so.3 (0x00007f5c1ebf6000)
libosimLepton_d.so => /home/mjhmilla/dev/opensim-core-install/lib/x86_64-linux-gnu/libosimLepton_d.so (0x00007f5c1e977000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f5c1e773000)
libf77blas.so.3 => /usr/lib/libf77blas.so.3 (0x00007f5c1e552000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f5c1e334000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f5c1e12c000)
/lib64/ld-linux-x86-64.so.2 (0x00005599c87a2000)
libblas.so.3 => /usr/lib/libblas.so.3 (0x00007f5c1c922000)
libgfortran.so.3 => /usr/lib/x86_64-linux-gnu/libgfortran.so.3 (0x00007f5c1c608000)
libcblas.so.3 => /usr/lib/libcblas.so.3 (0x00007f5c1c3e6000)
libatlas.so.3 => /usr/lib/libatlas.so.3 (0x00007f5c1be53000)
libquadmath.so.0 => /usr/lib/x86_64-linux-gnu/libquadmath.so.0 (0x00007f5c1bc17000)
----------------------------------------
New errors on run
----------------------------------------
In case this helps, the program now makes it past initSystem, but later dies near line 210
with the complaint
Do you see a similar list when you run dependency walker? Should I be concerned that it appears that both the release and debug versions of the libSimTK libraries appear to be dependencies? If thoughts on how to fix it?
In case this is relevant, initSystem is now working just fine, but the program later dies when I try to set the state. Details below.
Thank you again for your help!
Matt
----------------------------------------
Seemingly duplicated dependencies
----------------------------------------
libSimTKsimbody.so.3.6 libSimTKsimbody_d.so.3.6
libSimTKcommon.so.3.6 libSimTKsimbody_d.so.3.6
libSimTKmath.so.3.6 libSimTKmath_d.so.3.6
libSimTKsimbody.so.3.6 libSimTKsimbody_d.so.3.6
----------------------------------------
Full list of dependencies
----------------------------------------
linux-vdso.so.1 => (0x00007ffc2b5f2000)
libosimTools_d.so => /home/mjhmilla/dev/opensim-core-install/lib/x86_64-linux-gnu/libosimTools_d.so (0x00007f5c24469000)
libosimAnalyses_d.so => /home/mjhmilla/dev/opensim-core-install/lib/x86_64-linux-gnu/libosimAnalyses_d.so (0x00007f5c24159000)
libosimActuators_d.so => /home/mjhmilla/dev/opensim-core-install/lib/x86_64-linux-gnu/libosimActuators_d.so (0x00007f5c23d58000)
libosimSimulation_d.so => /home/mjhmilla/dev/opensim-core-install/lib/x86_64-linux-gnu/libosimSimulation_d.so (0x00007f5c23369000)
libosimCommon_d.so => /home/mjhmilla/dev/opensim-core-install/lib/x86_64-linux-gnu/libosimCommon_d.so (0x00007f5c22f16000)
libSimTKcommon.so.3.6 => /home/mjhmilla/dev/opensim-core-install/lib/x86_64-linux-gnu/libSimTKcommon.so.3.6 (0x00007f5c229bd000)
libSimTKmath.so.3.6 => /home/mjhmilla/dev/opensim-core-install/lib/x86_64-linux-gnu/libSimTKmath.so.3.6 (0x00007f5c223b4000)
libSimTKsimbody.so.3.6 => /home/mjhmilla/dev/opensim-core-install/lib/x86_64-linux-gnu/libSimTKsimbody.so.3.6 (0x00007f5c21d29000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f5c219fd000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f5c216f7000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f5c214e0000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5c2111b000)
libSimTKsimbody_d.so.3.6 => /home/mjhmilla/dev/opensim-core-install/lib/x86_64-linux-gnu/libSimTKsimbody_d.so.3.6 (0x00007f5c204eb000)
libSimTKmath_d.so.3.6 => /home/mjhmilla/dev/opensim-core-install/lib/x86_64-linux-gnu/libSimTKmath_d.so.3.6 (0x00007f5c1fb36000)
libSimTKcommon_d.so.3.6 => /home/mjhmilla/dev/opensim-core-install/lib/x86_64-linux-gnu/libSimTKcommon_d.so.3.6 (0x00007f5c1f392000)
liblapack.so.3 => /usr/lib/liblapack.so.3 (0x00007f5c1ebf6000)
libosimLepton_d.so => /home/mjhmilla/dev/opensim-core-install/lib/x86_64-linux-gnu/libosimLepton_d.so (0x00007f5c1e977000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f5c1e773000)
libf77blas.so.3 => /usr/lib/libf77blas.so.3 (0x00007f5c1e552000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f5c1e334000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f5c1e12c000)
/lib64/ld-linux-x86-64.so.2 (0x00005599c87a2000)
libblas.so.3 => /usr/lib/libblas.so.3 (0x00007f5c1c922000)
libgfortran.so.3 => /usr/lib/x86_64-linux-gnu/libgfortran.so.3 (0x00007f5c1c608000)
libcblas.so.3 => /usr/lib/libcblas.so.3 (0x00007f5c1c3e6000)
libatlas.so.3 => /usr/lib/libatlas.so.3 (0x00007f5c1be53000)
libquadmath.so.0 => /usr/lib/x86_64-linux-gnu/libquadmath.so.0 (0x00007f5c1bc17000)
----------------------------------------
New errors on run
----------------------------------------
In case this helps, the program now makes it past initSystem, but later dies near line 210
Code: Select all
modelState->updU()[i] = generalizedVelocities.at(i);
EXCEPTION: createOpenSimPendulum: SimTK Exception thrown at StateImpl.h:1198:
Error detected by Simbody method State::allocateCacheEntryWithPrerequisites(): Prerequisite cache entry (2,3) has depends-on stage Time but this one would have lower depends-on stage Instance. That would mean the prerequisite could get invalidated without invalidating this one; not good.
(Required condition 'prereq.getDependsOnStage() <= earliest' was not met.)