From c4539fb9e9de8344757154207ff846cac55d0f87 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Fri, 7 Feb 2025 14:49:57 +0800 Subject: [PATCH] misc(framebuffer): avoid freeing wild pointer, fixing forge crash on startup --- src/main/cpp/gl/framebuffer.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/cpp/gl/framebuffer.c b/src/main/cpp/gl/framebuffer.c index 894f1de..72c7995 100644 --- a/src/main/cpp/gl/framebuffer.c +++ b/src/main/cpp/gl/framebuffer.c @@ -41,13 +41,18 @@ void rebind_framebuffer(GLenum old_attachment, GLenum target_attachment) { void glBindFramebuffer(GLenum target, GLuint framebuffer) { LOG() + INIT_CHECK_GL_ERROR + LOG_D("glBindFramebuffer(0x%x, %d)", target, framebuffer) LOAD_GLES(glBindFramebuffer, void, GLenum target, GLuint framebuffer) gles_glBindFramebuffer(target, framebuffer); + CHECK_GL_ERROR_NO_INIT - if (!bound_framebuffer) + if (!bound_framebuffer) { bound_framebuffer = malloc(sizeof(struct framebuffer_t)); + memset(bound_framebuffer, 0, sizeof(struct framebuffer_t)); + } switch (target) { case GL_DRAW_FRAMEBUFFER: @@ -68,7 +73,7 @@ void glBindFramebuffer(GLenum target, GLuint framebuffer) { break; } - CHECK_GL_ERROR + CHECK_GL_ERROR_NO_INIT } void glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) {