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
This commit is contained in:
@@ -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,
|
||||
|
@@ -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);
|
||||
|
@@ -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() &&
|
||||
|
@@ -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,
|
||||
|
@@ -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,
|
||||
|
@@ -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,
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user