Fix T75981: crash in sculpt mode with mesh that used to have multiple materials
The material indices in a mesh can exceed the number of available materials slots in the object or mesh, sculpt drawing was not taking that into account.
This commit is contained in:
parent
b2cc2dda9c
commit
bc83fc9c04
Notes:
blender-bot
2023-02-14 01:35:49 +01:00
Referenced by issue #75981, Crash switching to Sculpt mode with material using Backface Culling
|
@ -2089,16 +2089,16 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata,
|
|||
for (int i = 0; i < materials_len; i++) {
|
||||
sculpt_shgrps_array[i] = shgrps_array[i].shading_grp;
|
||||
}
|
||||
DRW_shgroup_call_sculpt_with_materials(sculpt_shgrps_array, ob, use_vcol);
|
||||
DRW_shgroup_call_sculpt_with_materials(sculpt_shgrps_array, materials_len, ob, use_vcol);
|
||||
|
||||
for (int i = 0; i < materials_len; i++) {
|
||||
sculpt_shgrps_array[i] = shgrps_array[i].depth_grp;
|
||||
}
|
||||
DRW_shgroup_call_sculpt_with_materials(sculpt_shgrps_array, ob, use_vcol);
|
||||
DRW_shgroup_call_sculpt_with_materials(sculpt_shgrps_array, materials_len, ob, use_vcol);
|
||||
for (int i = 0; i < materials_len; i++) {
|
||||
sculpt_shgrps_array[i] = shgrps_array[i].depth_clip_grp;
|
||||
}
|
||||
DRW_shgroup_call_sculpt_with_materials(sculpt_shgrps_array, ob, use_vcol);
|
||||
DRW_shgroup_call_sculpt_with_materials(sculpt_shgrps_array, materials_len, ob, use_vcol);
|
||||
|
||||
for (int renderpass_index = 0;
|
||||
renderpass_index < stl->g_data->render_passes_material_count;
|
||||
|
@ -2106,7 +2106,7 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata,
|
|||
for (int i = 0; i < materials_len; i++) {
|
||||
sculpt_shgrps_array[i] = shgrps_array[i].material_accum_grp[renderpass_index];
|
||||
}
|
||||
DRW_shgroup_call_sculpt_with_materials(sculpt_shgrps_array, ob, use_vcol);
|
||||
DRW_shgroup_call_sculpt_with_materials(sculpt_shgrps_array, materials_len, ob, use_vcol);
|
||||
}
|
||||
|
||||
/* TODO(fclem): Support shadows in sculpt mode. */
|
||||
|
|
|
@ -126,7 +126,7 @@ static void workbench_cache_sculpt_populate(WORKBENCH_PrivateData *wpd,
|
|||
for (int i = 0; i < materials_len; i++) {
|
||||
shgrps[i] = workbench_material_setup(wpd, ob, i + 1, color_type, NULL);
|
||||
}
|
||||
DRW_shgroup_call_sculpt_with_materials(shgrps, ob, false);
|
||||
DRW_shgroup_call_sculpt_with_materials(shgrps, materials_len, ob, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -411,7 +411,10 @@ void DRW_shgroup_call_instances_with_attrs(DRWShadingGroup *shgroup,
|
|||
struct GPUBatch *inst_attributes);
|
||||
|
||||
void DRW_shgroup_call_sculpt(DRWShadingGroup *sh, Object *ob, bool wire, bool mask, bool vcol);
|
||||
void DRW_shgroup_call_sculpt_with_materials(DRWShadingGroup **sh, Object *ob, bool vcol);
|
||||
void DRW_shgroup_call_sculpt_with_materials(DRWShadingGroup **sh,
|
||||
int num_sh,
|
||||
Object *ob,
|
||||
bool vcol);
|
||||
|
||||
DRWCallBuffer *DRW_shgroup_call_buffer(DRWShadingGroup *shading_group,
|
||||
struct GPUVertFormat *format,
|
||||
|
|
|
@ -858,6 +858,7 @@ void DRW_shgroup_call_instances_with_attrs(DRWShadingGroup *shgroup,
|
|||
typedef struct DRWSculptCallbackData {
|
||||
Object *ob;
|
||||
DRWShadingGroup **shading_groups;
|
||||
int num_shading_groups;
|
||||
bool use_wire;
|
||||
bool use_mats;
|
||||
bool use_mask;
|
||||
|
@ -896,6 +897,9 @@ static void sculpt_draw_cb(DRWSculptCallbackData *scd, GPU_PBVH_Buffers *buffers
|
|||
|
||||
if (scd->use_mats) {
|
||||
index = GPU_pbvh_buffers_material_index_get(buffers);
|
||||
if (index >= scd->num_shading_groups) {
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
DRWShadingGroup *shgrp = scd->shading_groups[index];
|
||||
|
@ -1035,6 +1039,7 @@ void DRW_shgroup_call_sculpt(
|
|||
DRWSculptCallbackData scd = {
|
||||
.ob = ob,
|
||||
.shading_groups = &shgroup,
|
||||
.num_shading_groups = 1,
|
||||
.use_wire = use_wire,
|
||||
.use_mats = false,
|
||||
.use_mask = use_mask,
|
||||
|
@ -1042,11 +1047,15 @@ void DRW_shgroup_call_sculpt(
|
|||
drw_sculpt_generate_calls(&scd, use_vcol);
|
||||
}
|
||||
|
||||
void DRW_shgroup_call_sculpt_with_materials(DRWShadingGroup **shgroups, Object *ob, bool use_vcol)
|
||||
void DRW_shgroup_call_sculpt_with_materials(DRWShadingGroup **shgroups,
|
||||
int num_shgroups,
|
||||
Object *ob,
|
||||
bool use_vcol)
|
||||
{
|
||||
DRWSculptCallbackData scd = {
|
||||
.ob = ob,
|
||||
.shading_groups = shgroups,
|
||||
.num_shading_groups = num_shgroups,
|
||||
.use_wire = false,
|
||||
.use_mats = true,
|
||||
.use_mask = false,
|
||||
|
|
Loading…
Reference in New Issue