Fix T60261: Crash pasting a material without a nodetree
authorPhilipp Oeser <info@graphics-engineer.com>
Wed, 16 Jan 2019 21:59:02 +0000 (08:59 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 16 Jan 2019 21:59:02 +0000 (08:59 +1100)
source/blender/blenkernel/intern/material.c
source/blender/editors/render/render_shading.c

index 913bc9c47e6f5540cd61404a8c22475042b44a1a..fc03116de204a44841a63587ed99b15e5d3fe311 100644 (file)
@@ -1399,7 +1399,10 @@ void copy_matcopybuf(Main *bmain, Material *ma)
 
        memcpy(&matcopybuf, ma, sizeof(Material));
 
-       matcopybuf.nodetree = ntreeCopyTree_ex(ma->nodetree, bmain, false);
+       if (ma->nodetree != NULL) {
+               matcopybuf.nodetree = ntreeCopyTree_ex(ma->nodetree, bmain, false);
+       }
+
        matcopybuf.preview = NULL;
        BLI_listbase_clear(&matcopybuf.gpumaterial);
        /* TODO Duplicate Engine Settings and set runtime to NULL */
@@ -1425,7 +1428,9 @@ void paste_matcopybuf(Main *bmain, Material *ma)
        memcpy(ma, &matcopybuf, sizeof(Material));
        (ma->id) = id;
 
-       ma->nodetree = ntreeCopyTree_ex(matcopybuf.nodetree, bmain, false);
+       if (matcopybuf.nodetree != NULL) {
+               ma->nodetree = ntreeCopyTree_ex(matcopybuf.nodetree, bmain, false);
+       }
 }
 
 void BKE_material_eval(struct Depsgraph *depsgraph, Material *material)
index 587d2d91029f0f575e9a95edea593ba130b93ad7..bc92a45391c7d4e6cbbd0b47a49272cd1628eb38 100644 (file)
@@ -1782,6 +1782,7 @@ static int paste_material_exec(bContext *C, wmOperator *UNUSED(op))
 
        paste_matcopybuf(CTX_data_main(C), ma);
 
+       DEG_id_tag_update(&ma->id, ID_RECALC_COPY_ON_WRITE);
        WM_event_add_notifier(C, NC_MATERIAL | ND_SHADING_LINKS, ma);
 
        return OPERATOR_FINISHED;