From 16f2276fe2252183e7306a530d5397ae8b76b878 Mon Sep 17 00:00:00 2001 From: Matija Kecman Date: Fri, 3 Jul 2026 16:01:44 -0700 Subject: [PATCH] Increase priority of ViewerApp ModelEvent handler PiperOrigin-RevId: 942274710 Change-Id: Ib894420e2d8f1e57a1da2d953c944316a1ff42ae --- python/mujoco/experimental/studio/viewer_app.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/python/mujoco/experimental/studio/viewer_app.py b/python/mujoco/experimental/studio/viewer_app.py index 0dbd7f5b..63afdbf7 100644 --- a/python/mujoco/experimental/studio/viewer_app.py +++ b/python/mujoco/experimental/studio/viewer_app.py @@ -30,6 +30,7 @@ import numpy as np from mujoco.experimental.dear_imgui import dear_imgui as imgui + @dataclasses.dataclass(frozen=True) class ViewerAppInitEvent(messages.Event): """Lifecycle event dispatched once when the ViewerApp is initialised. @@ -418,12 +419,14 @@ class ViewerApp: imgui.End() imgui.PopStyleVar(3) - @messages.handler(priority=messages.Priority.INTERNAL) + # CRITICAL priority ensures the model is copied before any other handlers + # are notified of the ModelEvent. + @messages.handler(priority=messages.Priority.CRITICAL) def _on_model(self, event: messages.ModelEvent) -> bool: self.model = copy.deepcopy(event.model) self.data = mujoco.MjData(self.model) assert id(self.model) != id(event.model) - return True + return False # Do not consume to allow other handlers to recieve the event. @messages.handler(priority=messages.Priority.INTERNAL) def _on_exit(self, _: messages.ExitEvent) -> bool: