mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 18:28:10 +00:00
LibGUI: Turn GUI::Application::the() into a pointer
During app teardown, the Application object may be destroyed before something else, and so having Application::the() return a reference was obscuring the truth about its lifetime. This patch makes the API more honest by returning a pointer. While this makes call sites look a bit more sketchy, do note that the global Application pointer only becomes null during app teardown.
This commit is contained in:
parent
f7577585a6
commit
ca93c22ae2
26 changed files with 51 additions and 49 deletions
|
@ -39,18 +39,17 @@
|
|||
|
||||
namespace GUI {
|
||||
|
||||
static Application* s_the;
|
||||
static WeakPtr<Application> s_the;
|
||||
|
||||
Application& Application::the()
|
||||
Application* Application::the()
|
||||
{
|
||||
ASSERT(s_the);
|
||||
return *s_the;
|
||||
return s_the;
|
||||
}
|
||||
|
||||
Application::Application(int argc, char** argv)
|
||||
{
|
||||
ASSERT(!s_the);
|
||||
s_the = this;
|
||||
s_the = make_weak_ptr();
|
||||
m_event_loop = make<Core::EventLoop>();
|
||||
WindowServerConnection::the();
|
||||
Clipboard::initialize({});
|
||||
|
@ -68,7 +67,7 @@ Application::Application(int argc, char** argv)
|
|||
|
||||
Application::~Application()
|
||||
{
|
||||
s_the = nullptr;
|
||||
revoke_weak_ptrs();
|
||||
}
|
||||
|
||||
int Application::exec()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue