Skip to content

Commit 444b46c

Browse files
duburcqaYilingQiao
authored andcommitted
[BUG FIX] Fix backend fallback mechanism causing deadlock in Rasterizer. (Genesis-Embodied-AI#1546)
1 parent a730038 commit 444b46c

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

genesis/ext/pyrender/primitive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ def _remove_from_context(self):
478478
glDeleteVertexArrays(1, [self._vaid])
479479
glDeleteBuffers(len(self._buffers), list(self._buffers.values()))
480480
self._vaid = None
481-
self._buffers = {}
481+
self._buffers.clear()
482482

483483
def _in_context(self):
484484
return self._vaid is not None

genesis/ext/pyrender/renderer.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -609,24 +609,26 @@ def _bind_and_draw_primitive(self, primitive, pose, program, flags, env_idx):
609609
###########################################################################
610610

611611
def _update_context(self, scene, flags):
612-
# Update meshes
613-
scene_meshes = scene.meshes
612+
# Get existing and new meshes
613+
scene_meshes_new = scene.meshes.copy()
614+
scene_meshes_old = self._meshes
614615

615-
# Add new meshes to context
616-
for mesh in scene_meshes - self._meshes:
617-
for p in mesh.primitives:
618-
p._add_to_context()
619-
620-
# Remove old meshes from context
621-
for mesh in self._meshes - scene_meshes:
616+
# Remove from context old meshes that are now irrelevant
617+
for mesh in scene_meshes_old - scene_meshes_new:
622618
for p in mesh.primitives:
623619
p.delete()
624620

625-
self._meshes = scene_meshes.copy()
621+
# Update set of meshes right away, so that the context can be cleaned up correctly in case of failure
622+
self._meshes = scene_meshes_new
623+
624+
# Add new meshes to context
625+
for mesh in scene_meshes_new - scene_meshes_old:
626+
for p in mesh.primitives:
627+
p._add_to_context()
626628

627629
# Update mesh textures
628630
mesh_textures = set()
629-
for m in scene_meshes:
631+
for m in scene_meshes_new:
630632
for p in m.primitives:
631633
mesh_textures |= p.material.textures
632634

genesis/ext/pyrender/viewer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ def start(self, auto_refresh=True):
12371237
except OpenGL.error.Error:
12381238
# Invalid OpenGL context. Closing before raising.
12391239
self.close()
1240-
return
1240+
raise
12411241

12421242
# At this point, we are all set to display the graphical window, finally!
12431243
self.set_visible(True)

0 commit comments

Comments
 (0)