From d788f5231e81ae2be363f877d04ab93ddc396fa6 Mon Sep 17 00:00:00 2001 From: Antonioya Date: Wed, 12 Jun 2019 15:51:51 +0200 Subject: Fix T65741: Removing a GPencil Object's Material Slot deletes the strokes assigned to it This was a design decision, but now we have decided to change it using the active material for the strokes using deleted material. If the material slot is empty a new material is created to keep the strokes visible. --- source/blender/blenkernel/intern/material.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'source/blender/blenkernel/intern/material.c') diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 1e5a2d53bfa..e845271d802 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -361,9 +361,6 @@ static void material_data_index_remove_id(ID *id, short index) case ID_MB: /* meta-elems don't have materials atm */ break; - case ID_GD: - BKE_gpencil_material_index_remove((bGPdata *)id, index); - break; default: break; } @@ -1050,12 +1047,20 @@ bool BKE_object_material_slot_remove(Main *bmain, Object *ob) } /* check indices from mesh */ - if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_GPENCIL)) { + if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT)) { material_data_index_remove_id((ID *)ob->data, actcol - 1); if (ob->runtime.curve_cache) { BKE_displist_free(&ob->runtime.curve_cache->disp); } } + /* check indices from gpencil */ + else if (ob->type == OB_GPENCIL) { + /* need one color */ + if (ob->totcol == 0) { + BKE_gpencil_object_material_ensure_from_active_input_material(bmain, ob); + } + BKE_gpencil_material_index_reassign((bGPdata *)ob->data, ob->totcol, actcol - 1); + } return true; } -- cgit v1.2.3