Skip to content

Fix crash on renderbuffers with no sampler filter (#674)#870

Open
Chaos02 wants to merge 1 commit into
xCollateral:devfrom
Chaos02:fix/xaero-fbo-compat
Open

Fix crash on renderbuffers with no sampler filter (#674)#870
Chaos02 wants to merge 1 commit into
xCollateral:devfrom
Chaos02:fix/xaero-fbo-compat

Conversation

@Chaos02

@Chaos02 Chaos02 commented Jul 15, 2026

Copy link
Copy Markdown

VkGlRenderbuffer treats a GL renderbuffer like a sampled texture and demands a min filter. A renderbuffer is a render target with no sampler, so minFilter stays at its unset default of 0 and updateSampler() falls through to throw "Unexpected min filter value: 0". Treat minFilter == 0 as "no sampler needed" and return early.

Triggered in the wild by Xaero's ImprovedFramebuffer (issue #674). Confirmed fixed in-game on MC 1.21.1 with Xaero's Minimap / World Map.

Scope note: I originally paired this with a framebuffer deferred-attach guard, but that only turns the crash into wrong-texture map rendering — Xaero's map needs a proper deferred attachment-resolve in VkGlFramebuffer, which I'm working on separately. This PR is just the standalone renderbuffer crash fix.

Copilot AI review requested due to automatic review settings July 15, 2026 19:02

Copilot AI 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.

Pull request overview

This PR adds defensive handling in the GL emulation layer to avoid crashes when other mods create or configure custom framebuffer objects (FBOs) in ways that real OpenGL tolerates (notably Xaero’s ImprovedFramebuffer).

Changes:

  • Skip VkGlRenderbuffer.updateSampler() work when minFilter is unset (0) to avoid throwing on renderbuffer-backed images.
  • Add a guard in VkGlFramebuffer.framebufferTexture2D to avoid attaching/begin-rendering when the target texture (or its VulkanImage) is not yet allocated.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/main/java/net/vulkanmod/gl/VkGlRenderbuffer.java Adds an early-return in updateSampler() for renderbuffers with unset min filter.
src/main/java/net/vulkanmod/gl/VkGlFramebuffer.java Adds a deferred-attach guard in framebufferTexture2D to avoid null-image attachment crashes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +120 to +122
VkGlTexture vkGlTexture = VkGlTexture.getTexture(texture);
if (vkGlTexture == null || vkGlTexture.getVulkanImage() == null)
return;
VkGlRenderbuffer treats a GL renderbuffer like a sampled texture and
demands a min-filter. A GL renderbuffer is a render target, not a sampled
resource, so it legitimately has no sampler/filter: minFilter stays at its
unset default of 0. updateSampler() then falls through to its default ->
branch and throws:

    java.lang.IllegalStateException: Unexpected min filter value: 0
        at net.vulkanmod.gl.VkGlRenderbuffer.updateSampler(VkGlRenderbuffer.java:178)
        at net.vulkanmod.gl.VkGlRenderbuffer.allocateIfNeeded(VkGlRenderbuffer.java:133)
        at net.vulkanmod.gl.VkGlRenderbuffer.renderbufferStorage(VkGlRenderbuffer.java:58)

This crashes any mod that builds a custom FBO with a depth renderbuffer;
in the wild it is triggered by Xaero's ImprovedFramebuffer.renderbufferStorage
(issue xCollateral#674).

Fix: treat minFilter == 0 as "no sampler needed" and return early from
updateSampler(), skipping sampler creation for the renderbuffer.
@Chaos02
Chaos02 force-pushed the fix/xaero-fbo-compat branch 2 times, most recently from 9b1d271 to 18b37c3 Compare July 16, 2026 08:08
@Chaos02 Chaos02 changed the title Tolerate custom FBOs from other mods (Xaero): renderbuffer without filter, deferred texture attach Fix crash on renderbuffers with no sampler filter (#674) Jul 16, 2026
@Chaos02

Chaos02 commented Jul 16, 2026

Copy link
Copy Markdown
Author

Scope note while this is open, since it is Xaero motivated:

The renderbuffer crash fixed here (#674), and the FBO deferred-attach issue mentioned in the description, are both legitimately VulkanMod's side. VulkanMod emulates GL framebuffers, so it should tolerate an FBO built the way Xaero builds one (attach-before-allocate).

There is a third Xaero-on-VulkanMod crash that I would call out of scope for VulkanMod though. Xaero's World Map calls org.lwjgl.opengl.GL.getCapabilities() from MapLimiter.determineDriverType (driver / VRAM detection) and dies with IllegalStateException: No GLCapabilities instance set for the current thread under VulkanMod. A Vulkan backend has no GL context to report capabilities for, so that one belongs on Xaero's side rather than being emulated here.

Xaero's trackers, for cross reference:

Flagging it so it does not get lumped into VulkanMod's Xaero compat surface.

@Chaos02

Chaos02 commented Jul 16, 2026

Copy link
Copy Markdown
Author

Related PRs from the same effort (getting a VulkanMod based 1.21.1 pack working):

One correction to the scope note in the description above. I said Xaero's map needed a proper deferred attachment resolve in VkGlFramebuffer, and that I was working on it separately. That turned out to be wrong. I built that fix and traced it in game: the FBO lifecycle is actually healthy, and the map was still corrupted. The real cause was UNPACK_ROW_LENGTH == 0 being taken literally, which is what #872 fixes.

The deferred attach case is still real (a texture attached to an FBO before its storage is allocated does throw "Image is null"), it is just a separate crash rather than the map corruption. Happy to put that up separately if it is wanted.

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.

2 participants