Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Since I've been investigating issues like these quite thoroughly I figured I'd answer this year old question for people like me who come looking for it.

Basically, removing models on any other thread than the world thread results in a lot of race conditions, all the time. For instance, removing a model while a scene message is being built might lead to the scene message trying to access a now deleted element, resulting in segfaults, null pointers, you name it. I still don't have enough knowledge of the entire system to know what all the possibilities are but I'm sure there's more. Not to mention the memory leaks associated with deleting models... It seems the delete model scenario is not used very often, or these issues would be more prominent (and probably already fixed).

Anyway, if like me you really do need to delete models often, I suggest avoiding doing it directly. You can make sure deleting the model happens on the main thread by sending an entity_delete message to the system rather than calling World::RemoveModel(). That will circumvent at least some of the problems.