Fix #127527: Crash drawing with non-GP material
It was possible for a Grease Pencil object to have a material with no Grease Pencil settings. This can lead to crashes in many places because it's often assumed that the material has these settings. The fix makes sure that `BKE_object_material_get` returns a Grease Pencil material when called on a Grease Pencil object. If the Grease Pencil settings don't exist, it returns `nullptr`. In the future, it should be possible to have these materials and code that reads from the settings should fall back to the default material. Pull Request: https://projects.blender.org/blender/blender/pulls/127570
This commit is contained in:
@@ -727,6 +727,14 @@ Material **BKE_object_material_get_p(Object *ob, short act)
|
||||
Material *BKE_object_material_get(Object *ob, short act)
|
||||
{
|
||||
Material **ma_p = BKE_object_material_get_p(ob, act);
|
||||
/* Grease Pencil objects currently make the assumption that the returned material has Grease
|
||||
* Pencil settings. Ensure that this is the case otherwise return `nullptr`. */
|
||||
if (ob->type == OB_GREASE_PENCIL && ma_p != nullptr) {
|
||||
Material *ma = *ma_p;
|
||||
if (ma != nullptr) {
|
||||
return ma->gp_style != nullptr ? ma : nullptr;
|
||||
}
|
||||
}
|
||||
return ma_p ? *ma_p : nullptr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user