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
Error Deleting Components allocated on the Heap
- Vinay Kumar
- Posts: 34
- Joined: Thu Nov 08, 2018 6:50 am
- Dimitar Stanev
- Posts: 1096
- Joined: Fri Jan 31, 2014 5:14 am
Re: Error Deleting Components allocated on the Heap
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.
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.
- Vinay Kumar
- Posts: 34
- Joined: Thu Nov 08, 2018 6:50 am
Re: Error Deleting Components allocated on the Heap
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
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
- Attachments
-
- screenshot.png (135.74 KiB) Viewed 145 times