Skip to content

Commit

Permalink
handle vision sensor cleanup properly
Browse files Browse the repository at this point in the history
  • Loading branch information
cremebrule committed Dec 13, 2024
1 parent e31c12a commit 6275ab9
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions omnigibson/sensors/vision_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,16 +575,28 @@ def _remove_modality_from_backend(self, modality):
modality (str): Name of the modality to remove from the Replicator backend
"""
if self._annotators.get(modality, None) is not None:
self._annotators[modality].detach([self._render_product])
# Passing an explicit list is bugged -- see omni source code
# So we only pass in the product directly, which gets post-processed correctly
self._annotators[modality].detach(self._render_product)
self._annotators[modality] = None

def remove(self):
# Remove from global sensors dictionary
self.SENSORS.pop(self.prim_path)

# Remove all modalities
for modality in tuple(self.modalities):
self.remove_modality(modality)

# Destroy the render product
self._render_product.destroy()

# Remove the viewport if it's not the main viewport
if self._viewport.name != "Viewport":
self._viewport.destroy()
else:
# We're deleting our camera, so set the normal viewport camera to the default /Perspective camera
self.active_camera_path = "/OmniverseKit_Persp"

# Run super
super().remove()
Expand Down Expand Up @@ -882,10 +894,9 @@ def clear(cls):
"""
Clear all the class-wide variables.
"""
for sensor in cls.SENSORS.values():
# Destroy any sensor that is not attached to the main viewport window
if sensor._viewport.name != "Viewport":
sensor._viewport.destroy()
# Remove all sensors
for sensor in tuple(cls.SENSORS.values()):
sensor.remove()

# Render to update
render()
Expand Down

0 comments on commit 6275ab9

Please sign in to comment.