Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/material.c
| Show First 20 Lines • Show All 1,393 Lines • ▼ Show 20 Lines | |||||
| void copy_matcopybuf(Main *bmain, Material *ma) | void copy_matcopybuf(Main *bmain, Material *ma) | ||||
| { | { | ||||
| if (matcopied) | if (matcopied) | ||||
| free_matcopybuf(); | free_matcopybuf(); | ||||
| memcpy(&matcopybuf, ma, sizeof(Material)); | memcpy(&matcopybuf, ma, sizeof(Material)); | ||||
| if (ma->nodetree) { | |||||
| matcopybuf.nodetree = ntreeCopyTree_ex(ma->nodetree, bmain, false); | matcopybuf.nodetree = ntreeCopyTree_ex(ma->nodetree, bmain, false); | ||||
| } | |||||
| else { | |||||
| matcopybuf.nodetree = NULL; | |||||
| } | |||||
brecht: `if (ma->nodetree)` seems better, no need to lose the node tree if it's there but unused. | |||||
brechtUnsubmitted Not Done Inline ActionsSetting matcopybuf.nodetree = NULL; is redundant, so could be left out. brecht: Setting `matcopybuf.nodetree = NULL;` is redundant, so could be left out. | |||||
| matcopybuf.preview = NULL; | matcopybuf.preview = NULL; | ||||
| BLI_listbase_clear(&matcopybuf.gpumaterial); | BLI_listbase_clear(&matcopybuf.gpumaterial); | ||||
| /* TODO Duplicate Engine Settings and set runtime to NULL */ | /* TODO Duplicate Engine Settings and set runtime to NULL */ | ||||
| matcopied = 1; | matcopied = 1; | ||||
| } | } | ||||
| void paste_matcopybuf(Main *bmain, Material *ma) | void paste_matcopybuf(Main *bmain, Material *ma) | ||||
| { | { | ||||
| Show All 9 Lines | if (ma->nodetree) { | ||||
| ntreeFreeNestedTree(ma->nodetree); | ntreeFreeNestedTree(ma->nodetree); | ||||
| MEM_freeN(ma->nodetree); | MEM_freeN(ma->nodetree); | ||||
| } | } | ||||
| id = (ma->id); | id = (ma->id); | ||||
| memcpy(ma, &matcopybuf, sizeof(Material)); | memcpy(ma, &matcopybuf, sizeof(Material)); | ||||
| (ma->id) = id; | (ma->id) = id; | ||||
| if (matcopybuf.nodetree) { | |||||
| ma->nodetree = ntreeCopyTree_ex(matcopybuf.nodetree, bmain, false); | ma->nodetree = ntreeCopyTree_ex(matcopybuf.nodetree, bmain, false); | ||||
| } | } | ||||
Not Done Inline ActionsThe same bug exists here. If matcopybuf.nodetree is NULL, then ntreeCopyTree_ex returns an uninitialized variable. To me it seems it's really BKE_id_copy_ex that should be fixed, since I can imagine similar bugs in other places. brecht: The same bug exists here. If `matcopybuf.nodetree` is `NULL`, then `ntreeCopyTree_ex` returns… | |||||
| } | |||||
| void BKE_material_eval(struct Depsgraph *depsgraph, Material *material) | void BKE_material_eval(struct Depsgraph *depsgraph, Material *material) | ||||
| { | { | ||||
| DEG_debug_print_eval(depsgraph, __func__, material->id.name, material); | DEG_debug_print_eval(depsgraph, __func__, material->id.name, material); | ||||
| GPU_material_free(&material->gpumaterial); | GPU_material_free(&material->gpumaterial); | ||||
| } | } | ||||
if (ma->nodetree) seems better, no need to lose the node tree if it's there but unused.