From bda221ef2efec5583dfa47ec278b039387913ad5 Mon Sep 17 00:00:00 2001 From: YimingWu Date: Thu, 12 Dec 2024 17:04:21 +0100 Subject: [PATCH] Fix #131711: Grease Pencil: Null check when getting material passes The material returned by `BKE_object_material_get` could be nullptr when the material is somehow not a grease pencil material and this situation needs to be handled. This is likely caused by faulty file from previous verisons. Pull Request: https://projects.blender.org/blender/blender/pulls/131714 --- .../blender/modifiers/intern/MOD_grease_pencil_util.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index 651f0c399ad..c18eb6cfc25 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -190,12 +190,13 @@ void draw_custom_curve_settings(const bContext * /*C*/, uiLayout *layout, Pointe static Vector get_grease_pencil_material_passes(const Object *ob) { short *totcol = BKE_object_material_len_p(const_cast(ob)); - Vector result(*totcol); + Vector result(*totcol, 0); Material *ma = nullptr; for (short i = 0; i < *totcol; i++) { - ma = BKE_object_material_get(const_cast(ob), i + 1); - /* Pass index of the grease pencil material. */ - result[i] = ma->gp_style->index; + if (ma = BKE_object_material_get(const_cast(ob), i + 1)) { + /* Pass index of the grease pencil material. */ + result[i] = ma->gp_style->index; + } } return result; }