From 5fe653cf82b7e1ab775836479acd32df56d107b4 Mon Sep 17 00:00:00 2001 From: cpw Date: Sat, 16 May 2015 12:55:15 -0400 Subject: [PATCH] Attempt to fix the slow loading problem. Instead of forcing the main thread to wait around on every call to processWindowMessages, we will simply skip it, if the mutex is already claimed by the display thread. This should fix slow loading issues seen by some with the new loading screen. --- .../java/cpw/mods/fml/client/FMLClientHandler.java | 10 ++++++---- .../main/java/cpw/mods/fml/client/SplashProgress.java | 11 +++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/fml/src/main/java/cpw/mods/fml/client/FMLClientHandler.java b/fml/src/main/java/cpw/mods/fml/client/FMLClientHandler.java index 5a41a7245c..53b7f3cb8a 100644 --- a/fml/src/main/java/cpw/mods/fml/client/FMLClientHandler.java +++ b/fml/src/main/java/cpw/mods/fml/client/FMLClientHandler.java @@ -1003,9 +1003,11 @@ public class FMLClientHandler implements IFMLSidedHandler public void processWindowMessages() { // workaround for windows requiring messages being processed on the main thread - if(LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_WINDOWS) - { - Display.processMessages(); - } + if (LWJGLUtil.getPlatform() != LWJGLUtil.PLATFORM_WINDOWS) return; + // If we can't grab the mutex, the update call is blocked, probably in native code, just skip it and carry on + // We'll get another go next time + if (!SplashProgress.mutex.tryAcquire()) return; + Display.processMessages(); + SplashProgress.mutex.release(); } } diff --git a/fml/src/main/java/cpw/mods/fml/client/SplashProgress.java b/fml/src/main/java/cpw/mods/fml/client/SplashProgress.java index 62e672aed2..d52154d0f7 100644 --- a/fml/src/main/java/cpw/mods/fml/client/SplashProgress.java +++ b/fml/src/main/java/cpw/mods/fml/client/SplashProgress.java @@ -13,6 +13,7 @@ import java.lang.Thread.UncaughtExceptionHandler; import java.nio.IntBuffer; import java.util.Iterator; import java.util.Properties; +import java.util.concurrent.Semaphore; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; @@ -81,6 +82,7 @@ public class SplashProgress private static int barBorderColor; private static int barColor; private static int barBackgroundColor; + static final Semaphore mutex = new Semaphore(1); private static String getString(String name, String def) { @@ -297,7 +299,16 @@ public class SplashProgress glEnd(); glDisable(GL_TEXTURE_2D); + // We use mutex to indicate safely to the main thread that we're taking the display global lock + // So the main thread can skip processing messages while we're updating. + // There are system setups where this call can pause for a while, because the GL implementation + // is trying to impose a framerate or other thing is occurring. Without the mutex, the main + // thread would delay waiting for the same global display lock + mutex.acquireUninterruptibly(); Display.update(); + // As soon as we're done, we release the mutex. The other thread can now ping the processmessages + // call as often as it wants until we get get back here again + mutex.release(); if(pause) { clearGL();