From c1f8cbb9d5c1179560efa67ac80f3060c3f75d7e Mon Sep 17 00:00:00 2001 From: Lordmau5 Date: Tue, 17 Feb 2026 12:38:38 +0100 Subject: [PATCH] frontend: Fix unclean shutdown on Windows This issue was brought back by a somewhat recent change to fix slow shutdown times in Linux. To paraphrase tfo from the OBS Discord: "I think the issue is that all the tray actions are parented to trayIcon, so when it's deleted, Qt auto deletes them as children, then delete trayMenu on the next line accesses those dead actions." We now create the tray menu first, then setting the parent of the actions (show / hide, stop / start streaming, etc.) to the tray menu. --- frontend/widgets/OBSBasic_SysTray.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/frontend/widgets/OBSBasic_SysTray.cpp b/frontend/widgets/OBSBasic_SysTray.cpp index e1d81501f..612550b2c 100644 --- a/frontend/widgets/OBSBasic_SysTray.cpp +++ b/frontend/widgets/OBSBasic_SysTray.cpp @@ -32,22 +32,20 @@ void OBSBasic::SystemTrayInit() trayIcon = new QSystemTrayIcon(QIcon::fromTheme("obs-tray", trayIconFile), this); trayIcon->setToolTip("OBS Studio"); - showHide = new QAction(QTStr("Basic.SystemTray.Show"), trayIcon.data()); - sysTrayStream = - new QAction(StreamingActive() ? QTStr("Basic.Main.StopStreaming") : QTStr("Basic.Main.StartStreaming"), - trayIcon.data()); - sysTrayRecord = - new QAction(RecordingActive() ? QTStr("Basic.Main.StopRecording") : QTStr("Basic.Main.StartRecording"), - trayIcon.data()); + trayMenu = new QMenu; + + showHide = new QAction(QTStr("Basic.SystemTray.Show"), trayMenu); + sysTrayStream = new QAction( + StreamingActive() ? QTStr("Basic.Main.StopStreaming") : QTStr("Basic.Main.StartStreaming"), trayMenu); + sysTrayRecord = new QAction( + RecordingActive() ? QTStr("Basic.Main.StopRecording") : QTStr("Basic.Main.StartRecording"), trayMenu); sysTrayReplayBuffer = new QAction(ReplayBufferActive() ? QTStr("Basic.Main.StopReplayBuffer") : QTStr("Basic.Main.StartReplayBuffer"), - trayIcon.data()); + trayMenu); sysTrayVirtualCam = new QAction(VirtualCamActive() ? QTStr("Basic.Main.StopVirtualCam") : QTStr("Basic.Main.StartVirtualCam"), - trayIcon.data()); - exit = new QAction(QTStr("Exit"), trayIcon.data()); - - trayMenu = new QMenu; + trayMenu); + exit = new QAction(QTStr("Exit"), trayMenu); previewProjector = new QMenu(QTStr("Projector.Open.Preview")); studioProgramProjector = new QMenu(QTStr("Projector.Open.Program"));