Matlab crash afterI'm using model scaling using API
Posted: Fri Mar 09, 2012 12:28 am
Hi,
I would like to use OpenSim API in Matlab to programmatically scale my model. I wrote down
the followjng code to do that:
import org.opensim.modeling.*
% Get the original model
M_Model = Model('Delp1990.osim');
% Create the ScaleSet object
leg_ScaleSet = ScaleSet();
segNames = {'ground','pelvis','femur_r','tibia_r','talus_r','calcn_r','toes_r','femur_l','tibia_l','talus_l','calcn_l','toes_l','torso'};
for i = 1 : length(segNames)
seg_Scale(i) = Scale();
seg_Scale(i).setSegmentName(segNames{i});
if strcmp(segNames{i},'tibia_r')
seg_Scale(i).setScaleFactors([0.3, 0.3, 0.3]);
else
seg_Scale(i).setScaleFactors([1, 1, 1]);
end
seg_Scale(i).setApply(true);
leg_ScaleSet.append(seg_Scale(i));
end
% Scale the model
state_State = M_Model.initSystem;
scaled = M_Model.scale(state_State,leg_ScaleSet);
% Save it to .osim file
M_Model.print('Delp1990_scaled.osim');
When I lunch the function the first time it greatly works. But when I lunch it again, Matlab crashes and, in the hs_err_pidXXXX.log file generated in the same folder of the .m script, I have the following lines:
Stack: [0x0c340000,0x0c3c0000], sp=0x0c3bf7d0, free space=509k
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j org.opensim.modeling.opensimModelJNI.delete_Scale(J)V+0
j org.opensim.modeling.Scale.delete()V+25
j org.opensim.modeling.Scale.finalize()V+1
v ~StubRoutines::call_stub
j java.lang.ref.Finalizer.invokeFinalizeMethod(Ljava/lang/Object;)V+0
j java.lang.ref.Finalizer.runFinalizer()V+45
j java.lang.ref.Finalizer.access$100(Ljava/lang/ref/Finalizer;)V+1
j java.lang.ref.Finalizer$FinalizerThread.run()V+11
v ~StubRoutines::call_stub
By ther way, the output model Delp1990_scaled.osim is asved before the crash and it' correct.
I guess there must be something about Scale or ScaleSet object deallocations. Am I using the Java objects in a wrong way?
I'm using Matlab 32bit on a Win 7 64bit OS.
Thank you very much in advance.
Davide
I would like to use OpenSim API in Matlab to programmatically scale my model. I wrote down
the followjng code to do that:
import org.opensim.modeling.*
% Get the original model
M_Model = Model('Delp1990.osim');
% Create the ScaleSet object
leg_ScaleSet = ScaleSet();
segNames = {'ground','pelvis','femur_r','tibia_r','talus_r','calcn_r','toes_r','femur_l','tibia_l','talus_l','calcn_l','toes_l','torso'};
for i = 1 : length(segNames)
seg_Scale(i) = Scale();
seg_Scale(i).setSegmentName(segNames{i});
if strcmp(segNames{i},'tibia_r')
seg_Scale(i).setScaleFactors([0.3, 0.3, 0.3]);
else
seg_Scale(i).setScaleFactors([1, 1, 1]);
end
seg_Scale(i).setApply(true);
leg_ScaleSet.append(seg_Scale(i));
end
% Scale the model
state_State = M_Model.initSystem;
scaled = M_Model.scale(state_State,leg_ScaleSet);
% Save it to .osim file
M_Model.print('Delp1990_scaled.osim');
When I lunch the function the first time it greatly works. But when I lunch it again, Matlab crashes and, in the hs_err_pidXXXX.log file generated in the same folder of the .m script, I have the following lines:
Stack: [0x0c340000,0x0c3c0000], sp=0x0c3bf7d0, free space=509k
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j org.opensim.modeling.opensimModelJNI.delete_Scale(J)V+0
j org.opensim.modeling.Scale.delete()V+25
j org.opensim.modeling.Scale.finalize()V+1
v ~StubRoutines::call_stub
j java.lang.ref.Finalizer.invokeFinalizeMethod(Ljava/lang/Object;)V+0
j java.lang.ref.Finalizer.runFinalizer()V+45
j java.lang.ref.Finalizer.access$100(Ljava/lang/ref/Finalizer;)V+1
j java.lang.ref.Finalizer$FinalizerThread.run()V+11
v ~StubRoutines::call_stub
By ther way, the output model Delp1990_scaled.osim is asved before the crash and it' correct.
I guess there must be something about Scale or ScaleSet object deallocations. Am I using the Java objects in a wrong way?
I'm using Matlab 32bit on a Win 7 64bit OS.
Thank you very much in advance.
Davide