Page 1 of 1
Error Deleting Components allocated on the Heap
Posted: Thu Nov 21, 2019 10:22 pm
by vinaym815
Hello everyone,
I have allocated muscle controller on the heap and then added it to the OpenSim model. After deleting the model I am still able to access the muscle controller but deleting it causes the program to crash (Line83 in Link). Same thing happens for the Excitation functions (Line 75).
Any ideas about what I am doing wrong here.
https://github.com/vinaym815/OpenSimExa ... ug.cpp#L83
Thank you
Re: Error Deleting Components allocated on the Heap
Posted: Fri Nov 22, 2019 8:01 am
by mitkof6
The model takes ownership of the controller after calling addController (or any object that is added to the model). Therefore, if you delete the controller manually, the model also tries to delete it when it is destroyed.
I see that you tend to allocate many things on the heap and manually delete them. It would be better to use shared/unique pointers so that you will not have to worry about memory leaks.
Re: Error Deleting Components allocated on the Heap
Posted: Fri Nov 22, 2019 8:44 pm
by vinaym815
Yes, you are right.
As shown in the screenshot, I was able to print the controller's ("Vinay") and the excitation signal names ("ExtSignal"), which raised my concerns. However, it seems I was just printing leftover stuff (Tried different controller name "MuscleController" and "ExcitationSignal").
As of why I have allocated so many items on the heap, I was using this script to figure out multithreaded optimization using simbody's CMAES
https://github.com/vinaym815/OpenSimExa ... /main.cpp . That script uses arrays of pointers to different models accesses them uniquely using a queue, as I was not able to move the loading and modification of OpenSim Models to different threads initialization. If you have a idea of how to implement it differently or a similar implementation in mind please suggest.
Thank you