From 09c6306ca99a24b2b0aca5198899cbdd24b66fe2 Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Fri, 12 Apr 2024 17:42:31 -0400 Subject: [PATCH] Fix arena growth being calculated with bytes instead of elements This caused excessively large arenas in some test scenarios, with most of the allocated space unused --- .../mods/sodium/client/gl/arena/GlBufferArena.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/jellysquid/mods/sodium/client/gl/arena/GlBufferArena.java b/src/main/java/me/jellysquid/mods/sodium/client/gl/arena/GlBufferArena.java index 96206f518..95b7ca2b8 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/gl/arena/GlBufferArena.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/gl/arena/GlBufferArena.java @@ -277,9 +277,9 @@ public boolean upload(CommandList commandList, Stream stream) { // If we weren't able to upload some buffers, they will have been left behind in the queue if (!queue.isEmpty()) { // Calculate the amount of memory needed for the remaining uploads - int remainingElements = queue.stream() - .mapToInt(upload -> upload.getDataBuffer().getLength()) - .sum(); + int remainingElements = (int)(queue.stream() + .mapToLong(upload -> upload.getDataBuffer().getLength()) + .sum() / this.stride); // Ask the arena to grow to accommodate the remaining uploads // This will force a re-allocation and compaction, which will leave us a continuous free segment