From ba03ebdadd09bdcb231017c662c5b3990550de70 Mon Sep 17 00:00:00 2001 From: Saran Tunyasuvunakool Date: Wed, 11 Oct 2023 04:05:37 -0700 Subject: [PATCH] Fix a segfault in the passive viewer on macOS. The segfault is caused by a call to mjui_update outside of the macOS main thread, introduced in 3e12f0d50c15c5d6fb3da45a1db1c29bfcfd77b0. PiperOrigin-RevId: 572531447 Change-Id: Ib8424c746d18a776c0b91087d9501aa8ee463026 --- simulate/simulate.cc | 9 ++++++++- simulate/simulate.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/simulate/simulate.cc b/simulate/simulate.cc index 2a4d98d5..9713cf1d 100644 --- a/simulate/simulate.cc +++ b/simulate/simulate.cc @@ -1885,7 +1885,7 @@ void Simulate::Sync() { update_profiler = true; update_sensor = true; scrub_index = 0; - mjui0_update_section(this, SECT_SIMULATION); + pending_.ui_update_simulation = true; pending_.reset = false; } @@ -2326,6 +2326,13 @@ void Simulate::Render() { } // update UI sections from last sync + if (pending_.ui_update_simulation) { + if (this->ui0_enable && this->ui0.sect[SECT_SIMULATION].state) { + mjui0_update_section(this, SECT_SIMULATION); + } + pending_.ui_update_simulation = false; + } + if (this->ui0_enable && this->ui0.sect[SECT_WATCH].state) { mjui0_update_section(this, SECT_WATCH); } diff --git a/simulate/simulate.h b/simulate/simulate.h index d50a6677..a21e8e0b 100644 --- a/simulate/simulate.h +++ b/simulate/simulate.h @@ -148,6 +148,7 @@ class Simulate { int newperturb; bool select; mjuiState select_state; + bool ui_update_simulation; bool ui_update_physics; bool ui_update_rendering; bool ui_update_joint;