Forráskód Böngészése

Improved SDL input focus check.

Lasse Öörni 13 éve
szülő
commit
c1ef7e84d8
1 módosított fájl, 8 hozzáadás és 11 törlés
  1. 8 11
      Engine/Input/Input.cpp

+ 8 - 11
Engine/Input/Input.cpp

@@ -133,22 +133,19 @@ void Input::Update()
         }
         }
     }
     }
     
     
-    // Poll SDL window activation state
+    // Check for activation and inactivation from SDL window flags. Must nullcheck the window pointer because it may have
+    // been closed due to input events
     SDL_Window* window = graphics_->GetImpl()->GetWindow();
     SDL_Window* window = graphics_->GetImpl()->GetWindow();
-    if (!window)
-        return;
-    
-    unsigned flags = SDL_GetWindowFlags(window);
-    if ((flags & (SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS)) == (SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS))
+    if (window)
     {
     {
-        if (!active_)
+        unsigned flags = SDL_GetWindowFlags(window) & (SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS);
+        if (!active_ && flags == (SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS))
             activated_ = true;
             activated_ = true;
-    }
-    else
-    {
-        if (active_)
+        else if (active_ && (flags & SDL_WINDOW_INPUT_FOCUS) == 0)
             MakeInactive();
             MakeInactive();
     }
     }
+    else
+        return;
     
     
     // Activate input now if necessary
     // Activate input now if necessary
     if (activated_)
     if (activated_)