Browse Source

Fix exit from UI crash, store root widget properly if no parent

Josh Engebretson 10 years ago
parent
commit
f1836c6dda

+ 1 - 1
Script/AtomicEditor/ui/frames/menus/MainFrameMenu.ts

@@ -40,7 +40,7 @@ class MainFrameMenu extends Atomic.ScriptObject {
 
             if (refid == "quit") {
 
-                this.sendEvent(EditorEvents.Quit);
+                Atomic.ui.requestExit();
                 return true;
 
             }

+ 1 - 1
Script/AtomicEditor/ui/modal/license/ProWindow.ts

@@ -30,7 +30,7 @@ class ProWindow extends ModalWindow {
 
             } else if (id == "quit") {
 
-                this.sendEvent(EditorEvents.Quit);
+                Atomic.ui.requestExit();
 
             }
 

+ 7 - 1
Source/Atomic/UI/UI.cpp

@@ -88,7 +88,8 @@ UI::UI(Context* context) :
     keyboardDisabled_(false),
     initialized_(false),
     skinLoaded_(false),
-    consoleVisible_(false)
+    consoleVisible_(false),
+    exitRequested_(false)
 {
 
 }
@@ -465,6 +466,11 @@ void UI::HandleScreenMode(StringHash eventType, VariantMap& eventData)
 
 void UI::HandleUpdate(StringHash eventType, VariantMap& eventData)
 {
+    if (exitRequested_) {
+        SendEvent(E_EXITREQUESTED);
+        exitRequested_ = false;
+        return;
+    }
     TBMessageHandler::ProcessMessages();
 }
 

+ 4 - 1
Source/Atomic/UI/UI.h

@@ -71,6 +71,9 @@ public:
     void ShowConsole(bool value);
     void ToggleConsole();
 
+    /// request exit on next frame
+    void RequestExit() { exitRequested_ = true; inputDisabled_ = true; }
+
     UIRenderer* GetRenderer() { return renderer_; }
 
 private:
@@ -106,6 +109,7 @@ private:
     bool initialized_;
     bool skinLoaded_;
     bool consoleVisible_;
+    bool exitRequested_;
 
     // Events
     void HandleScreenMode(StringHash eventType, VariantMap& eventData);
@@ -120,7 +124,6 @@ private:
     void HandleUpdate(StringHash eventType, VariantMap& eventData);
     void HandleConsoleClosed(StringHash eventType, VariantMap& eventData);
 
-
 };
 
 }

+ 1 - 1
Source/Atomic/UI/UIWidget.cpp

@@ -289,7 +289,7 @@ void UIWidget::Center()
     if (!root)
     {
         UI* ui = GetSubsystem<UI>();
-        ui->GetRootWidget();
+        root = ui->GetRootWidget();
     }
 
     TBRect bounds(0, 0, root->GetRect().w, root->GetRect().h);