From 9081df9708b392be3a5bff531836a4e9ea6f159d Mon Sep 17 00:00:00 2001 From: jp9000 Date: Wed, 19 Oct 2016 06:44:02 -0700 Subject: [PATCH] UI: Fix poor handling of system tray pointers The original pull request that added the system tray feature was riddled with bad pointer usage. Bare pointers that are never properly freed, never contained within a QPointer or unique_ptr. These have now been changed to use QPointer variables, and to always check when the variables are valid before using. The order of destruction for QMenu that uses the actions has now been prioritized first before the actions. --- UI/window-basic-main.cpp | 12 ++++++++---- UI/window-basic-main.hpp | 14 +++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index 4f5ce134a..0c8b3bf37 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -3652,7 +3652,8 @@ inline void OBSBasic::OnActivate() App()->IncrementSleepInhibition(); UpdateProcessPriority(); - trayIcon->setIcon(QIcon(":/res/images/tray_active.png")); + if (trayIcon) + trayIcon->setIcon(QIcon(":/res/images/tray_active.png")); } } @@ -3663,7 +3664,8 @@ inline void OBSBasic::OnDeactivate() App()->DecrementSleepInhibition(); ClearProcessPriority(); - trayIcon->setIcon(QIcon(":/res/images/obs.png")); + if (trayIcon) + trayIcon->setIcon(QIcon(":/res/images/obs.png")); } } @@ -4557,7 +4559,8 @@ void OBSBasic::SetShowing(bool showing) "BasicWindow", "geometry", saveGeometry().toBase64().constData()); - showHide->setText(QTStr("Basic.SystemTray.Show")); + if (showHide) + showHide->setText(QTStr("Basic.SystemTray.Show")); QTimer::singleShot(250, this, SLOT(hide())); if (previewEnabled) @@ -4566,7 +4569,8 @@ void OBSBasic::SetShowing(bool showing) setVisible(false); } else if (showing && !isVisible()) { - showHide->setText(QTStr("Basic.SystemTray.Hide")); + if (showHide) + showHide->setText(QTStr("Basic.SystemTray.Hide")); QTimer::singleShot(250, this, SLOT(show())); if (previewEnabled) diff --git a/UI/window-basic-main.hpp b/UI/window-basic-main.hpp index d52a8c7c9..1dd0cc5fb 100644 --- a/UI/window-basic-main.hpp +++ b/UI/window-basic-main.hpp @@ -151,13 +151,13 @@ private: QPointer startStreamMenu; - QSystemTrayIcon *trayIcon; - QMenu *trayMenu; - QAction *sysTrayStream; - QAction *sysTrayRecord; - QAction *showHide; - QAction *showPreview; - QAction *exit; + QPointer trayIcon; + QPointer sysTrayStream; + QPointer sysTrayRecord; + QPointer showHide; + QPointer showPreview; + QPointer exit; + QPointer trayMenu; bool disableHiding = false; void DrawBackdrop(float cx, float cy);