Skip to content

Commit a0b9d31

Browse files
authored
Fix memory corruption caused by GlyphExtVertexSerializer (#760)
1 parent 5751a2f commit a0b9d31

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/sodiumCompatibility/java/net/irisshaders/iris/compat/sodium/impl/vertex_format/GlyphExtVertexSerializer.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ public class GlyphExtVertexSerializer implements VertexSerializer {
2222
private static final Vector3f saveNormal = new Vector3f();
2323
private static final int STRIDE = IrisVertexFormats.GLYPH.getVertexSize();
2424

25-
private static void endQuad(float uSum, float vSum, long src, long dst) {
25+
private static void endQuad(float uSum, float vSum, long dst) {
2626
uSum *= 0.25f;
2727
vSum *= 0.25f;
2828

29-
quad.setup(src, IrisVertexFormats.GLYPH.getVertexSize());
29+
quad.setup(dst, STRIDE);
3030

3131
float normalX, normalY, normalZ;
3232

@@ -48,6 +48,11 @@ private static void endQuad(float uSum, float vSum, long src, long dst) {
4848

4949
@Override
5050
public void serialize(long src, long dst, int vertexCount) {
51+
// The code below assumes there are exactly 4 vertices being pushed
52+
if (vertexCount != 4) {
53+
throw new IllegalStateException();
54+
}
55+
5156
float uSum = 0.0f, vSum = 0.0f;
5257

5358
for (int i = 0; i < vertexCount; i++) {
@@ -64,9 +69,9 @@ public void serialize(long src, long dst, int vertexCount) {
6469
MemoryUtil.memPutShort(dst + 36, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedItem());
6570

6671
src += DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP.getVertexSize();
67-
dst += IrisVertexFormats.GLYPH.getVertexSize();
72+
dst += STRIDE;
6873
}
6974

70-
endQuad(uSum, vSum, src, dst);
75+
endQuad(uSum, vSum, dst - STRIDE); // Point to the *start* of the last vertex.
7176
}
7277
}

0 commit comments

Comments
 (0)