llvmpipe: Prevent segfault during fs variant cache shrinking.
authorJosé Fonseca <jfonseca@vmware.com>
Wed, 28 Sep 2011 19:23:13 +0000 (20:23 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Thu, 29 Sep 2011 16:43:38 +0000 (17:43 +0100)
src/gallium/drivers/llvmpipe/lp_state_fs.c

index 6243a96f454a1321f16ddc088ff144ed5f249839..646c38d2aee0f09519126f4b937735b0a98a4e3d 100644 (file)
@@ -1366,10 +1366,21 @@ llvmpipe_update_fs(struct llvmpipe_context *lp)
           */
          llvmpipe_finish(pipe, __FUNCTION__);
 
-         for (i = 0; i < LP_MAX_SHADER_VARIANTS / 4; i++) {
-            struct lp_fs_variant_list_item *item;
-            item = last_elem(&lp->fs_variants_list);
-            llvmpipe_remove_shader_variant(lp, item->base);
+         /*
+          * We need to re-check lp->nr_fs_variants because an arbitrarliy large
+          * number of shader variants (potentially all of them) could be
+          * pending for destruction on flush.
+          */
+
+         if (lp->nr_fs_variants >= LP_MAX_SHADER_VARIANTS) {
+            for (i = 0; i < LP_MAX_SHADER_VARIANTS / 4; i++) {
+               struct lp_fs_variant_list_item *item;
+               item = last_elem(&lp->fs_variants_list);
+               if (!item) {
+                  break;
+               }
+               llvmpipe_remove_shader_variant(lp, item->base);
+            }
          }
       }