Quellcode durchsuchen

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.
Richard Stanway vor 2 Jahren
Ursprung
Commit
d8bf21de2f
1 geänderte Dateien mit 7 neuen und 0 gelöschten Zeilen
  1. 7 0
      UI/window-basic-stats.cpp

+ 7 - 0
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);
 }