Workbench: Fix crash when using more than one metaball
authorClément Foucault <foucault.clem@gmail.com>
Fri, 21 Dec 2018 14:59:13 +0000 (15:59 +0100)
committerClément Foucault <foucault.clem@gmail.com>
Fri, 21 Dec 2018 15:14:19 +0000 (16:14 +0100)
Was caused by recent change in logic

source/blender/draw/engines/workbench/workbench_deferred.c

index 52caeb6cbf433ab471c0afce1224c4e05171f62c..2096d31659d4d1a445f0f6af29ac2fc23fb00d79 100644 (file)
@@ -828,12 +828,14 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
                        /* Draw textured */
                        struct GPUBatch **geom_array = DRW_cache_mesh_surface_texpaint_get(ob);
                        for (int i = 0; i < materials_len; i++) {
-                               Material *mat = give_current_material(ob, i + 1);
-                               Image *image;
-                               ED_object_get_active_image(ob, i + 1, &image, NULL, NULL, NULL);
-                               int color_type = workbench_material_determine_color_type(wpd, image, ob);
-                               material = get_or_create_material_data(vedata, ob, mat, image, color_type);
-                               DRW_shgroup_call_object_add(material->shgrp, geom_array[i], ob);
+                               if (geom_array != NULL && geom_array[i] != NULL) {
+                                       Material *mat = give_current_material(ob, i + 1);
+                                       Image *image;
+                                       ED_object_get_active_image(ob, i + 1, &image, NULL, NULL, NULL);
+                                       int color_type = workbench_material_determine_color_type(wpd, image, ob);
+                                       material = get_or_create_material_data(vedata, ob, mat, image, color_type);
+                                       DRW_shgroup_call_object_add(material->shgrp, geom_array[i], ob);
+                               }
                        }
                }
                else if (ELEM(wpd->shading.color_type,
@@ -845,7 +847,9 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
                        }
                        else {
                                struct GPUBatch *geom = DRW_cache_object_surface_get(ob);
-                               DRW_shgroup_call_object_add(material->shgrp, geom, ob);
+                               if (geom) {
+                                       DRW_shgroup_call_object_add(material->shgrp, geom, ob);
+                               }
                        }
                }
                else {
@@ -863,9 +867,11 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
 
                                geoms = DRW_cache_object_surface_material_get(ob, gpumat_array, materials_len, NULL, NULL, NULL);
                                for (int i = 0; i < materials_len; ++i) {
-                                       Material *mat = give_current_material(ob, i + 1);
-                                       material = get_or_create_material_data(vedata, ob, mat, NULL, V3D_SHADING_MATERIAL_COLOR);
-                                       DRW_shgroup_call_object_add(material->shgrp, geoms[i], ob);
+                                       if (geoms != NULL && geoms[i] != NULL) {
+                                               Material *mat = give_current_material(ob, i + 1);
+                                               material = get_or_create_material_data(vedata, ob, mat, NULL, V3D_SHADING_MATERIAL_COLOR);
+                                               DRW_shgroup_call_object_add(material->shgrp, geoms[i], ob);
+                                       }
                                }
                        }
                }