From e888921819cc0a64c0f6b5977dacde219c688db7 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sat, 19 Apr 2008 01:31:47 -0400 Subject: [PATCH] Don't create unnecessary attributes. Pixel shaders and no-item lists shouldn't call Malloc(). --HG-- branch : trunk --- mojoshader.c | 10 ++++++++++ mojoshader.h | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/mojoshader.c b/mojoshader.c index 8c31fbf5..ac1d1a4b 100644 --- a/mojoshader.c +++ b/mojoshader.c @@ -4233,6 +4233,16 @@ static MOJOSHADER_uniform *build_uniforms(Context *ctx) static MOJOSHADER_attribute *build_attributes(Context *ctx) { + if (ctx->shader_type == MOJOSHADER_TYPE_PIXEL) + { + if (ctx->attribute_count > 0) + fail(ctx, "BUG: pixel shader shouldn't have vertex attributes"); + return NULL; // nothing to do for pixel shaders. + } // if + + if (ctx->attribute_count == 0) + return NULL; // nothing to do. + MOJOSHADER_attribute *retval = (MOJOSHADER_attribute *) Malloc(ctx, sizeof (MOJOSHADER_attribute) * ctx->attribute_count); diff --git a/mojoshader.h b/mojoshader.h index 168bcc69..252c919d 100644 --- a/mojoshader.h +++ b/mojoshader.h @@ -170,10 +170,10 @@ typedef struct /* * (uniform_count) elements of data that specify Uniforms to be set for * this shader. See discussion on MOJOSHADER_uniform for details. + * This can be NULL on error or if (uniform_count) is zero. */ MOJOSHADER_uniform *uniforms; - /* * The number of elements pointed to by (attributes). */ @@ -182,6 +182,7 @@ typedef struct /* * (attribute_count) elements of data that specify Attributes to be set * for this shader. See discussion on MOJOSHADER_attribute for details. + * This can be NULL on error or if (attribute_count) is zero. */ MOJOSHADER_attribute *attributes;