-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to properly destroy/deconstruct the simulator? #333
Comments
The above snippet works fine, i.e., doesn't segfault (due to dubplicate models?) if I don't use from scenario import gazebo as scenario_gazebo
import gym_ignition_models
for sim_idx in range (3):
print(f"Simulation {sim_idx}")
gazebo = scenario_gazebo.GazeboSimulator(step_size=0.001, rtf=1.0, steps_per_run=round((1 / 0.001) / 30))
assert gazebo.initialize()
world = gazebo.get_world()
assert world.insert_model(gym_ignition_models.get_model_file("ground_plane"))
gazebo.run()
gazebo.close() |
Calling I remember in the past segfaults occurring due to plugins, that do not get unloaded when the corresponding model or world is deleted (gazebosim/gz-sim#113). However, you completely destroy the simulator, and it should be unrelated. You can try to find out the incriminated line calling a script (as simple as possible) with: Just checking, do you have any custom plugins in your world? |
Valgrind traces the segfault back to ign-rendering and the sensor plugin. Apparently, there is a dangling reference to the previous sun, which has been destroyed, and following the null pointer leads to a segfault. This would also be in line with the error messages from SceneManager stating that the model already exists for each model being inserted.
If I remove the sensor plugin from the simulation, it runs as expected. However, I do need it to extract sensor data from the simulation (images in my case). I tried to manually insert the plugin (via
From ignition's point of view no. From scenario's point of view maybe, since I am using the sensor plugin to get camera images. |
This was my suspicion, and I'm afraid we cannot do much from downstream. My suggestion is to compile ign-gazebo either in
or, if you already have an existing workspace, you can just rebuild ign-gazebo as follows:
Then, use again valgrind and find the exact line. The fix could be one-liner, and submitting an upstream fix could be easy. Note that, once you have all this setup ready, you can use your local colcon setup with the fix, you don't have to wait that the upstream PR will get merged / released. |
Thanks for the detailed explanation! I'll close this issue since it is an upstream problem. Unfortunately, I currently don't have the time to fix this upstream myself, so it will have to wait until my schedule frees and I can work on "extracurriculars" again. That said, a workaround that I found is to run the simulator in a subprocess (via |
I want to run a series of simulations in scenario and one instance of the simulation has many moving parts. The robot will interact with different objects, modifying their initial state. To clean up between simulations, I thought that it is easiest to completely destroy the simulation and rebuild it from scratch. This is the safest way to ensure that there is no residue from the previous simulation/run.
My naive approach was
which fails with a segmentation fault
Segmentation fault log
How would I correctly close the simulator and clean up once the simulation has finished?
The text was updated successfully, but these errors were encountered: