Fix GLProxy error in multiplayer

Make some GLProxy methods static to prevent setup order issues
This commit is contained in:
James Seibel
2025-12-17 09:02:07 -06:00
parent 90564f2537
commit eecb28d11f
8 changed files with 23 additions and 25 deletions
@@ -379,8 +379,11 @@ public class ClientApi
try
{
// make sure the GLProxy is created for future use
GLProxy.getInstance();
// these tasks always need to be called, regardless of whether the renderer is enabled or not to prevent memory leaks
GLProxy.getInstance().runRenderThreadTasks();
GLProxy.runRenderThreadTasks();
}
catch (Exception e)
{
@@ -90,7 +90,7 @@ public class ClientPluginChannelApi
LOGGER.info("Server level key received: [" + msg.levelKey + "].");
GLProxy.getInstance().queueRunningOnRenderThread(() ->
GLProxy.queueRunningOnRenderThread(() ->
{
IClientLevelWrapper clientLevel = MC.getWrappedClientLevel(true);
IServerKeyedClientLevel existingKeyedClientLevel = KEYED_CLIENT_LEVEL_MANAGER.getServerKeyedLevel();
@@ -107,7 +107,7 @@ public class LodBufferContainer implements AutoCloseable
// upload on MC's render thread
GLProxy.getInstance().queueRunningOnRenderThread(() ->
GLProxy.queueRunningOnRenderThread(() ->
{
try
{
@@ -295,7 +295,7 @@ public class LodBufferContainer implements AutoCloseable
{
this.buffersUploaded = false;
GLProxy.getInstance().queueRunningOnRenderThread(() ->
GLProxy.queueRunningOnRenderThread(() ->
{
for (GLVertexBuffer buffer : this.vbos)
{
@@ -56,13 +56,13 @@ public class GLProxy
public static final Set<String> LOGGED_GL_MESSAGES = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
private static final ConcurrentLinkedQueue<Runnable> RENDER_THREAD_RUNNABLE_QUEUE = new ConcurrentLinkedQueue<>();
private static GLProxy instance = null;
private final ConcurrentLinkedQueue<Runnable> renderThreadRunnableQueue = new ConcurrentLinkedQueue<>();
/** Minecraft's GL capabilities */
public final GLCapabilities glCapabilities;
@@ -231,7 +231,7 @@ public class GLProxy
return uploadOverride;
}
public boolean runningOnRenderThread()
public static boolean runningOnRenderThread()
{
long currentContext = GLFW.glfwGetCurrentContext();
return currentContext != 0L; // if the context isn't null, it's the MC context
@@ -243,12 +243,12 @@ public class GLProxy
// Worker Thread Runnables //
//=========================//
public void queueRunningOnRenderThread(Runnable renderCall)
public static void queueRunningOnRenderThread(Runnable renderCall)
{
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
this.renderThreadRunnableQueue.add(() -> this.runOpenGlCall(renderCall, stackTrace));
RENDER_THREAD_RUNNABLE_QUEUE.add(() -> runOpenGlCall(renderCall, stackTrace));
}
private void runOpenGlCall(Runnable renderCall, StackTraceElement[] stackTrace)
private static void runOpenGlCall(Runnable renderCall, StackTraceElement[] stackTrace)
{
try
{
@@ -266,11 +266,11 @@ public class GLProxy
* Doesn't do any thread/GL Context validation.
* Running this outside of the render thread may cause crashes or other issues.
*/
public void runRenderThreadTasks()
public static void runRenderThreadTasks()
{
long startTime = System.nanoTime();
Runnable runnable = this.renderThreadRunnableQueue.poll();
Runnable runnable = RENDER_THREAD_RUNNABLE_QUEUE.poll();
while(runnable != null)
{
runnable.run();
@@ -283,7 +283,7 @@ public class GLProxy
break;
}
runnable = this.renderThreadRunnableQueue.poll();
runnable = RENDER_THREAD_RUNNABLE_QUEUE.poll();
}
}
@@ -100,7 +100,7 @@ public class GLBuffer implements AutoCloseable
protected void create(boolean asBufferStorage)
{
if (!GLProxy.getInstance().runningOnRenderThread())
if (!GLProxy.runningOnRenderThread())
{
LodUtil.assertNotReach("Thread ["+Thread.currentThread()+"] tried to create a GLBuffer outside the MC render thread.");
}
@@ -151,7 +151,7 @@ public class GLBuffer implements AutoCloseable
BUFFER_ID_TO_PHANTOM.remove(id);
}
GLProxy.getInstance().queueRunningOnRenderThread(() ->
GLProxy.queueRunningOnRenderThread(() ->
{
// destroy the buffer if it exists,
// the buffer may not exist if the destroy method is called twice
@@ -44,7 +44,7 @@ public class QuadElementBuffer extends GLElementBuffer
public int getCapacity()
{
return super.getSize() / GLEnums.getTypeSize(getType());
return super.getSize() / GLEnums.getTypeSize(this.getType());
}
private static void buildBufferByte(int quadCount, ByteBuffer buffer)
@@ -140,7 +140,6 @@ public class QuadElementBuffer extends GLElementBuffer
return;
}
int vertexCount = quadCount * 4; // 4 vertices per quad
GLProxy gl = GLProxy.getInstance();
if (vertexCount < 255)
{ // Reserve 1 for the reset index
@@ -158,7 +157,7 @@ public class QuadElementBuffer extends GLElementBuffer
ByteBuffer buffer = MemoryUtil.memAlloc(this.indicesCount * GLEnums.getTypeSize(this.type));
buildBuffer(quadCount, buffer, this.type);
if (!gl.bufferStorageSupported)
if (!GLProxy.getInstance().bufferStorageSupported)
{
this.bind();
@@ -493,12 +493,8 @@ public class LodRenderer
return false;
}
if (!GLProxy.hasInstance())
{
// shouldn't normally happen, but just in case
LOGGER.warn("Renderer setup called but GLProxy has not yet been setup!");
return false;
}
// GLProxy should have already been created by this point, but just in case create it now
GLProxy.getInstance();
@@ -337,7 +337,7 @@ public class RenderableBoxGroup
@Override
public void close()
{
GLProxy.getInstance().queueRunningOnRenderThread(() ->
GLProxy.queueRunningOnRenderThread(() ->
{
if (this.instanceChunkPosVbo != 0)
{