From 27969b6752ad916cc48a71bc9a8db84f48e91318 Mon Sep 17 00:00:00 2001 From: Zach H Date: Tue, 15 Mar 2016 00:22:23 -0400 Subject: [PATCH] prevent null crash --- cockatrice/src/tab_message.cpp | 13 ++++++++++--- cockatrice/src/tab_room.cpp | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cockatrice/src/tab_message.cpp b/cockatrice/src/tab_message.cpp index c9f4e625..33711560 100644 --- a/cockatrice/src/tab_message.cpp +++ b/cockatrice/src/tab_message.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "tab_message.h" #include "abstractclient.h" #include "chatview.h" @@ -131,9 +132,15 @@ bool TabMessage::shouldShowSystemPopup(const Event_UserMessage &event) { } void TabMessage::showSystemPopup(const Event_UserMessage &event) { - disconnect(trayIcon, SIGNAL(messageClicked()), 0, 0); - trayIcon->showMessage(tr("Private message from ") + otherUserInfo->name().c_str(), event.message().c_str()); - connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked())); + if (trayIcon) { + disconnect(trayIcon, SIGNAL(messageClicked()), 0, 0); + trayIcon->showMessage(tr("Private message from ") + otherUserInfo->name().c_str(), event.message().c_str()); + connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked())); + } + else + { + qDebug() << "Error: trayIcon is NULL. TabMessage::showSystemPopup failed"; + } } void TabMessage::messageClicked() { diff --git a/cockatrice/src/tab_room.cpp b/cockatrice/src/tab_room.cpp index ba59a2aa..b455befd 100644 --- a/cockatrice/src/tab_room.cpp +++ b/cockatrice/src/tab_room.cpp @@ -160,8 +160,8 @@ void TabRoom::focusTab() { } void TabRoom::actShowMentionPopup(QString &sender) { - if (tabSupervisor->currentIndex() != tabSupervisor->indexOf(this) - || QApplication::activeWindow() == 0 || QApplication::focusWidget() == 0) { + if (trayIcon && (tabSupervisor->currentIndex() != tabSupervisor->indexOf(this) || QApplication::activeWindow() == 0 + || QApplication::focusWidget() == 0)) { disconnect(trayIcon, SIGNAL(messageClicked()), 0, 0); trayIcon->showMessage(sender + tr(" mentioned you."), tr("Click to view")); connect(trayIcon, SIGNAL(messageClicked()), chatView, SLOT(actMessageClicked()));