diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2020-01-28 18:39:33 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2020-01-28 18:39:37 +0300 |
commit | 3fd4c88e3a2e9d99d45a0856fcc339e013c0a79a (patch) | |
tree | c9349a1f1fc7e80b113ce4110891e27992c12e98 | |
parent | fd0bc7e002ced8ffd85e9aa3edcae173dbd13392 (diff) |
Fix T72593 Blender crashes when modifier change the material count
Instead of changing the modifiers behavior, we make sure to always use
the data->totcol instead of the ob->totcol. Also we centralize getting
this number to avoid future issues.
Fix T72593 Blender crashes when separating mesh
Fix T72017 Crash on set visibility change
9 files changed, 51 insertions, 8 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c index d0fe7c6637e..2c29083199a 100644 --- a/source/blender/draw/engines/eevee/eevee_materials.c +++ b/source/blender/draw/engines/eevee/eevee_materials.c @@ -1457,7 +1457,7 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata, /* First get materials for this mesh. */ if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL)) { - const int materials_len = MAX2(1, ob->totcol); + const int materials_len = DRW_cache_object_material_count_get(ob); struct DRWShadingGroup **shgrp_array = BLI_array_alloca(shgrp_array, materials_len); struct DRWShadingGroup **shgrp_depth_array = BLI_array_alloca(shgrp_depth_array, diff --git a/source/blender/draw/engines/workbench/workbench_deferred.c b/source/blender/draw/engines/workbench/workbench_deferred.c index 1af9357e015..15e8e1711dd 100644 --- a/source/blender/draw/engines/workbench/workbench_deferred.c +++ b/source/blender/draw/engines/workbench/workbench_deferred.c @@ -962,7 +962,7 @@ static void workbench_cache_populate_texture_paint_mode(WORKBENCH_Data *vedata, } else { /* IMAGEPAINT_MODE_MATERIAL */ - const int materials_len = MAX2(1, ob->totcol); + const int materials_len = DRW_cache_object_material_count_get(ob); struct GPUBatch **geom_array = DRW_cache_mesh_surface_texpaint_get(ob); for (int i = 0; i < materials_len; i++) { if (geom_array != NULL && geom_array[i] != NULL) { @@ -1034,7 +1034,7 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob) const bool use_sculpt_pbvh = BKE_sculptsession_use_pbvh_draw(ob, draw_ctx->v3d) && !DRW_state_is_image_render(); const bool use_hide = is_active && DRW_object_use_hide_faces(ob); - const int materials_len = MAX2(1, ob->totcol); + const int materials_len = DRW_cache_object_material_count_get(ob); const Mesh *me = (ob->type == OB_MESH) ? ob->data : NULL; bool has_transp_mat = false; const WORKBENCH_ColorOverride color_override = workbench_object_color_override_get(ob); diff --git a/source/blender/draw/engines/workbench/workbench_forward.c b/source/blender/draw/engines/workbench/workbench_forward.c index ae001f8d10c..3e8c12c0bef 100644 --- a/source/blender/draw/engines/workbench/workbench_forward.c +++ b/source/blender/draw/engines/workbench/workbench_forward.c @@ -594,7 +594,7 @@ static void workbench_forward_cache_populate_texture_paint_mode(WORKBENCH_Data * } else { /* IMAGEPAINT_MODE_MATERIAL */ - const int materials_len = MAX2(1, ob->totcol); + const int materials_len = DRW_cache_object_material_count_get(ob); struct GPUBatch **geom_array = DRW_cache_mesh_surface_texpaint_get(ob); for (int i = 0; i < materials_len; i++) { if (geom_array != NULL && geom_array[i] != NULL) { @@ -668,7 +668,7 @@ void workbench_forward_cache_populate(WORKBENCH_Data *vedata, Object *ob) if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL)) { const bool use_sculpt_pbvh = BKE_sculptsession_use_pbvh_draw(ob, draw_ctx->v3d) && !DRW_state_is_image_render(); - const int materials_len = MAX2(1, ob->totcol); + const int materials_len = DRW_cache_object_material_count_get(ob); const Mesh *me = (ob->type == OB_MESH) ? ob->data : NULL; const WORKBENCH_ColorOverride color_override = workbench_object_color_override_get(ob); const bool use_texture_paint_drawing = !(DRW_state_is_image_render() && diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c index f2e43e032a9..083901c9ebe 100644 --- a/source/blender/draw/intern/draw_cache.c +++ b/source/blender/draw/intern/draw_cache.c @@ -824,6 +824,25 @@ GPUBatch *DRW_cache_object_surface_get(Object *ob) } } +int DRW_cache_object_material_count_get(struct Object *ob) +{ + short type = (ob->runtime.mesh_eval != NULL) ? OB_MESH : ob->type; + + switch (type) { + case OB_MESH: + return DRW_mesh_material_count_get(ob->data); + case OB_CURVE: + case OB_SURF: + case OB_FONT: + return DRW_curve_material_count_get(ob->data); + case OB_MBALL: + return DRW_metaball_material_count_get(ob->data); + default: + BLI_assert(0); + return 0; + } +} + GPUBatch **DRW_cache_object_surface_material_get(struct Object *ob, struct GPUMaterial **gpumat_array, uint gpumat_array_len, diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h index 11564464546..a77a847409b 100644 --- a/source/blender/draw/intern/draw_cache.h +++ b/source/blender/draw/intern/draw_cache.h @@ -59,6 +59,7 @@ struct GPUBatch **DRW_cache_object_surface_material_get(struct Object *ob, int **auto_layer_is_srgb, int *auto_layer_count); struct GPUBatch *DRW_cache_object_face_wireframe_get(struct Object *ob); +int DRW_cache_object_material_count_get(struct Object *ob); /* Empties */ struct GPUBatch *DRW_cache_plain_axes_get(void); @@ -138,8 +139,6 @@ struct GPUBatch *DRW_cache_mesh_surface_weights_get(struct Object *ob); struct GPUBatch *DRW_cache_mesh_surface_mesh_analysis_get(struct Object *ob); struct GPUBatch *DRW_cache_mesh_face_wireframe_get(struct Object *ob); -void DRW_cache_mesh_sculpt_coords_ensure(struct Object *ob); - /* Curve */ struct GPUBatch *DRW_cache_curve_surface_get(struct Object *ob); struct GPUBatch **DRW_cache_curve_surface_shaded_get(struct Object *ob, diff --git a/source/blender/draw/intern/draw_cache_impl.h b/source/blender/draw/intern/draw_cache_impl.h index 8cb318bd0bb..2970314db64 100644 --- a/source/blender/draw/intern/draw_cache_impl.h +++ b/source/blender/draw/intern/draw_cache_impl.h @@ -69,6 +69,8 @@ void DRW_mesh_batch_cache_free_old(struct Mesh *me, int ctime); /* Curve */ void DRW_curve_batch_cache_create_requested(struct Object *ob); +int DRW_curve_material_count_get(struct Curve *cu); + struct GPUBatch *DRW_curve_batch_cache_get_wire_edge(struct Curve *cu); struct GPUBatch *DRW_curve_batch_cache_get_normal_edge(struct Curve *cu); struct GPUBatch *DRW_curve_batch_cache_get_edge_detection(struct Curve *cu, bool *r_is_manifold); @@ -80,7 +82,10 @@ struct GPUBatch **DRW_curve_batch_cache_get_surface_shaded(struct Curve *cu, struct GPUMaterial **gpumat_array, uint gpumat_array_len); struct GPUBatch *DRW_curve_batch_cache_get_wireframes_face(struct Curve *cu); + /* Metaball */ +int DRW_metaball_material_count_get(struct MetaBall *mb); + struct GPUBatch *DRW_metaball_batch_cache_get_triangles_with_normals(struct Object *ob); struct GPUBatch **DRW_metaball_batch_cache_get_surface_shaded(struct Object *ob, struct MetaBall *mb, @@ -163,6 +168,8 @@ struct GPUBatch *DRW_mesh_batch_cache_get_edituv_facedots(struct Mesh *me); struct GPUBatch *DRW_mesh_batch_cache_get_uv_edges(struct Mesh *me); struct GPUBatch *DRW_mesh_batch_cache_get_edit_mesh_analysis(struct Mesh *me); +int DRW_mesh_material_count_get(struct Mesh *me); + /* Edit mesh bitflags (is this the right place?) */ enum { VFLAG_VERT_ACTIVE = 1 << 0, diff --git a/source/blender/draw/intern/draw_cache_impl_curve.c b/source/blender/draw/intern/draw_cache_impl_curve.c index ab800e42cc0..05ec9bda642 100644 --- a/source/blender/draw/intern/draw_cache_impl_curve.c +++ b/source/blender/draw/intern/draw_cache_impl_curve.c @@ -414,7 +414,7 @@ static bool curve_batch_cache_valid(Curve *cu) return false; } - if (cache->mat_len != max_ii(1, cu->totcol)) { + if (cache->mat_len != DRW_curve_material_count_get(cu)) { return false; } @@ -914,6 +914,11 @@ GPUBatch *DRW_curve_batch_cache_get_edge_detection(Curve *cu, bool *r_is_manifol return DRW_batch_request(&cache->batch.edge_detection); } +int DRW_curve_material_count_get(Curve *cu) +{ + return max_ii(1, cu->totcol); +} + /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c index aadcc2a939a..167e48e9c2d 100644 --- a/source/blender/draw/intern/draw_cache_impl_mesh.c +++ b/source/blender/draw/intern/draw_cache_impl_mesh.c @@ -831,6 +831,11 @@ GPUBatch *DRW_mesh_batch_cache_get_surface_vertpaint(Mesh *me) return DRW_batch_request(&cache->batch.surface); } +int DRW_mesh_material_count_get(Mesh *me) +{ + return mesh_render_mat_len_get(me); +} + /** \} */ /* ---------------------------------------------------------------------- */ diff --git a/source/blender/draw/intern/draw_cache_impl_metaball.c b/source/blender/draw/intern/draw_cache_impl_metaball.c index e3bfcbde3ef..c14e66c2b47 100644 --- a/source/blender/draw/intern/draw_cache_impl_metaball.c +++ b/source/blender/draw/intern/draw_cache_impl_metaball.c @@ -25,6 +25,7 @@ #include "MEM_guardedalloc.h" +#include "BLI_math_base.h" #include "BLI_utildefines.h" #include "DNA_meta_types.h" @@ -206,6 +207,8 @@ GPUBatch **DRW_metaball_batch_cache_get_surface_shaded(Object *ob, return NULL; } + BLI_assert(gpumat_array_len == DRW_metaball_material_count_get(mb)); + MetaBallBatchCache *cache = metaball_batch_cache_get(mb); if (cache->shaded_triangles == NULL) { cache->mat_len = gpumat_array_len; @@ -270,3 +273,8 @@ struct GPUBatch *DRW_metaball_batch_cache_get_edge_detection(struct Object *ob, return cache->edge_detection; } + +int DRW_metaball_material_count_get(MetaBall *mb) +{ + return max_ii(1, mb->totcol); +} |