Skip to content

Commit 32bbbcd

Browse files
authored
fix: Fixed division by 0 (#329)
1 parent 62df1a3 commit 32bbbcd

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

headlessmc-lwjgl/src/main/java/io/github/headlesshq/headlessmc/lwjgl/LwjglProperties.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public interface LwjglProperties {
1010
String REFRESH_RATE = "hmc.lwjgl.refreshrate";
1111
String BITS_PER_PIXEL = "hmc.lwjgl.bitsperpixel";
1212
String JNI_VERSION = "hmc.lwjgl.nativejniversion";
13+
String UNIFORM_OFFSET_ALIGNMENT = "hmc.lwjgl.uniformoffsetalignment";
1314
String NO_AWT = "hmc.lwjgl.no.awt";
1415

1516
String TWEAKER_MAIN_CLASS = "hmc.tweaker.main.class";

headlessmc-lwjgl/src/main/java/io/github/headlesshq/headlessmc/lwjgl/redirections/LwjglRedirections.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
public class LwjglRedirections {
1818
public static final int GL_TEXTURE_WIDTH = 4096;
1919
public static final int GL_TEXTURE_INTERNAL_FORMAT_CONST = 4099;
20+
public static final int GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT = 0x8A34;
21+
2022
public static final int GL_TEXTURE_INTERNAL_FORMAT = Integer.parseInt(
2123
System.getProperty(LwjglProperties.GL_TEXTURE_INTERNAL_FORMAT, "32856")); //RGBA8
2224
public static final int TEXTURE_SIZE = Integer.parseInt(
@@ -33,6 +35,8 @@ public class LwjglRedirections {
3335
System.getProperty(LwjglProperties.BITS_PER_PIXEL, "32"));
3436
public static final int JNI_VERSION = Integer.parseInt(
3537
System.getProperty(LwjglProperties.JNI_VERSION, "24"));
38+
public static final int UNIFORM_OFFSET_ALIGNMENT = Integer.parseInt(
39+
System.getProperty(LwjglProperties.UNIFORM_OFFSET_ALIGNMENT, "1"));
3640
private static final ThreadLocal<Long> CURRENT_BUFFER_SIZE =
3741
ThreadLocal.withInitial(() -> 0L);
3842
private static final long START = System.nanoTime();
@@ -315,6 +319,19 @@ public static void register(RedirectionManager manager) {
315319
//j net.caffeinemc.mods.sodium.api.memory.MemoryIntrinsics.copyMemory(JJI)V+8
316320
//j net.minecraft.class_287.push(Lorg/lwjgl/system/MemoryStack;JILnet/caffeinemc/mods/sodium/api/vertex/format/VertexFormatDescription;)V+47
317321
//j me.jellysquid.mods.sodium.client.render.vertex.buffer.SodiumBufferBuilder.push(Lorg/lwjgl/system/MemoryStack;JILnet/caffeinemc/mods/sodium/api/vertex/format
322+
323+
// 1.21.6 onwards
324+
// DynamicUniformStorage.<init>
325+
// GlDevice this.uniformOffsetAlignment = GL11.glGetInteger(35380);
326+
// division by zero, because the integer returned is 0
327+
manager.redirect("Lorg/lwjgl/opengl/GL11;glGetInteger(I)I",
328+
(obj, desc, type, args) -> {
329+
if ((int) args[0] == GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT) {
330+
return UNIFORM_OFFSET_ALIGNMENT;
331+
}
332+
333+
return 0;
334+
});
318335
}
319336

320337
}

0 commit comments

Comments
 (0)