Fix incorrect buffer batching in multiblock preview rendering on 1.21.1#376
Fix incorrect buffer batching in multiblock preview rendering on 1.21.1#376kawaiixissa13 wants to merge 2 commits into
Conversation
kawaiixissa13
commented
Jul 16, 2026
fixes rendering issues, particularly those revealed by interactions with apotheosis or anything else that uses the neoforge AFTER_TRIPWIRE rendering stage?
idk if this is a problem w other loaders, i only tested the issue and fix on neoforge...
fixes #339 in my testing
for reference heres what it looked like before
There was a problem hiding this comment.
Code Review
This pull request updates MultiblockPreviewRenderer.java to call endBatch() on the main buffer source before initializing the preview buffers, resolving batching issues. The review feedback highlights that statically caching the buffers wrapper can lead to stale references when the game's render buffers are recreated. It is recommended to re-initialize the buffers on every render call to ensure they remain active and to fix the indentation formatting.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| var mainBuffers = mc.renderBuffers().bufferSource(); | ||
| mainBuffers.endBatch(); // when we do initBuffers we keep the buffers but dont know if were still batching, so it doesnt properly end in the getBuffer call and breaks stuff | ||
| if (buffers == null) { | ||
| buffers = initBuffers(mc.renderBuffers().bufferSource()); | ||
| buffers = initBuffers(mainBuffers); | ||
| } |
There was a problem hiding this comment.
Caching the buffers wrapper statically using if (buffers == null) is problematic.
The game's RenderBuffers or its underlying BufferSource can be recreated or re-initialized (for example, during resource pack reloads, dimension changes, or graphics settings adjustments). If this happens, the statically cached buffers will hold references to stale, disposed buffers. This can cause the multiblock preview to stop rendering entirely or lead to memory leaks and crashes.
Since initBuffers is extremely lightweight (it only wraps the existing buffer source and maps a few render types), we should re-initialize buffers on every call to renderMultiblock to ensure it always uses the active BufferSource of the current frame. Additionally, this suggestion fixes the tab indentation to match the rest of the file (using spaces instead of tabs).
var mainBuffers = mc.renderBuffers().bufferSource();
mainBuffers.endBatch(); // when we do initBuffers we keep the buffers but dont know if were still batching, so it doesnt properly end in the getBuffer call and breaks stuff
buffers = initBuffers(mainBuffers);There was a problem hiding this comment.
that isnt right, it doesnt break anything to do that but it works fine and might have a small performance hit. and even if it was right that code was already like that unrelated to what this fixes so it should be done seprately
edit: fixed the indentation though