Fix new material for pinned objects
authorCampbell Barton <ideasman42@gmail.com>
Thu, 3 Jan 2019 01:33:12 +0000 (12:33 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 3 Jan 2019 01:34:31 +0000 (12:34 +1100)
Grease pencil check was using active object.

source/blender/editors/render/render_shading.c

index 6875c803c33b1241551af738a379599f0b349d61..f2446a01ecf142b60036823627ba23d5dd00ba12 100644 (file)
@@ -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);
                        }