From 0f3515d4e2cdb4df68540e1dfd74b1dc9e1e821e Mon Sep 17 00:00:00 2001 From: Lukas Toenne Date: Tue, 19 Mar 2013 10:42:33 +0000 Subject: [PATCH] Fixes for context updates of the node editor: * If the node tree can be updated from context (tree has get_from_context callback defined), reset the pointers first to clear the editor path if no tree can be found. * Stupid mistake: snode->from != snode->from is always false. * Shader nodes context update: set the 'from' pointer to the active object, even if it doesn't have a material or node tree. --- source/blender/editors/space_node/node_edit.c | 10 ++++++++-- source/blender/nodes/shader/node_shader_tree.c | 3 +-- source/blender/nodes/texture/node_texture_tree.c | 10 ++++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index 256b02d3288..37b7b1cfd5f 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -530,11 +530,17 @@ void snode_set_context(const bContext *C) } if (!(snode->flag & SNODE_PIN) || ntree == NULL) { - if (treetype->get_from_context) + if (treetype->get_from_context) { + /* reset and update from context */ + ntree = NULL; + id = NULL; + from = NULL; + treetype->get_from_context(C, treetype, &ntree, &id, &from); + } } - if (snode->nodetree != ntree || snode->id != id || snode->from != snode->from) { + if (snode->nodetree != ntree || snode->id != id || snode->from != from) { ED_node_tree_start(snode, ntree, id, from); } } diff --git a/source/blender/nodes/shader/node_shader_tree.c b/source/blender/nodes/shader/node_shader_tree.c index 68846255983..8ea6a92a8b8 100644 --- a/source/blender/nodes/shader/node_shader_tree.c +++ b/source/blender/nodes/shader/node_shader_tree.c @@ -80,15 +80,14 @@ static void shader_get_from_context(const bContext *C, bNodeTreeType *UNUSED(tre if (snode->shaderfrom == SNODE_SHADER_OBJECT) { if (ob) { + *r_from = &ob->id; if (ob->type == OB_LAMP) { - *r_from = &ob->id; *r_id = ob->data; *r_ntree = ((Lamp *)ob->data)->nodetree; } else { Material *ma = give_current_material(ob, ob->actcol); if (ma) { - *r_from = &ob->id; *r_id = &ma->id; *r_ntree = ma->nodetree; } diff --git a/source/blender/nodes/texture/node_texture_tree.c b/source/blender/nodes/texture/node_texture_tree.c index e1a29a67446..4d67b36f9cc 100644 --- a/source/blender/nodes/texture/node_texture_tree.c +++ b/source/blender/nodes/texture/node_texture_tree.c @@ -83,11 +83,13 @@ static void texture_get_from_context(const bContext *C, bNodeTreeType *UNUSED(tr } } else if (snode->texfrom == SNODE_TEX_WORLD) { - tx = give_current_world_texture(scene->world); - if (tx) { + if (scene->world) { *r_from = (ID *)scene->world; - *r_id = &tx->id; - *r_ntree = tx->nodetree; + tx = give_current_world_texture(scene->world); + if (tx) { + *r_id = &tx->id; + *r_ntree = tx->nodetree; + } } } else {