erwincoumans / tiny-differentiable-simulator

Tiny Differentiable Simulator is a header-only C++ and CUDA physics library for reinforcement learning and robotics with zero dependencies.
Apache License 2.0
1.23k stars 130 forks source link

Python API segmentation fault #116

Open ErikGartner opened 3 years ago

ErikGartner commented 3 years ago

Using world.get_mb_constraint_solver() and world.set_mb_constraint_solver() will lead to segmentation fault due to double free from both world's destructor and PyBind11's destructor.

One solution is to remove them from the Python API until they are made safe. I can make a PR if this is a desired fix.

erwincoumans commented 3 years ago

Thanks for the report. Indeed, mixing memory allocations from Python as well as in C++ will easily lead to issues when using PyBind11. I'd like to remove the allocations in world and other locations, but it may require a bit of refactoring (breaking the API). Let's leave it open for now, until it is sorted.

erwincoumans commented 3 years ago

One quick way would be to have the world a member of the default constraint solver, with a pointer to it, so it doesn't need to be deleted. Then we can get rid of the new in constructor and delete in the destructor. So the allocation of a alternative constraint solver happens externally.