From 08476b5779f65c5bdda900111a23478b5f3ad528 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Sun, 31 Mar 2024 15:10:56 -0700 Subject: [PATCH] Delicious words - Check against totalAvailable in StagingBuffer#reserveForCopy - Fixes garbage being rendered after uploading large amounts of data --- .../flywheel/backend/engine/indirect/StagingBuffer.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/StagingBuffer.java b/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/StagingBuffer.java index a419c6fb1..0556c0c2e 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/StagingBuffer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/StagingBuffer.java @@ -164,9 +164,8 @@ public class StagingBuffer { */ public long reserveForCopy(long size, int dstVbo, long dstOffset) { assertMultipleOf4(size); - // Don't need to check totalAvailable here because that's a looser constraint than the bytes remaining. long remaining = capacity - pos; - if (size > remaining) { + if (size > remaining || size > totalAvailable) { return MemoryUtil.NULL; } @@ -236,6 +235,10 @@ public class StagingBuffer { } private void pushTransfer(int dstVbo, long srcOffset, long dstOffset, long size) { + if (totalAvailable < size) { + throw new IllegalStateException("Not enough available space to transfer"); + } + transfers.push(dstVbo, srcOffset, dstOffset, size); usedCapacity += size; totalAvailable -= size;