From c2c92fab518bdd441af2ef8181111b7a49821a50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Fl=C3=B6ser?= Date: Sun, 6 Jan 2019 17:05:10 +0100 Subject: [PATCH] Ensure the Compositor does not start during termination Summary: The SceneOpenGLES test was starting to randomly crash on my system. On investigation I observed that there was a graphics reset ("Attempting to reset compositing.") which triggered a delayed restart of the compositor. This even was only processed while waiting for XWayland to terminate. Which resulted in a crash in KWin::getXServerVersion as the xcb connection broke. It makes no sense to setup the compositor again during application shutdown. Thus the dtors set a flag that they are terminating the application and Compositor::setup is checking for it. Test Plan: Test no longer crashes, although it goes through the crashing path Reviewers: #kwin Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D18015 --- autotests/integration/kwin_wayland_test.cpp | 1 + composite.cpp | 4 ++++ main.h | 9 +++++++++ main_wayland.cpp | 1 + main_x11.cpp | 1 + 5 files changed, 16 insertions(+) diff --git a/autotests/integration/kwin_wayland_test.cpp b/autotests/integration/kwin_wayland_test.cpp index d750a53af0..bd37b5a4f1 100644 --- a/autotests/integration/kwin_wayland_test.cpp +++ b/autotests/integration/kwin_wayland_test.cpp @@ -76,6 +76,7 @@ WaylandTestApplication::WaylandTestApplication(OperationMode mode, int &argc, ch WaylandTestApplication::~WaylandTestApplication() { + setTerminating(); kwinApp()->platform()->setOutputsEnabled(false); // need to unload all effects prior to destroying X connection as they might do X calls // also before destroy Workspace, as effects might call into Workspace diff --git a/composite.cpp b/composite.cpp index 16b3b6a644..a5341460b6 100644 --- a/composite.cpp +++ b/composite.cpp @@ -156,6 +156,10 @@ Compositor::~Compositor() void Compositor::setup() { + if (kwinApp()->isTerminating()) { + // don't setup while KWin is terminating. An event to restart might be lingering in the event queue due to graphics reset + return; + } if (hasScene()) return; if (m_suspended) { diff --git a/main.h b/main.h index 6bde7f2f22..166c35fe12 100644 --- a/main.h +++ b/main.h @@ -188,6 +188,10 @@ public: return m_platform; } + bool isTerminating() const { + return m_terminating; + } + static void setupMalloc(); static void setupLocalizedString(); @@ -231,6 +235,10 @@ protected: } void destroyAtoms(); + void setTerminating() { + m_terminating = true; + } + protected: QString m_originalSessionKey; static int crashes; @@ -252,6 +260,7 @@ private: bool m_useKActivities = true; #endif Platform *m_platform = nullptr; + bool m_terminating = false; }; inline static Application *kwinApp() diff --git a/main_wayland.cpp b/main_wayland.cpp index ce25dcc7fc..f2cd475179 100644 --- a/main_wayland.cpp +++ b/main_wayland.cpp @@ -129,6 +129,7 @@ ApplicationWayland::ApplicationWayland(int &argc, char **argv) ApplicationWayland::~ApplicationWayland() { + setTerminating(); if (!waylandServer()) { return; } diff --git a/main_x11.cpp b/main_x11.cpp index 765caefee8..e5e4d2b690 100644 --- a/main_x11.cpp +++ b/main_x11.cpp @@ -187,6 +187,7 @@ ApplicationX11::ApplicationX11(int &argc, char **argv) ApplicationX11::~ApplicationX11() { + setTerminating(); destroyCompositor(); destroyWorkspace(); if (!owner.isNull() && owner->ownerWindow() != XCB_WINDOW_NONE) // If there was no --replace (no new WM)