Page 1 of 1

MATLAB crashes while creating .osim model with API

Posted: Thu Nov 16, 2017 9:30 am
by adkoele
Hi,

I created a MATLAB function to write an .osim file with scaled mass/length parameters from an existing .osim file. This function makes MATLAB crash. Sometimes it will work once or twice, but eventually MATLAB will crash.

I've included the log file of a crash, and also the MATLAB function that I use. It's a .txt file because I could not attach .m files. I use 32-bit MATLAB R2015b and Opensim 3.3 on a 64-bit computer. Could you tell me why the function makes MATLAB crash?

Thanks,
Anne

Re: MATLAB crashes while creating .osim model with API

Posted: Thu Nov 16, 2017 1:30 pm
by tkuchida
Not sure this is the only problem, but there seems to be a logical inconsistency at lines 35 and 39. It looks like you want to choose random polynomials of degree 4 for your splines, but these random coefficients should be chosen outside the for loop; if chosen inside the loop, you are essentially assigning random y values which may cause issues downstream. You might try replacing rand() with arbitrary but fixed numbers to rule out any memory-related issues associated with running the script repeatedly, then perhaps try plotting the random (x,y) points you are using to define the splines when the script crashes.

Re: MATLAB crashes while creating .osim model with API

Posted: Thu Nov 16, 2017 1:32 pm
by chrisdembia
Tom has a good point about the random points; I'm not sure if addPoint() supports adding points out of order.

Here are a few additional suggestions:

1. When editing items in a set, use `updBodySet()`, etc. instead of `getBodySet()`. Similarly, `getSpatialTransform()` should be `updSpatialTransform()`.

2. Line 24 should be `joint = model.updJointSet().get(iJnt);` and you should not overwrite the joint in line 48; you are modifying the one that's already in the model.

3. Line 56: When accessing a specific joint, access it by name, not by index. For example, `model.getJointSet().get('hip')`.

I suspect that the presence of line 48 is causing the crash. If that's not it, then it's likely the `setFunction()` calls in line 46-47. Try commenting out those lines and see if that avoids the crash. If so, then try using `setFunction(spline1.clone())`.

Re: MATLAB crashes while creating .osim model with API

Posted: Fri Nov 17, 2017 8:15 am
by adkoele
Thanks for the help! These three suggestions, and using setFunction(spline1.clone()) solved the problem. I checked if the random order of the numbers in the spline is a problem, but it is not.