Skip to content

Commit

Permalink
Don't create unnecessary attributes.
Browse files Browse the repository at this point in the history
Pixel shaders and no-item lists shouldn't call Malloc().

--HG--
branch : trunk
  • Loading branch information
icculus committed Apr 19, 2008
1 parent b6b3fe9 commit e888921
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions mojoshader.c
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion mojoshader.h
Expand Up @@ -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).
*/
Expand All @@ -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;

Expand Down

0 comments on commit e888921

Please sign in to comment.