Skip to content

Commit

Permalink
Fix 3D gui container edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed Jun 1, 2024
1 parent fc94f00 commit 87746f0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies = [
[project.optional-dependencies]
dev = [
"pyright>=1.1.308",
"ruff==0.4.6",
"ruff==0.4.7",
"pre-commit==3.3.2",
]
examples = [
Expand Down
9 changes: 4 additions & 5 deletions src/viser/_scene_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,17 +1272,16 @@ def add_3d_gui_container(
"""

# Avoids circular import.
from ._gui_api import GuiApi, _make_unique_id
from ._gui_api import _make_unique_id

# New name to make the type checker happy; ViserServer and ClientHandle inherit
# from both GuiApi and MessageApi. The pattern below is unideal.
gui_api = self
assert isinstance(gui_api, GuiApi)
gui_api = self._owner.gui

# Remove the 3D GUI container if it already exists. This will make sure
# contained GUI elements are removed, preventing potential memory leaks.
if name in gui_api._handle_from_node_name:
gui_api._handle_from_node_name[name].remove()
if name in self._handle_from_node_name:
self._handle_from_node_name[name].remove()

container_id = _make_unique_id()
self._websock_interface.queue_message(
Expand Down
4 changes: 2 additions & 2 deletions src/viser/_scene_handles.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,6 @@ def remove(self) -> None:
super().remove()

# Clean up contained GUI elements.
self._gui_api._container_handle_from_id.pop(self._container_id)
for child in self._children.values():
for child in tuple(self._children.values()):
child.remove()
self._gui_api._container_handle_from_id.pop(self._container_id)

0 comments on commit 87746f0

Please sign in to comment.