When I initiate a model from a model file path (e.g. Model(filePathToModelFile)), Matlab throws a Java exception as below:
Java exception occurred:
java.lang.NullPointerException: null upcall object in OpenSim::LogSink::sinkImpl
at org.opensim.modeling.opensimSimulationJNI.new_Model__SWIG_1(Native Method)
at org.opensim.modeling.Model.<init>(Model.java:821)
What does this mean? It only happens when looping a few times. In Matlab debug mode, even if Model(filePathToModelFile) does not work, initiating an empty model (e.g. Model()) still works fine.
Is this related to sending the OpenSim messages to the Matlab Command Window?
At the beginning of the Matlab script, the "Logger.addSink(JavaLogSink())" is used to send OpenSim messages to the Matlab.
Java exception related to Logger?
- Ayman Habib
- Posts: 2248
- Joined: Fri Apr 01, 2005 12:24 pm
Re: Java exception related to Logger?
Hello Xiao,
Yes this is related to passing log messages from the OpenSim API to the log file (sink using the logger's terminology).
Generally the call to add sink should be done once at the start or one place where logging is needed and not inside a loop. My guess is that by creating the sink at the call site as described (Logger.addSink(JavaLogSink()) it's possible that the Java garbage collection scheme thinks it's not used downstream and deletes it causing the crash.
I'd suggest you either not add a sink altogether or add it once outside any looping. Something like so you have a live handle to the log and it doesn't get deleted by garbage collection. If you remove it entirely you may get no logging at all or the default clutter depending on your environment/Matlab version.
Please let us know if that helps,
-Ayman
Yes this is related to passing log messages from the OpenSim API to the log file (sink using the logger's terminology).
Generally the call to add sink should be done once at the start or one place where logging is needed and not inside a loop. My guess is that by creating the sink at the call site as described (Logger.addSink(JavaLogSink()) it's possible that the Java garbage collection scheme thinks it's not used downstream and deletes it causing the crash.
I'd suggest you either not add a sink altogether or add it once outside any looping. Something like
Code: Select all
myLog = JavaLogSink(); Logger.addSink(myLog)
Please let us know if that helps,
-Ayman
Re: Java exception related to Logger?
Thanks Ayman for the quick reply.
To clarify: the Logger.addSink(JavaLogSink()) was originally called only once at the beginning of the script, not in the loop. However, when RRATool was called in a loop to run multiple times, Matlab threw a Java exception as described in the original post.
With some quick testing, the method that Ayman suggested seems to be more stable. No exception has been thrown by Matlab yet. If is more stable than , maybe the suggestion about "how to show OpenSim's log messages in the Matlab Command Window" on the Scripting with Matlab page https://simtk-confluence.stanford.edu/d ... mandWindow need to be updated?
To clarify: the Logger.addSink(JavaLogSink()) was originally called only once at the beginning of the script, not in the loop. However, when RRATool was called in a loop to run multiple times, Matlab threw a Java exception as described in the original post.
With some quick testing, the method that Ayman suggested seems to be more stable. No exception has been thrown by Matlab yet. If
Code: Select all
myLog = JavaLogSink(); Logger.addSink(myLog)
Code: Select all
the Logger.addSink(JavaLogSink())
- Ayman Habib
- Posts: 2248
- Joined: Fri Apr 01, 2005 12:24 pm
Re: Java exception related to Logger?
Good idea Xiao,
I went ahead and updated the page. Thanks for reporting.
-Ayman
I went ahead and updated the page. Thanks for reporting.
-Ayman