diff options
author | Philipp Oeser <info@graphics-engineer.com> | 2020-06-29 13:43:54 +0300 |
---|---|---|
committer | Philipp Oeser <info@graphics-engineer.com> | 2020-06-29 15:23:10 +0300 |
commit | 4fc5233467b1c273cdb82b221d8faa53249b99c6 (patch) | |
tree | d36d78d670e0b1b18f845fd03691fcc4840f1673 /source/blender/blenkernel | |
parent | 9feb0d5f2eb87cc5f19b00c8928514e44edc4dde (diff) |
Fix T78401: Convert Mesh to Grease Pencil with empty material slot crashes
Also create the 'simple fill' in case there are only empty material
slots.
Maniphest Tasks: T78401
Differential Revision: https://developer.blender.org/D8151
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/intern/gpencil_geom.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/source/blender/blenkernel/intern/gpencil_geom.c b/source/blender/blenkernel/intern/gpencil_geom.c index 18c0848bad9..542f80aa9b5 100644 --- a/source/blender/blenkernel/intern/gpencil_geom.c +++ b/source/blender/blenkernel/intern/gpencil_geom.c @@ -1908,14 +1908,27 @@ void BKE_gpencil_convert_mesh(Main *bmain, /* Export faces as filled strokes. */ if (use_faces) { if (create_mat) { + /* Find a material slot with material assigned */ + bool material_found = false; + for (i = 0; i < ob_mesh->totcol; i++) { + Material *ma = BKE_object_material_get(ob_mesh, i + 1); + if (ma != NULL) { + material_found = true; + break; + } + } + /* If no materials, create a simple fill. */ - if (ob_mesh->totcol == 0) { + if (!material_found) { gpencil_add_material(bmain, ob_gp, "Fill", default_colors[1], false, true, &r_idx); } else { /* Create all materials for fill. */ for (i = 0; i < ob_mesh->totcol; i++) { Material *ma = BKE_object_material_get(ob_mesh, i + 1); + if (ma == NULL) { + continue; + } float color[4]; copy_v3_v3(color, &ma->r); color[3] = 1.0f; |