Error Deleting Components allocated on the Heap

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Vinay Kumar
Posts: 34
Joined: Thu Nov 08, 2018 6:50 am

Error Deleting Components allocated on the Heap

Post by Vinay Kumar » Thu Nov 21, 2019 10:22 pm

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

Tags:

User avatar
Dimitar Stanev
Posts: 1096
Joined: Fri Jan 31, 2014 5:14 am

Re: Error Deleting Components allocated on the Heap

Post by Dimitar Stanev » Fri Nov 22, 2019 8:01 am

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.

User avatar
Vinay Kumar
Posts: 34
Joined: Thu Nov 08, 2018 6:50 am

Re: Error Deleting Components allocated on the Heap

Post by Vinay Kumar » Fri Nov 22, 2019 8:44 pm

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
Attachments
screenshot.png
screenshot.png (135.74 KiB) Viewed 150 times

POST REPLY