softbankrobotics-research / qibullet

Bullet simulation for SoftBank Robotics robots
Apache License 2.0
146 stars 38 forks source link

Segmentation fault on macOS #27

Open aadevmobile opened 4 years ago

aadevmobile commented 4 years ago

Hello, When running the pepper_basic or any other test it loads the model and crashes.. I'm not sure why. If I run a pybullet test it works.

AA-MacBook-Pro:peppersim aa$ python peper_basic.py pybullet build time: Mar 10 2020 14:41:15 Version = 4.1 INTEL-14.2.16 Vendor = Intel Inc. Renderer = Intel(R) Iris(TM) Plus Graphics 650 b3Printf: Selected demo: Physics Server startThreads creating 1 threads. starting thread 0 started thread 0 MotionThreadFunc thread started Fatal Python error: Segmentation fault

Current thread 0x000070000eccd000 (most recent call first): File "/Users/aa/Library/Python/2.7/lib/python/site-packages/qibullet/camera.py", line 265 in _getCameraImage File "/Users/aa/Library/Python/2.7/lib/python/site-packages/qibullet/camera.py", line 386 in _frameExtractionLoop File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 754 in run File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 801 in __bootstrap_inner File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 774 in __bootstrap

Thread 0x0000000103c45dc0 (most recent call first): File "/Users/aa/Library/Python/2.7/lib/python/site-packages/qibullet/camera.py", line 152 in getFrame File "/Users/aa/Library/Python/2.7/lib/python/site-packages/qibullet/camera.py", line 304 in _waitForCorrectImageFormat File "/Users/aa/Library/Python/2.7/lib/python/site-packages/qibullet/camera.py", line 365 in subscribe File "/Users/aa/Library/Python/2.7/lib/python/site-packages/qibullet/robot_virtual.py", line 205 in subscribeCamera File "peper_basic.py", line 23 in main File "peper_basic.py", line 32 in Segmentation fault: 11

mbusy commented 4 years ago

Hi, Thanks for reporting the issue. Could you specify which version of qiBullet you're currently using, and your OS version ?

Edit: Looking at your logs, my guess is that the combination Mac OS + default camera renderer issues the segfault. Could you run the following script and tell me if it works ? (If it doesn't work, try replacing gui=True by gui=False)

from qibullet import SimulationManager
from qibullet import PepperVirtual

def main():
    simulation_manager = SimulationManager()
    client = simulation_manager.launchSimulation(gui=True)
    pepper = simulation_manager.spawnPepper(client, spawn_ground_plane=True)
    raw_input("Press enter to stop the simulation")
    simulation_manager.stopSimulation(client)

if __name__ == "__main__":
    main()
aadevmobile commented 4 years ago

Hi mbusy,

thank you very much for your fast reply

With the sample you provided it doesn't crash but it stops responding within the window; I'm able to press enter in the terminal to exit it. Without the gui = False it seems to run ok.

what are the minimum requirements to run it? I mean could it be that my mac specs can't handle it?

mbusy commented 4 years ago

You're welcome. I don't think that your specs are the problem, I believe that the OS doesn't handle OpenGL3 successfully... The way I see it you've got 2 problems:

Regarding the first issue, one possible solution would be to replace that line by

pybullet.connect(pybullet.GUI, options="--opengl2")

Regarding the second issue, I'm guessing that using pybullet.ER_TINY_RENDERER instead of pybullet.ER_BULLET_HARDWARE_OPENGL (here) might fix the issue, but that's not ideal.

I'll test this as soon as possible, but I don't have a system running Mac OS at my disposal (and with the COVID situation I might have some troubles getting my hands on one). I'll eventually test that on a VM

aadevmobile commented 4 years ago

Hi mbusy,

mbusy commented 4 years ago

Alright, it was worth a shot, thanks for testing :smile:.

Another explanation for the first problem could be the simulation step thread. On Windows / Linux, running a simulation with a GUI will automatically spawn an additional thread, stepping the simulation. If I remember correctly, in Mac OS that thread might not be spawned because of OS limitations... So we would need to manually spawn such a thread. Could be done by connecting to a pybullet GUI_SERVER, and then connecting to the created server using pybullet.connect(pybullet.SHARED_MEMORY)

mbusy commented 4 years ago

This comment (issue in bullet3) seems to confirm it. I just hope that a Python thread will work, instead of a big while loop

lubiluk commented 4 years ago

Hi, I'm also experiencing crashes on MacOS and I'm pretty sure it's related to camera. Without camera use everything seems to work well. For instance this works (https://github.com/softbankrobotics-research/qibullet/blob/master/examples/robot_joint_control.py) while this doesn't (https://github.com/softbankrobotics-research/qibullet/blob/master/examples/pepper_basic.py).

The line that makes everything crash is: handle = pepper.subscribeCamera(PepperVirtual.ID_CAMERA_TOP)

I hope it helps with investigation...

mbusy commented 4 years ago

Thanks for the feedback @lubiluk, yes the camera is indeed a source of bug on macOS, even when using ER_TINY_RENDERER over ER_BULLET_HARDWARE_OPENGL (see previous comment)...

There is also the problem of the freezing GUI: when you run the robot_joint_control example, do you manage to "nudge" (for lack of a better word) the head (or any link) of the robot, by clicking and dragging it with your mouse ?

lubiluk commented 4 years ago

There is also the problem of the freezing GUI: when you run the robot_joint_control example, do you manage to "nudge" (for lack of a better word) the head (or any link) of the robot, by clicking and dragging it with your mouse ?

Nudging the the robot seems alright. It doesn't freeze on my machine:

Version = 4.1 ATI-3.10.18
Vendor = ATI Technologies Inc.
Renderer = AMD Radeon R9 M370X OpenGL Engine
elggem commented 3 years ago

Hi, I looked a bit into this problem and found the following:

There is two crashes happening in the _getCameraImage function, one for pybullet.getLinkState and one for pybullet.getCameraImage.

When I replace the first call to pybullet.getLinkState and assign zero vectors to pos_world and q_world it works until the call to pybullet.getCameraImage but then segfaults. Changing the renderer to ER_TINY_RENDERER does not help even in that case the program segfaults.

I dont know how else to proceed to investigate this, but maybe it is helpful to somebody.

mbusy commented 3 years ago

@elggem Thanks for the info, even though I don't have a lot of time to work on this issue it's always appreciated. The fact that either renderer causes a segfault was already known, but I wasn't aware that pybullet.getLinkState also causes a crash, thanks for reporting