From 702efda27b10d4cc84c8d572acc18e40136defb1 Mon Sep 17 00:00:00 2001
From: Vanessa Karolek <vaka1997@uni-koblenz.de>
Date: Tue, 22 Jun 2021 14:26:29 +0200
Subject: [PATCH] [#60][Fix] fix active window indexing

Per default, if all windows are out of focus, the first window is used as reference.
---
 src/vkcv/Window.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/vkcv/Window.cpp b/src/vkcv/Window.cpp
index b25ee61b..d2ba366c 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)) {
-- 
GitLab