[MacPorts] #71926: OpenGL.error.Error: Attempt to retrieve context when no valid context
MacPorts
noreply at macports.org
Fri Jan 24 10:42:26 UTC 2025
#71926: OpenGL.error.Error: Attempt to retrieve context when no valid context
--------------------------------------+-----------------------
Reporter: krotalias | Owner: (none)
Type: defect | Status: new
Priority: Normal | Milestone:
Component: ports | Version: 2.10.5
Keywords: opengl, freeglut, python | Port: py-opengl
--------------------------------------+-----------------------
Python opengl used to work with freeglut. However, now there is a problem
getting the context. Editing
/opt/local/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10
/site-packages/OpenGL/platform/ctypesloader.py
and replacing
fullName = util.find_library( name ) for
fullName = "/System/Library/Frameworks/{}.framework/{}".format(name,name)
as discussed here --
https://github.com/PixarAnimationStudios/OpenUSD/issues/1372 -- fixes the
problem.
The monkeypatch_ctypes approach also works, and one must import it before
opengl in any code using pyopengl:
# https://github.com/PixarAnimationStudios/OpenUSD/issues/1372
#
/opt/local/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12
/site-packages/OpenGL/platform/ctypesloader.py
def monkeypatch_ctypes():
import os
import ctypes.util
uname = os.uname()
if uname.sysname == "Darwin" and uname.release >= "20.":
real_find_library = ctypes.util.find_library
def find_library(name):
if name in {"OpenGL", "GLUT"}: # add more names here if
necessary
return
f"/System/Library/Frameworks/{name}.framework/{name}"
return real_find_library(name)
ctypes.util.find_library = find_library
return
monkeypatch_ctypes()
--------------------------------
The version of the python used is irrelevant. The bug also appears for
python 3.13
I tested on macos Catalina and Monterey, because I do not have access to a
newer Mac.
Thank you.
--
Ticket URL: <https://trac.macports.org/ticket/71926>
MacPorts <https://www.macports.org/>
Ports system for macOS
More information about the macports-tickets
mailing list