mesa: in slang linker, replace assertion with link error when max samplers exceeded
authorBrian Paul <brian.paul@tungstengraphics.com>
Tue, 9 Dec 2008 21:30:42 +0000 (14:30 -0700)
committerBrian Paul <brian.paul@tungstengraphics.com>
Tue, 16 Dec 2008 01:19:05 +0000 (18:19 -0700)
src/mesa/shader/slang/slang_link.c

index 08d7540372392f1c8251a170e82e1031242c4984..834f05176c43ca2d56e5eab23df2dde2155fed95 100644 (file)
@@ -207,7 +207,7 @@ link_varying_vars(struct gl_shader_program *shProg, struct gl_program *prog)
  * This is basically a list/index of all uniforms found in either/both of
  * the vertex and fragment shaders.
  */
-static void
+static GLboolean
 link_uniform_vars(struct gl_shader_program *shProg,
                   struct gl_program *prog,
                   GLuint *numSamplers)
@@ -239,7 +239,10 @@ link_uniform_vars(struct gl_shader_program *shProg,
          /* Allocate a new sampler index */
          GLuint sampNum = *numSamplers;
          GLuint oldSampNum = (GLuint) prog->Parameters->ParameterValues[i][0];
-         assert(oldSampNum < MAX_SAMPLERS);
+         if (oldSampNum >= MAX_SAMPLERS) {
+            link_error(shProg, "Too many texture samplers");
+            return GL_FALSE;
+         }
          samplerMap[oldSampNum] = sampNum;
          (*numSamplers)++;
       }
@@ -265,6 +268,7 @@ link_uniform_vars(struct gl_shader_program *shProg,
       }
    }
 
+   return GL_TRUE;
 }
 
 
@@ -560,10 +564,18 @@ _slang_link(GLcontext *ctx,
    }
 
    /* link uniform vars */
-   if (shProg->VertexProgram)
-      link_uniform_vars(shProg, &shProg->VertexProgram->Base, &numSamplers);
-   if (shProg->FragmentProgram)
-      link_uniform_vars(shProg, &shProg->FragmentProgram->Base, &numSamplers);
+   if (shProg->VertexProgram) {
+      if (!link_uniform_vars(shProg, &shProg->VertexProgram->Base,
+                             &numSamplers)) {
+         return;
+      }
+   }
+   if (shProg->FragmentProgram) {
+      if (!link_uniform_vars(shProg, &shProg->FragmentProgram->Base,
+                             &numSamplers)) {
+         return;
+      }
+   }
 
    /*_mesa_print_uniforms(shProg->Uniforms);*/