diff --git a/src/vkcv/Window.cpp b/src/vkcv/Window.cpp
index b25ee61b10a8aa68cdd8f7e359cb4f854fed8d2c..d2ba366c95d99549a49ff2294da04985094c05c0 100644
--- a/src/vkcv/Window.cpp
+++ b/src/vkcv/Window.cpp
@@ -149,6 +149,7 @@ namespace vkcv {
                                              s_Windows.end(),
                                              [](GLFWwindow* window){return glfwGetWindowAttrib(window, GLFW_FOCUSED);})
                                 - s_Windows.begin();
+        activeWindowIndex *= (activeWindowIndex < s_Windows.size());    // fixes index getting out of bounds (e.g. if there is no focused window)
         auto window = static_cast<Window *>(glfwGetWindowUserPointer(s_Windows[activeWindowIndex]));
 
         if (window != nullptr && glfwJoystickPresent(gamepadIndex)) {