diff --git a/examples/ExampleBrowser/main.cpp b/examples/ExampleBrowser/main.cpp index 46bbd2b0b..180f94a77 100644 --- a/examples/ExampleBrowser/main.cpp +++ b/examples/ExampleBrowser/main.cpp @@ -20,8 +20,51 @@ static double gMinUpdateTimeMicroSecs = 1000.; +static bool interrupted=false; +static OpenGLExampleBrowser* sExampleBrowser=0; + +#ifndef _WIN32 +#include +#include +#include +static void cleanup(int signo) +{ +printf("SIG cleanup: %d\n", signo); + + if (interrupted) { // this is the second time, we're hanging somewhere + // if (example) { + // example->abort(); + // } + + b3Printf("Aborting and deleting SharedMemoryCommon object"); + sleep(1); + delete sExampleBrowser; + sExampleBrowser = 0; + errx(EXIT_FAILURE, "aborted example on signal %d", signo); + } else + { + b3Printf("no action"); + } + interrupted = true; + warnx("caught signal %d", signo); +} +#endif//_WIN32 + int main(int argc, char* argv[]) { + +#ifndef _WIN32 + struct sigaction action; + memset(&action, 0x0, sizeof(action)); + action.sa_handler = cleanup; + static const int signos[] = { SIGHUP, SIGINT, SIGQUIT, SIGABRT, SIGSEGV, SIGPIPE, SIGTERM }; + for (int ii(0); ii < sizeof(signos) / sizeof(*signos); ++ii) { + if (0 != sigaction(signos[ii], &action, NULL)) { + err(EXIT_FAILURE, "signal %d", signos[ii]); + } + } +#endif + { b3CommandLineArgs args(argc, argv); b3Clock clock; @@ -31,6 +74,7 @@ int main(int argc, char* argv[]) examples.initExampleEntries(); OpenGLExampleBrowser* exampleBrowser = new OpenGLExampleBrowser(&examples); + sExampleBrowser = exampleBrowser;//for etc, cleanup shared memory bool init = exampleBrowser->init(argc, argv); exampleBrowser->registerFileImporter(".urdf", ImportURDFCreateFunc); exampleBrowser->registerFileImporter(".sdf", ImportSDFCreateFunc); @@ -57,7 +101,7 @@ int main(int argc, char* argv[]) clock.reset(); exampleBrowser->update(deltaTimeInSeconds); } - } while (!exampleBrowser->requestedExit()); + } while (!exampleBrowser->requestedExit() && !interrupted); } delete exampleBrowser; diff --git a/examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp b/examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp index 8f01bfb5a..e8d43c8b1 100644 --- a/examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp +++ b/examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp @@ -86,7 +86,7 @@ public: b3PhysicsClientHandle b3CreateInProcessPhysicsServerAndConnectMainThread(int argc, char* argv[]) { InProcessPhysicsClientSharedMemoryMainThread* cl = new InProcessPhysicsClientSharedMemoryMainThread(argc, argv, 1); - cl->setSharedMemoryKey(SHARED_MEMORY_KEY); + cl->setSharedMemoryKey(SHARED_MEMORY_KEY+1); cl->connect(); return (b3PhysicsClientHandle ) cl; } @@ -94,7 +94,7 @@ b3PhysicsClientHandle b3CreateInProcessPhysicsServerAndConnectMainThread(int arg b3PhysicsClientHandle b3CreateInProcessPhysicsServerAndConnectMainThreadSharedMemory(int argc, char* argv[]) { InProcessPhysicsClientSharedMemoryMainThread* cl = new InProcessPhysicsClientSharedMemoryMainThread(argc, argv, 0); - cl->setSharedMemoryKey(SHARED_MEMORY_KEY); + cl->setSharedMemoryKey(SHARED_MEMORY_KEY+1); cl->connect(); return (b3PhysicsClientHandle ) cl; } diff --git a/examples/pybullet/gym/pybullet_envs/bullet/minitaur_gym_env.py b/examples/pybullet/gym/pybullet_envs/bullet/minitaur_gym_env.py index d74906408..6e7872a61 100644 --- a/examples/pybullet/gym/pybullet_envs/bullet/minitaur_gym_env.py +++ b/examples/pybullet/gym/pybullet_envs/bullet/minitaur_gym_env.py @@ -278,7 +278,7 @@ class MinitaurBulletEnv(gym.Env): nearVal=0.1, farVal=100.0) (_, _, px, _, _) = self._pybullet_client.getCameraImage( width=RENDER_WIDTH, height=RENDER_HEIGHT, viewMatrix=view_matrix, - projectionMatrix=proj_matrix) + projectionMatrix=proj_matrix, renderer=pybullet.ER_BULLET_HARDWARE_OPENGL) rgb_array = np.array(px) rgb_array = rgb_array[:, :, :3] return rgb_array diff --git a/examples/pybullet/gym/pybullet_envs/env_bases.py b/examples/pybullet/gym/pybullet_envs/env_bases.py index 5e2017e42..f291d556b 100644 --- a/examples/pybullet/gym/pybullet_envs/env_bases.py +++ b/examples/pybullet/gym/pybullet_envs/env_bases.py @@ -82,7 +82,7 @@ class MJCFBaseBulletEnv(gym.Env): (_, _, px, _, _) = p.getCameraImage( width=self._render_width, height=self._render_height, viewMatrix=view_matrix, projectionMatrix=proj_matrix, - #renderer=p.ER_BULLET_HARDWARE_OPENGL + renderer=p.ER_BULLET_HARDWARE_OPENGL ) rgb_array = np.array(px) rgb_array = rgb_array[:, :, :3] diff --git a/examples/pybullet/pybullet.c b/examples/pybullet/pybullet.c index e1df46636..82249434a 100644 --- a/examples/pybullet/pybullet.c +++ b/examples/pybullet/pybullet.c @@ -440,13 +440,16 @@ static PyObject* pybullet_connectPhysicsServer(PyObject* self, PyObject* args, P command = b3InitSyncBodyInfoCommand(sm); statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command); statusType = b3GetStatusType(statusHandle); -#if 0 if (statusType != CMD_BODY_INFO_COMPLETED) { - PyErr_SetString(SpamError, "b3InitSyncBodyInfoCommand failed."); - return NULL; + printf("Connection terminated, couldn't get body info\n"); + b3DisconnectSharedMemory(sm); + sm = 0; + sPhysicsClients1[freeIndex] = 0; + sPhysicsClientsGUI[freeIndex] = 0; + sNumPhysicsClients++; + return -1; } -#endif } } return PyInt_FromLong(freeIndex); diff --git a/setup.py b/setup.py index 395bd22b9..5cae36c27 100644 --- a/setup.py +++ b/setup.py @@ -440,7 +440,7 @@ print("-----") setup( name = 'pybullet', - version='1.3.8', + version='1.4.0', description='Official Python Interface for the Bullet Physics SDK specialized for Robotics Simulation and Reinforcement Learning', long_description='pybullet is an easy to use Python module for physics simulation, robotics and deep reinforcement learning based on the Bullet Physics SDK. With pybullet you can load articulated bodies from URDF, SDF and other file formats. pybullet provides forward dynamics simulation, inverse dynamics computation, forward and inverse kinematics and collision detection and ray intersection queries. Aside from physics simulation, pybullet supports to rendering, with a CPU renderer and OpenGL visualization and support for virtual reality headsets.', url='https://github.com/bulletphysics/bullet3',