-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathpatch_pyrender.py
More file actions
49 lines (40 loc) · 1.48 KB
/
patch_pyrender.py
File metadata and controls
49 lines (40 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
import sys
import inspect
import pyrender
import pyrender.platforms.pyglet_platform as pyglet_mod
import pyrender.viewer as viewer_mod
def patch_pyglet():
pyglet_file = inspect.getfile(pyglet_mod)
print(f"Patching {pyglet_file}")
with open(pyglet_file, 'r') as f:
content = f.read()
old_except = "except pyglet.window.NoSuchConfigException as e:"
new_except = "except (pyglet.window.NoSuchConfigException, pyglet.gl.ContextException):"
if old_except in content:
content = content.replace(old_except, new_except)
else:
print("Warning: Could not find except block in pyglet_platform.py")
with open(pyglet_file, 'w') as f:
f.write(content)
def patch_viewer():
viewer_file = inspect.getfile(viewer_mod)
print(f"Patching {viewer_file}")
with open(viewer_file, 'r') as f:
content = f.read()
old_except = "except pyglet.window.NoSuchConfigException:"
new_except = "except (pyglet.window.NoSuchConfigException, pyglet.gl.ContextException):"
if old_except in content:
content = content.replace(old_except, new_except)
else:
print("Warning: Could not find except block in viewer.py")
with open(viewer_file, 'w') as f:
f.write(content)
if __name__ == "__main__":
try:
patch_pyglet()
patch_viewer()
print("Patched pyrender successfully")
except Exception as e:
print(f"Error patching pyrender: {e}")
sys.exit(1)