Skip to content

Fix incorrect buffer batching in multiblock preview rendering on 1.21.1#376

Open
kawaiixissa13 wants to merge 2 commits into
klikli-dev:version/1.21.1from
kawaiixissa13:fix/1.21.1-render-batching
Open

Fix incorrect buffer batching in multiblock preview rendering on 1.21.1#376
kawaiixissa13 wants to merge 2 commits into
klikli-dev:version/1.21.1from
kawaiixissa13:fix/1.21.1-render-batching

Conversation

@kawaiixissa13

Copy link
Copy Markdown
image image 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 image

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 253 to 257
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);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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);

@kawaiixissa13 kawaiixissa13 Jul 16, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant