From d8bf21de2f7d3831bde787d7396d9a8e8391a06f Mon Sep 17 00:00:00 2001 From: Richard Stanway Date: Mon, 11 Sep 2023 17:26:09 +0200 Subject: [PATCH] UI: Add cleanup of stats callback on window close Moving the cleanup to OBS_FRONTEND_EVENT_EXIT in #8735 only handled the cleanup from the dockable window, as the regular stats window is deleted on close when the UI is shut down. This caused an event handler leak each time the window is manually closed, resulting in crashes. This code looks a bit wrong since we delete the same handler in multiple places, but this is due to the code being used by both the dock (non-closable) and the window (closable). The OBS_FRONTEND_EVENT_EXIT handler handles cleanup from the dockable stats window, and the window close handler now handles cleanup from the non-dockable stats window. --- UI/window-basic-stats.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/UI/window-basic-stats.cpp b/UI/window-basic-stats.cpp index e4db84a00a22d4..0675dc10db427a 100644 --- a/UI/window-basic-stats.cpp +++ b/UI/window-basic-stats.cpp @@ -30,6 +30,9 @@ void OBSBasicStats::OBSFrontendEvent(enum obs_frontend_event event, void *ptr) stats->ResetRecTimeLeft(); break; case OBS_FRONTEND_EVENT_EXIT: + // This is only reached when the non-closable (dock) stats + // window is being cleaned up. Thee closable stats window is + // already gone by this point as it's deleted on close. obs_frontend_remove_event_callback(OBSFrontendEvent, stats); break; default: @@ -231,6 +234,10 @@ void OBSBasicStats::closeEvent(QCloseEvent *event) config_save_safe(main->Config(), "tmp", nullptr); } + // This code is only reached when the non-dockable stats window is + // manually closed or OBS is exiting. + obs_frontend_remove_event_callback(OBSFrontendEvent, this); + QWidget::closeEvent(event); }