From 4b12b5bf8959cfd104c253aa433ad64e2757c544 Mon Sep 17 00:00:00 2001 From: Samarth Brahmbhatt Date: Wed, 13 Jan 2021 16:29:26 -0800 Subject: [PATCH] avoid calling glfwTerminate( ) inside callback [GLFW guidelines](https://www.glfw.org/docs/3.3/intro_guide.html#reentrancy) say `glfwTerminate()` should not be called inside an event callback, since it is not reentrant. This fixes segfault when closing the `MjViewer` window by pressing ESC. --- mujoco_py/mjviewer.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mujoco_py/mjviewer.py b/mujoco_py/mjviewer.py index cf9ed6e3..18e0c5db 100644 --- a/mujoco_py/mjviewer.py +++ b/mujoco_py/mjviewer.py @@ -63,8 +63,7 @@ def key_callback(self, window, key, scancode, action, mods): if action == glfw.RELEASE and key == glfw.KEY_ESCAPE: print("Pressed ESC") print("Quitting.") - glfw.terminate() - sys.exit(0) + glfw.set_window_should_close(window, 1) def _cursor_pos_callback(self, window, xpos, ypos): if not (self._button_left_pressed or self._button_right_pressed):