From 87e5369aedfaa49b6d388be51bb8287871a28c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 3 May 2016 09:48:57 +0200 Subject: [PATCH] Add nullptr checks to SurfaceTreeModel We called into waylandServer() without checking and on Neon the connects with a null surface crashed. --- debug_console.cpp | 60 +++++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/debug_console.cpp b/debug_console.cpp index e49c8a2d17..3593effd09 100644 --- a/debug_console.cpp +++ b/debug_console.cpp @@ -809,33 +809,48 @@ SurfaceTreeModel::SurfaceTreeModel(QObject *parent) const auto unmangeds = workspace()->unmanagedList(); for (auto u : unmangeds) { + if (!u->surface()) { + continue; + } connect(u->surface(), &SurfaceInterface::subSurfaceTreeChanged, this, reset); } for (auto c : workspace()->allClientList()) { + if (!c->surface()) { + continue; + } connect(c->surface(), &SurfaceInterface::subSurfaceTreeChanged, this, reset); } for (auto c : workspace()->desktopList()) { - connect(c->surface(), &SurfaceInterface::subSurfaceTreeChanged, this, reset); - } - for (auto c : waylandServer()->internalClients()) { - connect(c->surface(), &SurfaceInterface::subSurfaceTreeChanged, this, reset); - } - connect(waylandServer(), &WaylandServer::shellClientAdded, this, - [this, reset] (ShellClient *c) { - connect(c->surface(), &SurfaceInterface::subSurfaceTreeChanged, this, reset); - reset(); + if (!c->surface()) { + continue; } - ); + connect(c->surface(), &SurfaceInterface::subSurfaceTreeChanged, this, reset); + } + if (waylandServer()) { + for (auto c : waylandServer()->internalClients()) { + connect(c->surface(), &SurfaceInterface::subSurfaceTreeChanged, this, reset); + } + connect(waylandServer(), &WaylandServer::shellClientAdded, this, + [this, reset] (ShellClient *c) { + connect(c->surface(), &SurfaceInterface::subSurfaceTreeChanged, this, reset); + reset(); + } + ); + } connect(workspace(), &Workspace::clientAdded, this, [this, reset] (AbstractClient *c) { - connect(c->surface(), &SurfaceInterface::subSurfaceTreeChanged, this, reset); + if (c->surface()) { + connect(c->surface(), &SurfaceInterface::subSurfaceTreeChanged, this, reset); + } reset(); } ); connect(workspace(), &Workspace::clientRemoved, this, reset); connect(workspace(), &Workspace::unmanagedAdded, this, [this, reset] (Unmanaged *u) { - connect(u->surface(), &SurfaceInterface::subSurfaceTreeChanged, this, reset); + if (u->surface()) { + connect(u->surface(), &SurfaceInterface::subSurfaceTreeChanged, this, reset); + } reset(); } ); @@ -860,11 +875,12 @@ int SurfaceTreeModel::rowCount(const QModelIndex &parent) const } return 0; } + const int internalClientsCount = waylandServer() ? waylandServer()->internalClients().count() : 0; // toplevel are all windows return workspace()->allClientList().count() + workspace()->desktopList().count() + workspace()->unmanagedList().count() + - waylandServer()->internalClients().count(); + internalClientsCount; } QModelIndex SurfaceTreeModel::index(int row, int column, const QModelIndex &parent) const @@ -901,9 +917,11 @@ QModelIndex SurfaceTreeModel::index(int row, int column, const QModelIndex &pare return createIndex(row, column, unmanaged.at(row-reference)->surface()); } reference += unmanaged.count(); - const auto &internal = waylandServer()->internalClients(); - if (row < reference + internal.count()) { - return createIndex(row, column, internal.at(row-reference)->surface()); + if (waylandServer()) { + const auto &internal = waylandServer()->internalClients(); + if (row < reference + internal.count()) { + return createIndex(row, column, internal.at(row-reference)->surface()); + } } // not found return QModelIndex(); @@ -961,10 +979,12 @@ QModelIndex SurfaceTreeModel::parent(const QModelIndex &child) const } } row += unmanaged.count(); - const auto &internal = waylandServer()->internalClients(); - for (int i = 0; i < internal.count(); i++) { - if (internal.at(i)->surface() == parent) { - return createIndex(row + i, 0, parent); + if (waylandServer()) { + const auto &internal = waylandServer()->internalClients(); + for (int i = 0; i < internal.count(); i++) { + if (internal.at(i)->surface() == parent) { + return createIndex(row + i, 0, parent); + } } } }