Don't create unnecessary attributes. trunk
authorRyan C. Gordon <icculus@icculus.org>
Sat, 19 Apr 2008 01:31:47 -0400
branchtrunk
changeset 145 5325c8d6077c
parent 144 2483576e1281
child 146 9a0d4707feb8
Don't create unnecessary attributes. Pixel shaders and no-item lists shouldn't call Malloc().
mojoshader.c
mojoshader.h
--- a/mojoshader.c	Fri Apr 18 22:00:19 2008 -0400
+++ b/mojoshader.c	Sat Apr 19 01:31:47 2008 -0400
@@ -4233,6 +4233,16 @@
 
 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);
 
--- a/mojoshader.h	Fri Apr 18 22:00:19 2008 -0400
+++ b/mojoshader.h	Sat Apr 19 01:31:47 2008 -0400
@@ -170,10 +170,10 @@
     /*
      * (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 @@
     /*
      * (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;