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 <cpw+github@weeksfamily.ca>
This commit is contained in:
cpw 2019-11-23 15:37:56 -05:00
parent 0e65f20f22
commit 31da9a4878
No known key found for this signature in database
GPG Key ID: 8EB3DF749553B1B7
1 changed files with 8 additions and 5 deletions

View File

@ -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();