Skip to content

Commit 8d2e896

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

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-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

Graphics/GraphicsEngineOpenGL/include/GLStubsAndroid.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,11 @@
10371037
#endif
10381038

10391039

1040+
#ifndef GL_MAX_LABEL_LENGTH
1041+
# define GL_MAX_LABEL_LENGTH 0x82E8
1042+
#endif
1043+
1044+
10401045
/* ------------------------------ GL_EXT_disjoint_timer_query ----------------------------- */
10411046
#ifndef GL_TIMESTAMP
10421047
# define GL_TIMESTAMP 0x8E28

0 commit comments

Comments
 (0)