From 683ae4f7ade18e4506d74b61b14e3fd95d672abb Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 22 Aug 2020 13:08:39 +0200 Subject: [PATCH] LibGUI: Fix crash during HackStudio application teardown We can't rely on a plain global WeakPtr during application teardown since destruction order is not defined. Instead, use a NeverDestroyed to hold the GUI::Application weak pointer. This way it will always be reliable. Fixes #3251. --- Libraries/LibGUI/Application.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Libraries/LibGUI/Application.cpp b/Libraries/LibGUI/Application.cpp index dd256ebdca0..259f0ffe4d1 100644 --- a/Libraries/LibGUI/Application.cpp +++ b/Libraries/LibGUI/Application.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -39,17 +40,17 @@ namespace GUI { -static WeakPtr s_the; +static NeverDestroyed> s_the; Application* Application::the() { - return s_the; + return *s_the; } Application::Application(int argc, char** argv) { - ASSERT(!s_the); - s_the = make_weak_ptr(); + ASSERT(!*s_the); + *s_the = make_weak_ptr(); m_event_loop = make(); WindowServerConnection::the(); Clipboard::initialize({});