ODE collision space not deleted when model is removed from the world

Create issue
Issue #1780 new
Elte Hupkes created an issue

When removing models from the world using ODE, the collision space for these models lingers, causing the simulation to become quadratically slower over time.

The collision space for a model is tracked by ODEPhysics::dataPtr::spaces, which is populated in ODEPhysics::CreateLink() (https://bitbucket.org/osrf/gazebo/src/47c6f792045ae8e67f3aa3ba64c07006151f470c/gazebo/physics/ode/ODEPhysics.cc?at=default&fileviewer=file-view-default#ODEPhysics.cc-494). However, no code is present anywhere to remove this space once a model is no longer active. This causes the quadratic performance degredation as further detailed in this question on Gazebo Answers.

It appears to me the solution is to introduce an ODEModel class to manage the collision space. This is exactly what I have done in the attached patch file, which appears to make the slowdown go away.

Comments (6)

  1. Elte Hupkes reporter

    There is an additional problem that arises whenever a link has the self_collide property. In that case it creates its own collision space, which is then also not deleted. I'm attaching a patch file with a possible fix for this.

  2. Ian Chen

    this is a great find! thanks for looking into this

    we should somehow come up with a test for this patch and get it in

  3. Elte Hupkes reporter

    @iche033 No problem, I really need this to work so my motives are rather selfish ;).

    I just realized there might be some issues with applying these patches. I am working on a custom branch which I tend to merge with the last stable tag of Gazebo available (currently it's 6.5.1) to fix any and all issues I run into when I find them. Especially the first patch was from before I merged 6.5.1 though so it might be hard to integrate. In addition I've some other fixes and workarounds in place in order to, frankly, just get this to work.

    The truth is that fixing this issue does not even matter without some of the other fixes I implemented:

    • Issue #1142 (I replaced Entity::parentEntity with a weak pointer to prevent reference loops)
    • When links are connected with joints, the link <- joint -> link also results in a circular reference. I found that in order for things to be properly deleted you need to:
      • Change the Link joint lists to use weak pointer (either that or change the Joint link references to use weak pointers, but the latter is more work and affects all joint implementations in all physics engines).
      • Change JointControllerPrivate::model and Joint::model to weak pointers

    I want to share all these but I've both limited time and limited knowledge of Mercurial so I'm not sure how to approach this.

  4. Log in to comment