diff --git a/genesis/ext/pyrender/primitive.py b/genesis/ext/pyrender/primitive.py index 580880498c..8f631d81cf 100644 --- a/genesis/ext/pyrender/primitive.py +++ b/genesis/ext/pyrender/primitive.py @@ -478,7 +478,7 @@ def _remove_from_context(self): glDeleteVertexArrays(1, [self._vaid]) glDeleteBuffers(len(self._buffers), list(self._buffers.values())) self._vaid = None - self._buffers = {} + self._buffers.clear() def _in_context(self): return self._vaid is not None diff --git a/genesis/ext/pyrender/renderer.py b/genesis/ext/pyrender/renderer.py index 2c31db13b7..28c26cc091 100644 --- a/genesis/ext/pyrender/renderer.py +++ b/genesis/ext/pyrender/renderer.py @@ -609,24 +609,26 @@ def _bind_and_draw_primitive(self, primitive, pose, program, flags, env_idx): ########################################################################### def _update_context(self, scene, flags): - # Update meshes - scene_meshes = scene.meshes + # Get existing and new meshes + scene_meshes_new = scene.meshes.copy() + scene_meshes_old = self._meshes - # Add new meshes to context - for mesh in scene_meshes - self._meshes: - for p in mesh.primitives: - p._add_to_context() - - # Remove old meshes from context - for mesh in self._meshes - scene_meshes: + # Remove from context old meshes that are now irrelevant + for mesh in scene_meshes_old - scene_meshes_new: for p in mesh.primitives: p.delete() - self._meshes = scene_meshes.copy() + # Update set of meshes right away, so that the context can be cleaned up correctly in case of failure + self._meshes = scene_meshes_new + + # Add new meshes to context + for mesh in scene_meshes_new - scene_meshes_old: + for p in mesh.primitives: + p._add_to_context() # Update mesh textures mesh_textures = set() - for m in scene_meshes: + for m in scene_meshes_new: for p in m.primitives: mesh_textures |= p.material.textures diff --git a/genesis/ext/pyrender/viewer.py b/genesis/ext/pyrender/viewer.py index d21714ff3c..9b6adf081c 100644 --- a/genesis/ext/pyrender/viewer.py +++ b/genesis/ext/pyrender/viewer.py @@ -1237,7 +1237,7 @@ def start(self, auto_refresh=True): except OpenGL.error.Error: # Invalid OpenGL context. Closing before raising. self.close() - return + raise # At this point, we are all set to display the graphical window, finally! self.set_visible(True)