GOOENGINE: Fix crash when material unassigned to faces
Ports the function change from this commit 2fda20e1db
Without it if any material slot is not assigned to any faces on a model and there are 6 or more material slots it crashes goo engine
This commit is contained in:
@@ -294,7 +294,7 @@ void EEVEE_cryptomatte_cache_populate(EEVEE_Data *vedata, EEVEE_ViewLayerData *s
|
||||
view_layer);
|
||||
|
||||
if ((cryptomatte_layers & VIEW_LAYER_CRYPTOMATTE_MATERIAL) != 0) {
|
||||
const int materials_len = DRW_cache_object_material_count_get(ob);
|
||||
const int materials_len = BKE_object_material_used_with_fallback_eval(*ob);
|
||||
GPUMaterial **gpumat_array = BLI_array_alloca(gpumat_array, materials_len);
|
||||
memset(gpumat_array, 0, sizeof(*gpumat_array) * materials_len);
|
||||
blender::gpu::Batch **geoms = GOO_cache_object_surface_material_get(
|
||||
|
||||
@@ -848,7 +848,7 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata,
|
||||
|
||||
/* First get materials for this mesh. */
|
||||
if (ELEM(ob->type, OB_MESH, OB_SURF)) {
|
||||
const int materials_len = DRW_cache_object_material_count_get(ob);
|
||||
const int materials_len = BKE_object_material_used_with_fallback_eval(*ob);
|
||||
|
||||
EeveeMaterialCache *matcache = BLI_array_alloca(matcache, materials_len);
|
||||
for (int i = 0; i < materials_len; i++) {
|
||||
|
||||
@@ -934,39 +934,6 @@ blender::gpu::VertBuf *DRW_cache_object_pos_vertbuf_get(Object *ob)
|
||||
}
|
||||
}
|
||||
|
||||
int DRW_cache_object_material_count_get(const Object *ob)
|
||||
{
|
||||
using namespace blender::draw;
|
||||
short type = ob->type;
|
||||
|
||||
Mesh *mesh = BKE_object_get_evaluated_mesh_no_subsurf_unchecked(ob);
|
||||
if (mesh != nullptr && type != OB_POINTCLOUD) {
|
||||
/* Some object types can have one data type in ob->data, but will be rendered as mesh.
|
||||
* For point clouds this never happens. Ideally this check would happen at another level
|
||||
* and we would just have to care about ob->data here. */
|
||||
type = OB_MESH;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case OB_MESH:
|
||||
return DRW_mesh_material_count_get(
|
||||
*ob, *static_cast<const Mesh *>((mesh != nullptr) ? mesh : ob->data));
|
||||
case OB_CURVES_LEGACY:
|
||||
case OB_SURF:
|
||||
case OB_FONT:
|
||||
return DRW_curve_material_count_get(static_cast<const Curve *>(ob->data));
|
||||
case OB_CURVES:
|
||||
return DRW_curves_material_count_get(static_cast<const Curves *>(ob->data));
|
||||
case OB_POINTCLOUD:
|
||||
return DRW_pointcloud_material_count_get(static_cast<const PointCloud *>(ob->data));
|
||||
case OB_VOLUME:
|
||||
return DRW_volume_material_count_get(static_cast<const Volume *>(ob->data));
|
||||
default:
|
||||
BLI_assert(0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Span<blender::gpu::Batch *> DRW_cache_object_surface_material_get(
|
||||
Object *ob, const Span<const GPUMaterial *> materials)
|
||||
{
|
||||
|
||||
@@ -75,7 +75,6 @@ blender::gpu::Batch **GOO_cache_object_surface_material_get(Object *ob,
|
||||
GPUMaterial **gpumat_array,
|
||||
uint gpumat_array_len);
|
||||
blender::gpu::Batch *DRW_cache_object_face_wireframe_get(const Scene *scene, Object *ob);
|
||||
int DRW_cache_object_material_count_get(const Object *ob);
|
||||
|
||||
/**
|
||||
* Returns the vertbuf used by shaded surface batch.
|
||||
|
||||
Reference in New Issue
Block a user