From 31da9a487874445dcad60204aba50afabbcec51f Mon Sep 17 00:00:00 2001 From: cpw Date: Sat, 23 Nov 2019 15:37:56 -0500 Subject: [PATCH] Fix the hang on startup problem when windows' broken device enumeration causes a huge glfwInit slowdown. Log a message too when this is detected. See https://github.com/glfw/glfw/issues/1284, https://stackoverflow.com/questions/10967795/directinput8-enumdevices-sometimes-painfully-slow, https://discourse.libsdl.org/t/win-10-initing-joystick-causes-45s-hang-in-sdl-dinput-joystickdetect/23293 Signed-off-by: cpw --- .../fml/loading/progress/ClientVisualization.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 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 ca341c2bb7..a1c53cc7a8 100644 --- a/src/fmllauncher/java/net/minecraftforge/fml/loading/progress/ClientVisualization.java +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/progress/ClientVisualization.java @@ -20,6 +20,7 @@ package net.minecraftforge.fml.loading.progress; import org.apache.commons.lang3.tuple.Pair; +import org.apache.logging.log4j.LogManager; import org.lwjgl.glfw.GLFWErrorCallback; import org.lwjgl.glfw.GLFWVidMode; import org.lwjgl.opengl.GL; @@ -52,9 +53,15 @@ class ClientVisualization implements EarlyProgressVisualization.Visualization { private void initWindow() { GLFWErrorCallback.createPrint(System.err).set(); + long glfwInitBegin = System.nanoTime(); if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } + long glfwInitEnd = System.nanoTime(); + + if (glfwInitEnd - glfwInitBegin > 1e9) { + LogManager.getLogger().fatal("WARNING : glfwInit took {} seconds to start.", (glfwInitEnd-glfwInitBegin) / 1.0e9); + } glfwDefaultWindowHints(); glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); @@ -237,8 +244,8 @@ class ClientVisualization implements EarlyProgressVisualization.Visualization { } private void run() { - initWindow(); running = true; + initWindow(); while (running) { renderProgress(); try { @@ -251,10 +258,6 @@ class ClientVisualization implements EarlyProgressVisualization.Visualization { @Override public void join() { -// try { -// Thread.sleep(10000); -// } catch (InterruptedException e) { -// } running = false; try { thread.join();