Skip to content

Commit 16f2276

Browse files
okmatijacopybara-github
authored andcommitted
Increase priority of ViewerApp ModelEvent handler
PiperOrigin-RevId: 942274710 Change-Id: Ib894420e2d8f1e57a1da2d953c944316a1ff42ae
1 parent 7e9ac58 commit 16f2276

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

python/mujoco/experimental/studio/viewer_app.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
from mujoco.experimental.dear_imgui import dear_imgui as imgui
3232

33+
3334
@dataclasses.dataclass(frozen=True)
3435
class ViewerAppInitEvent(messages.Event):
3536
"""Lifecycle event dispatched once when the ViewerApp is initialised.
@@ -418,12 +419,14 @@ def build_gui(self) -> None:
418419
imgui.End()
419420
imgui.PopStyleVar(3)
420421

421-
@messages.handler(priority=messages.Priority.INTERNAL)
422+
# CRITICAL priority ensures the model is copied before any other handlers
423+
# are notified of the ModelEvent.
424+
@messages.handler(priority=messages.Priority.CRITICAL)
422425
def _on_model(self, event: messages.ModelEvent) -> bool:
423426
self.model = copy.deepcopy(event.model)
424427
self.data = mujoco.MjData(self.model)
425428
assert id(self.model) != id(event.model)
426-
return True
429+
return False # Do not consume to allow other handlers to recieve the event.
427430

428431
@messages.handler(priority=messages.Priority.INTERNAL)
429432
def _on_exit(self, _: messages.ExitEvent) -> bool:

0 commit comments

Comments
 (0)