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 /source/blender/draw/intern | |
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
Diffstat (limited to 'source/blender/draw/intern')
-rw-r--r-- | source/blender/draw/intern/draw_cache.c | 19 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache.h | 3 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl.h | 7 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl_curve.c | 7 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl_mesh.c | 5 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl_metaball.c | 8 |
6 files changed, 46 insertions, 3 deletions
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); +} |