From 86e1fa671b63e026f7dff07122cb1b307b3609f7 Mon Sep 17 00:00:00 2001 From: Jeff Smith Date: Sat, 2 Dec 2023 13:59:01 -0600 Subject: [PATCH 1/2] Treat any falsy context as invalid --- OpenGL/GL/pointers.py | 2 +- OpenGL/contextdata.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/OpenGL/GL/pointers.py b/OpenGL/GL/pointers.py index 1906a081..0c2c15c9 100644 --- a/OpenGL/GL/pointers.py +++ b/OpenGL/GL/pointers.py @@ -276,7 +276,7 @@ def glRenderMode( newMode ): # Okay, now that the easy cases are out of the way... # Do we have a pre-stored pointer about which the user already knows? context = platform.GetCurrentContext() - if context == 0: + if not context: raise error.Error( """Returning from glRenderMode without a valid context!""" ) diff --git a/OpenGL/contextdata.py b/OpenGL/contextdata.py index 2639631c..39ae9965 100644 --- a/OpenGL/contextdata.py +++ b/OpenGL/contextdata.py @@ -35,7 +35,7 @@ def getContext( context = None ): """ if context is None: context = platform.GetCurrentContext() - if context == 0: + if not context: from OpenGL import error raise error.Error( """Attempt to retrieve context when no valid context""" From 43bfebca84b5e255741ed20b188c09dbbbc944a7 Mon Sep 17 00:00:00 2001 From: Jeff Smith Date: Sat, 2 Dec 2023 14:02:27 -0600 Subject: [PATCH 2/2] Return type for *GetCurrentContext is a pointer on all platforms --- OpenGL/platform/darwin.py | 4 +++- OpenGL/platform/egl.py | 4 +++- OpenGL/platform/glx.py | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/OpenGL/platform/darwin.py b/OpenGL/platform/darwin.py index bc0516bb..0edabe17 100644 --- a/OpenGL/platform/darwin.py +++ b/OpenGL/platform/darwin.py @@ -59,7 +59,9 @@ def GLE(self): return self.GLUT @baseplatform.lazy_property def GetCurrentContext( self ): - return self.CGL.CGLGetCurrentContext + CGLGetCurrentContext = self.CGL.CGLGetCurrentContext + CGLGetCurrentContext.restype = ctypes.c_void_p + return CGLGetCurrentContext def getGLUTFontPointer( self, constant ): """Platform specific function to retrieve a GLUT font pointer diff --git a/OpenGL/platform/egl.py b/OpenGL/platform/egl.py index 55fbb0be..5dd3befe 100644 --- a/OpenGL/platform/egl.py +++ b/OpenGL/platform/egl.py @@ -103,7 +103,9 @@ def GLE( self ): DEFAULT_FUNCTION_TYPE = staticmethod( ctypes.CFUNCTYPE ) @baseplatform.lazy_property def GetCurrentContext( self ): - return self.EGL.eglGetCurrentContext + eglGetCurrentContext = self.EGL.eglGetCurrentContext + eglGetCurrentContext.restype = ctypes.c_void_p + return eglGetCurrentContext def getGLUTFontPointer( self, constant ): """Platform specific function to retrieve a GLUT font pointer diff --git a/OpenGL/platform/glx.py b/OpenGL/platform/glx.py index 3fd684ac..e425e7bf 100644 --- a/OpenGL/platform/glx.py +++ b/OpenGL/platform/glx.py @@ -97,7 +97,9 @@ def GLE(self): # really kosher... @baseplatform.lazy_property def GetCurrentContext(self): - return self.GLX.glXGetCurrentContext + glXGetCurrentContext = self.GLX.glXGetCurrentContext + glXGetCurrentContext.restype = ctypes.c_void_p + return glXGetCurrentContext def getGLUTFontPointer(self, constant): """Platform specific function to retrieve a GLUT font pointer