bulletphysics / bullet3

Bullet Physics SDK: real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc.
http://bulletphysics.org
Other
12.66k stars 2.88k forks source link

Segmentation Fault when loading and removing soft bodies #3003

Closed huy-ha closed 3 years ago

huy-ha commented 4 years ago

Issue: When soft bodies are imported, deleted, and reimported, a segmentation fault occurs.

Setup:

To reproduce:

import pybullet as p
import pybullet_data
from time import sleep
from numpy import pi

p.connect(p.GUI)
p.setAdditionalSearchPath(pybullet_data.getDataPath())
p.setRealTimeSimulation(1)
p.resetSimulation(p.RESET_USE_DEFORMABLE_WORLD)
p.setGravity(0, 0, -9.8)

plane_id = p.loadURDF(fileName='plane.urdf')
while True:
    cloth_id = p.loadSoftBody(
        fileName='assets/cloth.obj',
        basePosition=[0, 0, 0.1],
        baseOrientation=p.getQuaternionFromEuler([pi / 2, 0, 0])
    )
    sleep(5)
    p.removeBody(cloth_id)

where assets/cloth.obj is just a subdivided plane mesh. Usually, the segfault occurs within less than 5 iterations whether or not the cloth is interacted with by applying a force with the mouse in the GUI.

❯ python test.py    
pybullet build time: Aug 11 2020 06:37:31
startThreads creating 1 threads.
starting thread 0
started thread 0
argc=2
argv[0] = --unused
argv[1] = --start_demo_name=Physics Server
ExampleBrowserThreadFunc started
X11 functions dynamically loaded using dlopen/dlsym OK!
X11 functions dynamically loaded using dlopen/dlsym OK!
Creating context
Created GL 3.3 context
Direct GLX rendering context obtained
Making context current
GL_VENDOR=Intel Open Source Technology Center
GL_RENDERER=Mesa DRI Intel(R) HD Graphics 4600 (HSW GT2)
GL_VERSION=4.5 (Core Profile) Mesa 20.3.0-devel (git-0c97e60 2020-08-13 bionic-oibaf-ppa)
GL_SHADING_LANGUAGE_VERSION=4.50
pthread_getconcurrency()=0
Version = 4.5 (Core Profile) Mesa 20.3.0-devel (git-0c97e60 2020-08-13 bionic-oibaf-ppa)
Vendor = Intel Open Source Technology Center
Renderer = Mesa DRI Intel(R) HD Graphics 4600 (HSW GT2)
b3Printf: Selected demo: Physics Server
startThreads creating 1 threads.
starting thread 0
started thread 0
MotionThreadFunc thread started
ven = Intel Open Source Technology Center
Workaround for some crash in the Intel OpenGL driver on Linux/Ubuntu
ven = Intel Open Source Technology Center
Workaround for some crash in the Intel OpenGL driver on Linux/Ubuntu
[1]    16691 segmentation fault (core dumped)  python test.py

I've found that that changing the parameters to p.loadSoftBody() will cause the segfault to happen a different iteration, but it always occurs.

If I don't remove the cloth, then the segfault doesn't seem to happen.

huy-ha commented 4 years ago

To give some background, I need a good way to reset a cloth after some interaction with it. I've tried saveState() and loadState() but it doesn't look like the state of deformables are saved in these states. resetBasePositionAndOrientation() also doesn't do the trick.

erwincoumans commented 4 years ago

Thanks for the report, we need to fix it.

indeed, cloth is an experimental new feature, most of the APIs only apply to rigid/multibodies.

huy-ha commented 4 years ago

Thanks Erwin!