Delicious words

- Check against totalAvailable in StagingBuffer#reserveForCopy
- Fixes garbage being rendered after uploading large amounts of data
This commit is contained in:
Jozufozu 2024-03-31 15:10:56 -07:00
parent dfca589c5b
commit 08476b5779

View file

@ -164,9 +164,8 @@ public class StagingBuffer {
*/ */
public long reserveForCopy(long size, int dstVbo, long dstOffset) { public long reserveForCopy(long size, int dstVbo, long dstOffset) {
assertMultipleOf4(size); assertMultipleOf4(size);
// Don't need to check totalAvailable here because that's a looser constraint than the bytes remaining.
long remaining = capacity - pos; long remaining = capacity - pos;
if (size > remaining) { if (size > remaining || size > totalAvailable) {
return MemoryUtil.NULL; return MemoryUtil.NULL;
} }
@ -236,6 +235,10 @@ public class StagingBuffer {
} }
private void pushTransfer(int dstVbo, long srcOffset, long dstOffset, long size) { 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); transfers.push(dstVbo, srcOffset, dstOffset, size);
usedCapacity += size; usedCapacity += size;
totalAvailable -= size; totalAvailable -= size;