Skip to content

Commit 9b1d271

Browse files
committed
Guard framebufferTexture2D against a not-yet-allocated attachment image
VkGlFramebuffer.framebufferTexture2D unconditionally attaches the target texture's backing VulkanImage, but a texture can legitimately be attached to an FBO before its storage has been allocated (real GL leaves the FBO incomplete until then). setAttachmentTexture only null-checks the VkGlTexture, not its VulkanImage, so setAttachmentImage throws "NullPointerException: Image is null" — crashing e.g. Xaero's ImprovedFramebuffer. Skip the attach/create/beginRendering when the texture is missing or its image is not yet allocated, mirroring the leniency already applied in the sibling framebufferRenderbuffer.
1 parent 18b37c3 commit 9b1d271

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/main/java/net/vulkanmod/gl/VkGlFramebuffer.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ public static void framebufferTexture2D(int target, int attachment, int texTarge
110110
throw new UnsupportedOperationException();
111111
}
112112

113+
// Deferred-attach guard: a texture may be attached to an FBO before its
114+
// backing storage (VulkanImage) has been allocated. Real GL tolerates
115+
// this — the FBO is simply incomplete until the storage exists — so skip
116+
// the attach/create/begin instead of throwing "Image is null" in
117+
// setAttachmentImage. Mirrors the leniency of framebufferRenderbuffer
118+
// below (which returns early instead of dereferencing a not-ready state).
119+
// Fixes the crash triggered by Xaero's ImprovedFramebuffer.
120+
VkGlTexture vkGlTexture = VkGlTexture.getTexture(texture);
121+
if (vkGlTexture == null || vkGlTexture.getVulkanImage() == null)
122+
return;
123+
113124
boundFramebuffer.setAttachmentTexture(attachment, texture);
114125
boundFramebuffer.create();
115126
VkGlFramebuffer.beginRendering(boundFramebuffer);

0 commit comments

Comments
 (0)