From cc4d8f947478f20d1abb256c29a21a63cf74b143 Mon Sep 17 00:00:00 2001 From: Joseph Cloutier Date: Thu, 23 Oct 2025 00:07:10 -0400 Subject: [PATCH 1/2] Get the correct max length before allocating buffers. `GL_ACTIVE_ATTRIBUTE_MAX_LENGTH` is not itself the length, but a constant used to look up that length. Presumably it's a larger number than necessary, which is why there weren't any problems. https://docs.gl/gl4/glGetActiveAttrib --- project/src/graphics/opengl/OpenGLBindings.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/project/src/graphics/opengl/OpenGLBindings.cpp b/project/src/graphics/opengl/OpenGLBindings.cpp index 31f71096ee..4e1460d618 100644 --- a/project/src/graphics/opengl/OpenGLBindings.cpp +++ b/project/src/graphics/opengl/OpenGLBindings.cpp @@ -1678,12 +1678,15 @@ namespace lime { value result = alloc_empty_object (); - std::string buffer (GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, 0); + GLsizei maxLength = 0; + glGetProgramiv (program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxLength); + + std::string buffer (maxLength, 0); GLsizei outLen = 0; GLsizei size = 0; GLenum type = 0; - glGetActiveAttrib (program, index, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &outLen, &size, &type, &buffer[0]); + glGetActiveAttrib (program, index, maxLength, &outLen, &size, &type, &buffer[0]); buffer.resize (outLen); @@ -1698,12 +1701,15 @@ namespace lime { HL_PRIM vdynamic* HL_NAME(hl_gl_get_active_attrib) (int program, int index) { - char buffer[GL_ACTIVE_ATTRIBUTE_MAX_LENGTH]; + GLsizei maxLength = 0; + glGetProgramiv (program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxLength); + + char buffer[maxLength]; GLsizei outLen = 0; GLsizei size = 0; GLenum type = 0; - glGetActiveAttrib (program, index, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &outLen, &size, &type, &buffer[0]); + glGetActiveAttrib (program, index, maxLength, &outLen, &size, &type, &buffer[0]); char* _buffer = (char*)malloc (outLen + 1); memcpy (_buffer, &buffer, outLen); From 7aa84258e759a055db5085767b214d35d61158dc Mon Sep 17 00:00:00 2001 From: Joseph Cloutier Date: Thu, 23 Oct 2025 01:09:40 -0400 Subject: [PATCH 2/2] Fix buffer allocation. --- project/src/graphics/opengl/OpenGLBindings.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/project/src/graphics/opengl/OpenGLBindings.cpp b/project/src/graphics/opengl/OpenGLBindings.cpp index 4e1460d618..a4c2053f94 100644 --- a/project/src/graphics/opengl/OpenGLBindings.cpp +++ b/project/src/graphics/opengl/OpenGLBindings.cpp @@ -1704,7 +1704,7 @@ namespace lime { GLsizei maxLength = 0; glGetProgramiv (program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxLength); - char buffer[maxLength]; + char* buffer = (char*)malloc (maxLength); GLsizei outLen = 0; GLsizei size = 0; GLenum type = 0; @@ -1715,6 +1715,8 @@ namespace lime { memcpy (_buffer, &buffer, outLen); _buffer[outLen] = '\0'; + free (buffer); + const int id_size = hl_hash_utf8 ("size"); const int id_type = hl_hash_utf8 ("type"); const int id_name = hl_hash_utf8 ("name");