Kaynağa Gözat

LibGUI: Handle Window::hide() during Application teardown better

If a window is being torn down during app shutdown, the global
application pointer may be nulled out already. So let's handle that
case gracefully in Window::hide().
Andreas Kling 4 yıl önce
ebeveyn
işleme
d9c5fdf5d5
1 değiştirilmiş dosya ile 9 ekleme ve 7 silme
  1. 9 7
      Userland/Libraries/LibGUI/Window.cpp

+ 9 - 7
Userland/Libraries/LibGUI/Window.cpp

@@ -196,15 +196,17 @@ void Window::hide()
         }
     }
 
-    bool app_has_visible_windows = false;
-    for (auto& window : *all_windows) {
-        if (window->is_visible()) {
-            app_has_visible_windows = true;
-            break;
+    if (auto* app = Application::the()) {
+        bool app_has_visible_windows = false;
+        for (auto& window : *all_windows) {
+            if (window->is_visible()) {
+                app_has_visible_windows = true;
+                break;
+            }
         }
+        if (!app_has_visible_windows)
+            app->did_delete_last_window({});
     }
-    if (!app_has_visible_windows)
-        Application::the()->did_delete_last_window({});
 }
 
 void Window::set_title(const StringView& title)