Skip to content

Commit 856abb7

Browse files
GLObjWrapper: do not allow debug label length exceed the GL_MAX_LABEL_LENGTH
1 parent 37bc6cd commit 856abb7

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

Graphics/GraphicsEngineOpenGL/include/GLObjectWrapper.hpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,29 @@ class GLObjWrapper
126126
VERIFY_EXPR(Name != nullptr);
127127
if (glObjectLabel && m_uiHandle)
128128
{
129-
glObjectLabel(m_CreateReleaseHelper.Type, m_uiHandle, -1, Name);
129+
static GLint MaxLabelLen = 0;
130+
if (MaxLabelLen == 0)
131+
{
132+
glGetIntegerv(GL_MAX_LABEL_LENGTH, &MaxLabelLen);
133+
# ifdef DILIGENT_DEVELOPMENT
134+
glGetError(); // Ignore GL error
135+
# endif
136+
if (MaxLabelLen <= 0)
137+
{
138+
// Minimum required value by the spec
139+
MaxLabelLen = 256;
140+
}
141+
142+
// The spec requires that the number of characters in <label>,
143+
// excluding the null terminator, is less than the value of MAX_LABEL_LENGTH.
144+
// In other words, the maximum length of the label is one less than the value of MAX_LABEL_LENGTH.
145+
--MaxLabelLen;
146+
}
147+
GLsizei Length = static_cast<GLsizei>(strlen(Name));
148+
if (Length > MaxLabelLen)
149+
Length = MaxLabelLen;
150+
151+
glObjectLabel(m_CreateReleaseHelper.Type, m_uiHandle, Length, Name);
130152
# ifdef DILIGENT_DEVELOPMENT
131153
glGetError(); // Ignore GL error
132154
# endif

0 commit comments

Comments
 (0)