summaryrefslogtreecommitdiff
path: root/Libraries/LibGUI
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-08-22 13:08:39 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-22 13:10:14 +0200
commit683ae4f7ade18e4506d74b61b14e3fd95d672abb (patch)
tree70bf711f3173f85cea26937bed2c9b1be877861d /Libraries/LibGUI
parent0359a5ce2702da0d8fb38a32e44124a4b37cc22e (diff)
downloadserenity-683ae4f7ade18e4506d74b61b14e3fd95d672abb.zip
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.
Diffstat (limited to 'Libraries/LibGUI')
-rw-r--r--Libraries/LibGUI/Application.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/Libraries/LibGUI/Application.cpp b/Libraries/LibGUI/Application.cpp
index dd256ebdca..259f0ffe4d 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 <AK/NeverDestroyed.h>
#include <LibCore/EventLoop.h>
#include <LibGUI/Action.h>
#include <LibGUI/Application.h>
@@ -39,17 +40,17 @@
namespace GUI {
-static WeakPtr<Application> s_the;
+static NeverDestroyed<WeakPtr<Application>> 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<Core::EventLoop>();
WindowServerConnection::the();
Clipboard::initialize({});