From ebd11b2d8463fddc190766c269bc31acf3414ffd Mon Sep 17 00:00:00 2001 From: Mr-Wiseguy Date: Wed, 23 Apr 2025 23:31:10 -0400 Subject: [PATCH] Close context when showing or hiding a context and reopen afterwards to prevent deadlocks --- src/ui/ui_state.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/ui/ui_state.cpp b/src/ui/ui_state.cpp index f981420..0a27460 100644 --- a/src/ui/ui_state.cpp +++ b/src/ui/ui_state.cpp @@ -796,16 +796,28 @@ void recompui::message_box(const char* msg) { } void recompui::show_context(ContextId context, std::string_view param) { - std::lock_guard lock{ui_state_mutex}; + ContextId prev_context = recompui::try_close_current_context(); + { + std::lock_guard lock{ ui_state_mutex }; - // TODO call the context's on_show callback with the param. - ui_state->show_context(context); + // TODO call the context's on_show callback with the param. + ui_state->show_context(context); + } + if (prev_context != ContextId::null()) { + prev_context.open(); + } } void recompui::hide_context(ContextId context) { - std::lock_guard lock{ui_state_mutex}; + ContextId prev_context = recompui::try_close_current_context(); + { + std::lock_guard lock{ ui_state_mutex }; - ui_state->hide_context(context); + ui_state->hide_context(context); + } + if (prev_context != ContextId::null()) { + prev_context.open(); + } } void recompui::hide_all_contexts() {