diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-01-03 04:33:12 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-01-03 04:34:31 +0300 |
commit | 487df021982710bb0145b8efc0c10f88192dff45 (patch) | |
tree | 1a86dd7c698b2c3f50f5cfa2c0695183dd046acd | |
parent | ba9e10fd6a5b7052d25f34343b7b723d25a94490 (diff) |
Fix new material for pinned objects
Grease pencil check was using active object.
-rw-r--r-- | source/blender/editors/render/render_shading.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/source/blender/editors/render/render_shading.c b/source/blender/editors/render/render_shading.c index 6875c803c33..f2446a01ecf 100644 --- a/source/blender/editors/render/render_shading.c +++ b/source/blender/editors/render/render_shading.c @@ -526,30 +526,32 @@ static int new_material_exec(bContext *C, wmOperator *UNUSED(op)) PointerRNA ptr, idptr; PropertyRNA *prop; + /* hook into UI */ + UI_context_active_but_prop_get_templateID(C, &ptr, &prop); + + Object *ob = (prop && RNA_struct_is_a(ptr.type, &RNA_Object)) ? ptr.data : NULL; + /* add or copy material */ if (ma) { ma = BKE_material_copy(bmain, ma); } else { - Object *ob = CTX_data_active_object(C); - if ((!ob) || (ob->type != OB_GPENCIL)) { - ma = BKE_material_add(bmain, DATA_("Material")); + const char *name = DATA_("Material"); + if (!(ob != NULL && ob->type == OB_GPENCIL)) { + ma = BKE_material_add(bmain, name); } else { - ma = BKE_material_add_gpencil(bmain, DATA_("Material")); + ma = BKE_material_add_gpencil(bmain, name); } ED_node_shader_default(C, &ma->id); ma->use_nodes = true; } - /* hook into UI */ - UI_context_active_but_prop_get_templateID(C, &ptr, &prop); if (prop) { - if (RNA_struct_is_a(ptr.type, &RNA_Object)) { + if (ob != NULL) { /* Add slot follows user-preferences for creating new slots, * RNA pointer assignment doesn't, see: T60014. */ - Object *ob = ptr.data; if (give_current_material_p(ob, ob->actcol) == NULL) { BKE_object_material_slot_add(bmain, ob); } |