Matlab Crashes on initSystem() / Frame not connected error && motion can't be displayed

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Ruth Meißner
Posts: 16
Joined: Sat Mar 23, 2019 11:28 am

Matlab Crashes on initSystem() / Frame not connected error && motion can't be displayed

Post by Ruth Meißner » Thu Dec 05, 2019 5:28 am

Hi everybody,

since two month I am working with openSim 4.0 for my master thesis. I am using the interface with Matlab since I will have several simulation runs once my code is finished.
I use a model that - to my knowlegde- has been developed with OpenSim 3.2 and has been adapted to OpenSim4.0 before it was given to me.
In my code, I add bodies, markers and geoemtries, then I scale this "generic model" to three different sizes and do IK runs. All the steps are coded in matlab.

I have two major issues with thrown errors that I don't understand.

1) Matlab crashes / Frame not connected error
When I started working, everything worked fine, but now Matlab crashes really often, sometimes without any warning. I could track it down to the model.initSystem() call. However, matlab does not crash every time nor does it crash always on the first time I call initSystem() (e.g. it is called for each scale separately). For me it seems to be quite randomly, especially as it is possible that my code runs through sometimes without any issue.
Interestingly, sometimes instead of matlab crashing a java exception is thrown in the matlab console when initSystem() is called. Also, this actuates the same way that it doesn't happen on each run and the initSystem() where it is thrown can be at different places / own functions in my code.
[I additionally realized that sometimes model.print(filename) might be the code line where matlab crashes, if this helps. Furthermore, often my CPU-usage is very high when matlab crashes. When I get the error instead of crashing, the CPU-usage is lower.]
This is the java exception thrown:
Java exception occurred:
java.io.IOException: Failed to connect Socket 'frame' of type Frame (details: Component 'tibia_r_geom_1'
could not find '..' of type Frame. Make sure a component exists at this path and that it is of the correct
type.
Thrown at component.h:764 in getComponent().).
In Object 'tibia_r_geom_1' of type Mesh.
Thrown at component.cpp:312 in finalizeConnections().

at org.opensim.modeling.opensimSimulationJNI.Model_initSystem(Native Method)

at org.opensim.modeling.Model.initSystem(Model.java:848)

The component named in the java exception changes in each case, it might be also for example: Component 'patella_l_geom_1' or Component 'talus_r_geom_1', both with a socket_frame "..". (Those are bodies that are in the original model given to me and are not created by me within the matlab code.)

What makes it really difficult for me to understand the issue, is that this problem is not happening regularly. Somethime the code works, sometimes it crashes, sometimes I get the error, everytime at different positions in my code. I would say that 4 out of 5 runs, my code runs through.

Well, and then there is the case where matlab shows the crash-window ("Matlab has encountered an internal problem and needs to close") but the code keeps running and I can just ignore the crash-window and continue working, coding, run code withing matlab without any issue.

In contrast to that, there is one case, where Matlab ALWAYS crashes when using initSystem(). If I want to visualize any model with the matlab visualizer (also the examples you deliver with the openSim 4.0 distribution), I need to call "model.setUseVisualizer(true)" and afterwards calling the next initSystem() will cause Matlab to crash. With model.setUseVisualizer(false) this won't happen.
Interestingly, if I let try anybody else at my university department to run e.g. TugOfWar_CompleteRunVisualize.m on his user on the same computer, the code executes and shows the visualisation window. On my user, matlab crashes on initSystem() executing the same code example. Therefor it seems to me that the issue might also be user-related?

As you can see, this doesn't seem to be a consistent error. I really read a lot of error descriptions in the forum / github etc but I couldn't fix any of these issues.
I would be very glad if you could help me.

2) motion file (result from IK tool) throw error
My code creates (using the IK tool) two different motion files (snychrone and asynchrone cranking) which are stored as mot-files in my workspace.
The Matlab console tells me that the IK tool completed.
When I open afterwards my scaled model in the GUI and load the motion into it, one of both files (asynchrone) won't work.
There are two different reactions by the GUI:
The first option is, when I make the motion current in the navigation tree (it is marked as bold), the motion menu on the top of the GUI with the "movie options" stays greyed out and I can see on the bottom of the GUI a small red sign that an error ( "A java.lang.IndexOutOfBoundsException exception has occurred.") has been thrown when the motion got loaded into the GUI.
The second option is that i can actually start displaying the motion but after the first time frames the same error is shown in an opening error window: "A java.lang.IndexOutOfBoundsException exception has occurred.". I attached the message.log file that OpenSim has automatically saved.

I would really appreciate if you have any hint that might help.
Currently I am out of ideas. :roll:

Thank you very much.

Best regards
Ruth Meissner


I am working with OpenSim4.0
path variable is correctly set
Windows 7

Tags:

User avatar
Ruth Meißner
Posts: 16
Joined: Sat Mar 23, 2019 11:28 am

Re: Matlab Crashes on initSystem() / Frame not connected error && motion can't be displayed

Post by Ruth Meißner » Thu Dec 05, 2019 7:24 am

Attachments were missing, sorry!
Attachments
messages.log
output error log from openSIM GUI when motion can't be played
(40.55 KiB) Downloaded 118 times
Last edited by Ruth Meißner on Thu Dec 19, 2019 6:44 am, edited 2 times in total.

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: Matlab Crashes on initSystem() / Frame not connected error && motion can't be displayed

Post by jimmy d » Thu Dec 05, 2019 7:48 am

Java exception occurred:
java.io.IOException: Failed to connect Socket 'frame' of type Frame (details: Component 'tibia_r_geom_1'
could not find '..' of type Frame. Make sure a component exists at this path and that it is of the correct
type.
Thrown at component.h:764 in getComponent().).
In Object 'tibia_r_geom_1' of type Mesh.
Thrown at component.cpp:312 in finalizeConnections().

at org.opensim.modeling.opensimSimulationJNI.Model_initSystem(Native Method)

at org.opensim.modeling.Model.initSystem(Model.java:848)
This tends to indicate that the model wasn't finalized during the editing process. When you are editing a model in Matlab (adding bodies, Geometries, etc), you have to call (at least) model.finalizeFromProperties() and model.finalizeConnections(). If you don't make sure that all the new components are hooked up correctly before printing, then you will see erratic behavior later when you read that model in and try to do things with it.

In an upcoming OpenSim update, the model.print() method actually calls finalizeConnections() to ensure it has been done before printing the model to file so that errors can be caught during the model creation process.

User avatar
Ruth Meißner
Posts: 16
Joined: Sat Mar 23, 2019 11:28 am

Re: Matlab Crashes on initSystem() / Frame not connected error && motion can't be displayed

Post by Ruth Meißner » Thu Dec 05, 2019 8:35 am

Hi James,

So far, I (only) used finalizeConnections().

Due to your suggestion, I added finalizeFromProperties(), which means that now I only call initSystem after finalizeConnections (before the new correction I called first initSystem() and then finalizeConnections() , because otherwise Matlab always crashed.)

I tried quite a lot of different "call orders", but overall I can say that it is still possible that Matlab crashes at those positions:
- finalizeConnections()
- scale()
- Model(modelll_original);

It is possible that matlab crashes or that it throws one of those errors:

Java exception occurred:
java.lang.RuntimeException: Access violation - no RTTI data!

at org.opensim.modeling.opensimCommonJNI.Component_finalizeFromProperties(Native Method)

at org.opensim.modeling.Component.finalizeFromProperties(Component.java:66)


Java exception occurred:
java.lang.RuntimeException: Failed to connect Socket 'frame' of type Frame (details: Component
'patella_r_geom_1' could not find '..' of type Frame. Make sure a component exists at this path and that
it is of the correct type.
Thrown at component.h:764 in getComponent().).
In Object 'patella_r_geom_1' of type Mesh.
Thrown at component.cpp:312 in finalizeConnections().

at org.opensim.modeling.opensimSimulationJNI.Model_finalizeConnections__SWIG_0(Native Method)

at org.opensim.modeling.Model.finalizeConnections(Model.java:787)



What I want to do is
- load the original model
- add constraints, markers, geometries, change default pose etc
- copy of that changed model
- scale the copy

What I implemented right now is:

Code: Select all

   
   	 modell_original.finalizeFromProperties() 
    	modell_original.finalizeConnections();
      	modell_original.initSystem();
      	%%WITH THIS FIRS PART OPTIONAL, IT TRIED BOTH AND BOTH CAUSE CRASHES
      	
   	model_scaled = Model(modell_original)
      	model_scaled.finalizeFromProperties() 
      	model_scaled.finalizeConnections();
      	state = model_scaled.initSystem();
      	model_scaled.scale(state, scaleSet, true, kilo);
      	% --- change some properties as model name etc ---%
      	model_scaled.print(filename);
     
What would be the correct order how I should implement this?

I just got the error various times, also crashing happened nearly all the time.

User avatar
Ruth Meißner
Posts: 16
Joined: Sat Mar 23, 2019 11:28 am

Re: Matlab Crashes on initSystem() / Frame not connected error && motion can't be displayed

Post by Ruth Meißner » Thu Dec 05, 2019 8:39 am

Another aspect:

I also tried running
OpenSimCreateTugOfWarModel., --> works
TugOfWar_CompleteRunVisualize.m --> matlab crashes on initSystem()

Since I did not change anything in the code (this is a distributed matlab example), it should not only be caused by finalizeFromProperties().
There need to be any additional reason.

User avatar
Ruth Meißner
Posts: 16
Joined: Sat Mar 23, 2019 11:28 am

Re: Matlab Crashes on initSystem() / Frame not connected error && motion can't be displayed

Post by Ruth Meißner » Tue Dec 17, 2019 10:20 am

Just as follow up, so that maybe someone else might be helped:

The issue of matlab crashes was caused by one final marker.adoptAndAppend(). Once I changed it to marker.cloneAndAppend() the issue was gone.
This post helped me: viewtopicPhpbb.php?f=91&t=9403&p=25821&start=0&view=

The other one might be explained here:
The title of the mot-file should not have more than 16 letters.
viewtopicPhpbb.php?f=91&t=7326&p=19263&start=0&view=

User avatar
Olivier Vandebroucke
Posts: 3
Joined: Tue Dec 31, 2019 11:47 am

Re: Matlab Crashes on initSystem() / Frame not connected error && motion can't be displayed

Post by Olivier Vandebroucke » Tue Dec 31, 2019 1:22 pm

Hello,

I was wondering, could it be an issue of not having enough of a powerful computer? I know that some other programs will crash on my dinosaur of a laptop, while my more recent desktop computer works fine. And since I was looking at spending part of the year at one of these flatsi n Montenegro, doing remote work, I figure I should get a new laptop if I want to be able to be efficient...

User avatar
Ruth Meißner
Posts: 16
Joined: Sat Mar 23, 2019 11:28 am

Re: Matlab Crashes on initSystem() / Frame not connected error && motion can't be displayed

Post by Ruth Meißner » Tue Jan 07, 2020 7:42 am

Hi,

thanks! I work on a university computer which I'd expect to have enough capacity.

However, I finally found all the issues and I am not running into the matlab crashes anymore:
1) USE cloneAndAppend and not adoptAndAppend for Markers etc.
2) When you want to use the matlab visualizer, the code needs to run on a local disk! I had my matlab scripts saved on a student-server (accessable from all university computers), but the code needs to be run from a local disk (e.g. C:\).

Since I am respecting those two things this, I haven't experienced any crashes.
Maybe this is helpful to someone...

Regards
Ruth

POST REPLY