diff --git a/src/ncurses_def.cpp b/src/ncurses_def.cpp index 415693fa9b715..45d6abbeeebb8 100644 --- a/src/ncurses_def.cpp +++ b/src/ncurses_def.cpp @@ -210,6 +210,7 @@ void catacurses::erase() void catacurses::endwin() { + ui_manager::reset(); return curses_check_result( ::endwin(), OK, "endwin" ); } diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index ba782827c9ed9..34cc14549eace 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -3771,6 +3771,7 @@ void catacurses::endwin() font.reset(); map_font.reset(); overmap_font.reset(); + ui_manager::reset(); WinDestroy(); } diff --git a/src/ui_manager.cpp b/src/ui_manager.cpp index 7ee3747691435..44ef80b42315f 100644 --- a/src/ui_manager.cpp +++ b/src/ui_manager.cpp @@ -75,6 +75,9 @@ ui_adaptor::ui_adaptor( ui_adaptor::debug_message_ui ) : is_imgui( false ), ui_adaptor::~ui_adaptor() { + if( is_shutting_down ) { + return; + } if( is_debug_message_ui ) { cata_assert( showing_debug_message ); showing_debug_message = false; @@ -306,6 +309,11 @@ void ui_adaptor::reset() position( point_zero, point_zero ); } +void ui_adaptor::shutdown() +{ + is_shutting_down = true; +} + void ui_adaptor::invalidate( const rectangle &rect, const bool reenable_uis_below ) { if( rect.p_min.x >= rect.p_max.x || rect.p_min.y >= rect.p_max.y ) { @@ -523,4 +531,11 @@ void invalidate_all_ui_adaptors() adaptor.invalidate_ui(); } } + +void reset() +{ + for( ui_adaptor &adaptor : ui_stack ) { + adaptor.shutdown(); + } +} } // namespace ui_manager diff --git a/src/ui_manager.h b/src/ui_manager.h index 1c117fe937bca..6f732905dabe2 100644 --- a/src/ui_manager.h +++ b/src/ui_manager.h @@ -222,6 +222,8 @@ class ui_adaptor **/ void reset(); + void shutdown(); + /* See the `ui_manager` namespace */ static void invalidate( const rectangle &rect, bool reenable_uis_below ); static bool has_imgui(); @@ -248,6 +250,7 @@ class ui_adaptor bool disabling_uis_below; bool is_debug_message_ui; + bool is_shutting_down = false; mutable bool invalidated; mutable bool deferred_resize; @@ -292,6 +295,7 @@ void redraw_invalidated(); **/ void screen_resized(); void invalidate_all_ui_adaptors(); +void reset(); } // namespace ui_manager #endif // CATA_SRC_UI_MANAGER_H diff --git a/src/wincurse.cpp b/src/wincurse.cpp index 35722ee0cf33c..2d936deceee35 100644 --- a/src/wincurse.cpp +++ b/src/wincurse.cpp @@ -761,6 +761,7 @@ std::optional input_context::get_coordinates( const catacurses::window // Ends the terminal, destroy everything void catacurses::endwin() { + ui_manager::reset(); DeleteObject( font ); WinDestroy(); // Unload it