Skip to content

Commit 929421d

Browse files
committed
Fix Snap-to-EE segfault: dispatch to physics thread (#17)
The _on_snap callback ran on viser's websocket thread and called arm.get_ee_pose() which accesses MuJoCo data (mj_forward + site_xpos). Concurrent access from the wrong thread causes a segfault. Fix: dispatch the MuJoCo read through event_loop.run_on_physics_thread, same pattern as _activate_teleop. Viser GUI updates (gizmo position) are thread-safe and stay on the websocket thread. Fixes ada_mj#17
1 parent 9f70e39 commit 929421d

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/mj_viser/teleop_panel.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,13 @@ def _on_activate(event) -> None:
298298

299299
@self._snap_btn.on_click
300300
def _on_snap(event) -> None:
301-
ee_pose = self._arm.get_ee_pose()
301+
def _do_snap():
302+
return self._arm.get_ee_pose()
303+
304+
if self._event_loop is not None:
305+
ee_pose = self._event_loop.run_on_physics_thread(_do_snap)
306+
else:
307+
ee_pose = _do_snap()
302308
self._gizmo.wxyz = xmat_to_wxyz(ee_pose[:3, :3].flatten())
303309
self._gizmo.position = tuple(ee_pose[:3, 3])
304310

0 commit comments

Comments
 (0)