This is a bug I found a while back which caused me a segmentation fault or other error - I can't remember the occasion, but it was detrimental to add this fix. I think I was adding and then removing objects from the world.
We need to remove the body from the collision interface ONLY if the body is actually still in the World.
Otherwise we get an error from the collision interface when the Body has been removed from the World earlier, but destroyElement() is still used as destructor method, e.g. from the Robot destructor.
Basically, only objects added to the world should exist in the collision interface. If also objects which are NOT part of the world should be able to exist in the collision interface, this PR would be wrong.
But because WorldElement inherently is meant to be part of World (and also are QObject children of World, which was relevant to this bug happening), I assume that the following change is desirable.
This is a bug I found a while back which caused me a segmentation fault or other error - I can't remember the occasion, but it was detrimental to add this fix. I think I was adding and then removing objects from the world.
We need to remove the body from the collision interface ONLY if the body is actually still in the World. Otherwise we get an error from the collision interface when the Body has been removed from the World earlier, but destroyElement() is still used as destructor method, e.g. from the Robot destructor.
Basically, only objects added to the world should exist in the collision interface. If also objects which are NOT part of the world should be able to exist in the collision interface, this PR would be wrong. But because WorldElement inherently is meant to be part of World (and also are QObject children of World, which was relevant to this bug happening), I assume that the following change is desirable.