From b3f253df61d934776ddba026770aa9a61ad9fcaf Mon Sep 17 00:00:00 2001 From: Take Weiland Date: Fri, 23 Apr 2021 07:45:38 +0200 Subject: [PATCH] Fix ClientVisualization crashing on systems without monitors (#7719) --- .../loading/progress/ClientVisualization.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/fmllauncher/java/net/minecraftforge/fml/loading/progress/ClientVisualization.java b/src/fmllauncher/java/net/minecraftforge/fml/loading/progress/ClientVisualization.java index b714faf003..6909767eec 100644 --- a/src/fmllauncher/java/net/minecraftforge/fml/loading/progress/ClientVisualization.java +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/progress/ClientVisualization.java @@ -111,14 +111,20 @@ class ClientVisualization implements EarlyProgressVisualization.Visualization { IntBuffer monPosLeft = stack.mallocInt(1); IntBuffer monPosTop = stack.mallocInt(1); glfwGetWindowSize(window, pWidth, pHeight); - GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); - glfwGetMonitorPos(glfwGetPrimaryMonitor(), monPosLeft, monPosTop); - // Center the window - glfwSetWindowPos( - window, - (vidmode.width() - pWidth.get(0)) / 2 + monPosLeft.get(0), - (vidmode.height() - pHeight.get(0)) / 2 + monPosTop.get(0) - ); + + // try to center the window, this is a best-effort as there may not be + // a primary monitor and we might not even be on the primary monitor... + long primaryMonitor = glfwGetPrimaryMonitor(); + if (primaryMonitor != NULL) + { + GLFWVidMode vidmode = glfwGetVideoMode(primaryMonitor); + glfwGetMonitorPos(primaryMonitor, monPosLeft, monPosTop); + glfwSetWindowPos( + window, + (vidmode.width() - pWidth.get(0)) / 2 + monPosLeft.get(0), + (vidmode.height() - pHeight.get(0)) / 2 + monPosTop.get(0) + ); + } IntBuffer iconWidth = stack.mallocInt(1); IntBuffer iconHeight = stack.mallocInt(1); IntBuffer iconChannels = stack.mallocInt(1);