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
This commit is contained in:
Philipp Oeser 2020-06-29 12:43:54 +02:00
parent 9feb0d5f2e
commit 4fc5233467
Notes: blender-bot 2023-02-14 05:25:44 +01:00
Referenced by issue #78401, Convert Mesh to Grease Pencil with empty material slot crashes
1 changed files with 14 additions and 1 deletions

View File

@ -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;