Gazebo crashes with segfaults when spawning and deleting objects repeatedly

asked 2019-06-30 18:29:41 -0500

guerteltier gravatar image

Hi all,

I am working on an intralogistics simulation application in gazebo and I need to spawn and delete objects often. Unfortunately I ran into a lot of problems and I hope to find some useful advices what I can do here. Many thanks in advance!

First I see a decreasing real time factor after spawning and deleting some objects, which was already discussed here:

http://answers.gazebosim.org/question...

http://answers.gazebosim.org/question...

http://answers.gazebosim.org/question...

The suggested workaround using the "entity_delete" request instead of the RemoveModel() function did not help. The simulation is still slowing down.

But even worse, gazebo crashes sometimes after deleting an object with a segfault error (using either the "entity_delete" request or the RemoveModel function). I am using gazebo 9.9.0 with ROS melodic 1.14.3.

To reproduce the error I created a simple minimal example, which crashes on my machine after spawning and deleting a few objects:


Simple spawning script, spawner.cpp:

#include <iostream>
#include <string>
#include <chrono>
#include <thread>

int main()
{
        int i=0;
        std::chrono::duration<int> duration(2);
        while(true)
        {
                auto start_time = std::chrono::steady_clock::now();
                system(std::string("gz model -f simple_box.sdf -x -4.6 -y -0.6 -z 0.5 -m spawned_" + std::to_string(i)).c_str());
                i++;
                auto end_time = start_time + duration;
                std::cout << "spawn" <<  i  <<  std::endl;
                std::this_thread::sleep_until(end_time);
        }
}

Simple despawning script, despawner.cpp

#include <iostream>
#include <string>
#include <chrono>
#include <thread>

int main()
{
    int i=0;
    std::chrono::duration<int> duration(2);
    while(true)
    {
        auto start_time = std::chrono::steady_clock::now();
        system(std::string("gz model -d -m spawned_" + std::to_string(i)).c_str());
        i++;
        std::cout << "despawn " << i<< std::endl;
        auto end_time = start_time + duration;
        std::this_thread::sleep_until(end_time);
    }       
}

simple_box.sdf:

<?xml version='1.0'?>
<sdf version="1.4">
<model name="my_model">
  <pose>0 0 0.5 0 0 0</pose>
    <link name="link">
      <inertial>
    <mass>1.0</mass>
    <inertia> <!-- inertias are tricky to compute -->
      <!-- http://gazebosim.org/tutorials?tut=inertia&cat=build_robot -->
      <ixx>0.083</ixx>       <!-- for a box: ixx = 0.083 * mass * (y*y + z*z) -->
      <ixy>0.0</ixy>         <!-- for a box: ixy = 0 -->
      <ixz>0.0</ixz>         <!-- for a box: ixz = 0 -->
      <iyy>0.083</iyy>       <!-- for a box: iyy = 0.083 * mass * (x*x + z*z) -->
      <iyz>0.0</iyz>         <!-- for a box: iyz = 0 -->
      <izz>0.083</izz>       <!-- for a box: izz = 0.083 * mass * (x*x + y*y) -->
    </inertia>
      </inertial>
      <collision name="collision">
    <geometry>
      <box>
        <size>0.1 0.1 0.1</size>
      </box>
    </geometry>
      </collision>
      <visual name="visual">
    <geometry>
      <box>
        <size>0.1 0.1 0.1</size>
      </box>
    </geometry>
      </visual>
    </link>
  </model>
</sdf>

Compiling:

g++ -std=c++11 spawner.cpp -o spawner.out

g++ -std=c++11 despawner.cpp -o despawner.out

Running:

Start Gazebo with an empty map

roslaunch gazebo_ros empty_world.launch verbose:=true

Run the spawner:

./spawner.out

After some seconds, launch the despawner

./despawner.out


Running gazebo with valgrind crashes with the following error:

==9571== Conditional jump or move ...
(more)
edit retag flag offensive close merge delete

Comments

I've also had this issue - you should consider opening an issue: https://bitbucket.org/osrf/gazebo/

you code example successfully reproduces this bug on my machine (also gazebo 9.9.0) under Kinetic

Peter Mitrano gravatar imagePeter Mitrano ( 2019-07-04 09:44:40 -0500 )edit