changeset 729:f953ae5b3732

PyTouhou: Fix GLFW callbacks to be nogil
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 08 Dec 2019 20:13:01 +0100
parents 414f8611f344
children f2c3848dabff
files pytouhou/lib/glfw.pyx
diffstat 1 files changed, 23 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/lib/glfw.pyx	Wed Oct 30 16:27:43 2019 +0100
+++ b/pytouhou/lib/glfw.pyx	Sun Dec 08 20:13:01 2019 +0100
@@ -27,31 +27,35 @@
 OPENGL_ES_API = GLFW_OPENGL_ES_API
 OPENGL_CORE_PROFILE = GLFW_OPENGL_CORE_PROFILE
 
-cdef void error_callback(int a, const char* b):
-    print('GLFW error 0x%x: %s' % (a, b.decode('utf-8')))
+cdef void error_callback(int a, const char* b) nogil:
+    with gil:
+        print('GLFW error 0x%x: %s' % (a, b.decode('utf-8')))
 
 cdef list _global_events = []
 
-cdef void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods):
-    if action != GLFW_PRESS:
-        return
-    if key == GLFW_KEY_ESCAPE:
-        _global_events.append((gui.PAUSE, None))
-    elif key in (GLFW_KEY_P, GLFW_KEY_HOME):
-        _global_events.append((gui.SCREENSHOT, None))
-    elif key == GLFW_KEY_DOWN:
-        _global_events.append((gui.DOWN, None))
-    elif key == GLFW_KEY_F11:
-        _global_events.append((gui.FULLSCREEN, None))
-    elif key == GLFW_KEY_ENTER:
-        if mods & GLFW_MOD_ALT:
+cdef void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) nogil:
+    with gil:
+        if action != GLFW_PRESS:
+            return
+        if key == GLFW_KEY_ESCAPE:
+            _global_events.append((gui.PAUSE, None))
+        elif key in (GLFW_KEY_P, GLFW_KEY_HOME):
+            _global_events.append((gui.SCREENSHOT, None))
+        elif key == GLFW_KEY_DOWN:
+            _global_events.append((gui.DOWN, None))
+        elif key == GLFW_KEY_F11:
             _global_events.append((gui.FULLSCREEN, None))
+        elif key == GLFW_KEY_ENTER:
+            if mods & GLFW_MOD_ALT:
+                _global_events.append((gui.FULLSCREEN, None))
 
-cdef void size_callback(GLFWwindow* window, int width, int height):
-    _global_events.append((gui.RESIZE, (width, height)))
+cdef void size_callback(GLFWwindow* window, int width, int height) nogil:
+    with gil:
+        _global_events.append((gui.RESIZE, (width, height)))
 
-cdef void close_callback(GLFWwindow* window):
-    _global_events.append((gui.EXIT, None))
+cdef void close_callback(GLFWwindow* window) nogil:
+    with gil:
+        _global_events.append((gui.EXIT, None))
 
 cdef void init() except *:
     glfwSetErrorCallback(<GLFWerrorfun>error_callback)