From f097c8773effcc2a1b940371c636ffa8c1cfd4ea Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Wed, 11 Nov 2020 19:11:09 -0500 Subject: [PATCH] mesa: allocate the attribute stack on demand Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/mesa/main/attrib.c | 17 ++++++++++++++--- src/mesa/main/mtypes.h | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c index b03457b..0e38511 100644 --- a/src/mesa/main/attrib.c +++ b/src/mesa/main/attrib.c @@ -78,7 +78,15 @@ _mesa_PushAttrib(GLbitfield mask) return; } - head = &ctx->AttribStack[ctx->AttribStackDepth]; + head = ctx->AttribStack[ctx->AttribStackDepth]; + if (unlikely(!head)) { + head = CALLOC_STRUCT(gl_attrib_node); + if (unlikely(!head)) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushAttrib"); + return; + } + ctx->AttribStack[ctx->AttribStackDepth] = head; + } head->Mask = mask; if (mask & GL_ACCUM_BUFFER_BIT) @@ -650,7 +658,7 @@ _mesa_PopAttrib(void) } ctx->AttribStackDepth--; - attr = &ctx->AttribStack[ctx->AttribStackDepth]; + attr = ctx->AttribStack[ctx->AttribStackDepth]; unsigned mask = attr->Mask; @@ -1471,11 +1479,14 @@ _mesa_free_attrib_data(struct gl_context *ctx) struct gl_attrib_node *attr; ctx->AttribStackDepth--; - attr = &ctx->AttribStack[ctx->AttribStackDepth]; + attr = ctx->AttribStack[ctx->AttribStackDepth]; if (attr->Mask & GL_TEXTURE_BIT) _mesa_reference_shared_state(ctx, &attr->Texture.SharedRef, NULL); } + + for (unsigned i = 0; i < ARRAY_SIZE(ctx->AttribStack); i++) + free(ctx->AttribStack[i]); } diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index bc42670..a15bdf8 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -5195,7 +5195,7 @@ struct gl_context /** \name State attribute stack (for glPush/PopAttrib) */ /*@{*/ GLuint AttribStackDepth; - struct gl_attrib_node AttribStack[MAX_ATTRIB_STACK_DEPTH]; + struct gl_attrib_node *AttribStack[MAX_ATTRIB_STACK_DEPTH]; /*@}*/ /** \name Renderer attribute groups -- 2.7.4