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.
This commit is contained in:
jp9000 2016-10-19 06:44:02 -07:00
parent dadefceccf
commit 9081df9708
2 changed files with 15 additions and 11 deletions

View file

@ -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)

View file

@ -151,13 +151,13 @@ private:
QPointer<QMenu> startStreamMenu;
QSystemTrayIcon *trayIcon;
QMenu *trayMenu;
QAction *sysTrayStream;
QAction *sysTrayRecord;
QAction *showHide;
QAction *showPreview;
QAction *exit;
QPointer<QSystemTrayIcon> trayIcon;
QPointer<QAction> sysTrayStream;
QPointer<QAction> sysTrayRecord;
QPointer<QAction> showHide;
QPointer<QAction> showPreview;
QPointer<QAction> exit;
QPointer<QMenu> trayMenu;
bool disableHiding = false;
void DrawBackdrop(float cx, float cy);