cogl-material: Fix the check to prevent using too many layers
authorNeil Roberts <neil@linux.intel.com>
Tue, 27 Apr 2010 15:38:07 +0000 (16:38 +0100)
committerNeil Roberts <neil@linux.intel.com>
Thu, 29 Apr 2010 11:15:17 +0000 (12:15 +0100)
There was a check at the bottom of the loop which sets up the state
for each of the layers so that it would break from the loop when the
maximum number of layers is reached. However after doing this it would
not increment 'i'. 'i' is later used to disable the remaining layers
so it would end up disabling the last layer it just set up.

This patch moves the check to be part of the loop condition so that
the check is performed after incrementing 'i'.

http://bugzilla.openedhand.com/show_bug.cgi?id=2064

clutter/cogl/cogl/cogl-material.c

index a73831e..462c644 100644 (file)
@@ -1469,8 +1469,10 @@ _cogl_material_flush_layers_gl_state (CoglMaterial *material,
 
   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
 
-  for (tmp = material->layers, i = 0; tmp != NULL; tmp = tmp->next, i++)
-    {
+  for (tmp = material->layers, i = 0;
+       tmp != NULL && i < _cogl_get_max_texture_image_units ();
+       tmp = tmp->next, i++)
+   {
       CoglHandle         layer_handle = (CoglHandle)tmp->data;
       CoglMaterialLayer *layer =
         _cogl_material_layer_pointer_from_handle (layer_handle);
@@ -1621,9 +1623,6 @@ _cogl_material_flush_layers_gl_state (CoglMaterial *material,
         g_array_append_val (ctx->current_layers, new_gl_layer_info);
 
       layer->flags &= ~COGL_MATERIAL_LAYER_FLAG_DIRTY;
-
-      if ((i+1) >= _cogl_get_max_texture_image_units ())
-       break;
     }
 
   /* Disable additional texture units that may have previously been in use.. */