Fix #35122: Blenderplayer crashes when loading level

Issue was caused by ntreeUpdateTree calling for a ntree
which is not in G.main.

This lead to issues in ntreeVerifyNodes (which is called
from ntreeUpdateTree).

Made is so ntreeUpdateTree now accepts main as an argument.
Will work for the release, later we could either solve the
TODO mentioned in ntreeUpdateTree which will eliminate need
in main there or make it so context's main is used from all
over where ntreeUpdateTree is called (currently there're
still some usages of G.main).
This commit is contained in:
Sergey Sharybin
2013-05-07 15:28:42 +00:00
parent c31ec62d2f
commit 5455928262
10 changed files with 64 additions and 59 deletions

View File

@@ -358,7 +358,7 @@ struct bNodeTree *ntreeFromID(struct ID *id);
void ntreeMakeLocal(struct bNodeTree *ntree);
int ntreeHasType(struct bNodeTree *ntree, int type);
void ntreeUpdateTree(struct bNodeTree *ntree);
void ntreeUpdateTree(struct Main *main, struct bNodeTree *ntree);
/* XXX Currently each tree update call does call to ntreeVerifyNodes too.
* Some day this should be replaced by a decent depsgraph automatism!
*/

View File

@@ -2848,7 +2848,7 @@ void ntreeVerifyNodes(struct Main *main, struct ID *id)
} FOREACH_NODETREE_END
}
void ntreeUpdateTree(bNodeTree *ntree)
void ntreeUpdateTree(Main *bmain, bNodeTree *ntree)
{
bNode *node;
@@ -2886,8 +2886,8 @@ void ntreeUpdateTree(bNodeTree *ntree)
ntreeInterfaceTypeUpdate(ntree);
/* XXX hack, should be done by depsgraph!! */
if (G.main)
ntreeVerifyNodes(G.main, &ntree->id);
if (bmain)
ntreeVerifyNodes(bmain, &ntree->id);
if (ntree->update & (NTREE_UPDATE_LINKS | NTREE_UPDATE_NODES)) {
/* node updates can change sockets or links, repeat link pointer update afterward */

View File

@@ -2579,7 +2579,7 @@ static void lib_verify_nodetree(Main *main, int UNUSED(open))
{
FOREACH_NODETREE(main, ntree, id) {
/* make an update call for the tree */
ntreeUpdateTree(ntree);
ntreeUpdateTree(main, ntree);
} FOREACH_NODETREE_END
}
}

View File

@@ -93,7 +93,7 @@ bNode *node_add_node(const bContext *C, const char *idname, int type, float locx
node->locx = locx;
node->locy = locy + 60.0f;
ntreeUpdateTree(snode->edittree);
ntreeUpdateTree(bmain, snode->edittree);
ED_node_set_active(bmain, snode->edittree, node);
if (snode->nodetree->type == NTREE_COMPOSIT) {
@@ -285,7 +285,7 @@ static int add_reroute_exec(bContext *C, wmOperator *op)
BLI_freelistN(&input_links);
/* always last */
ntreeUpdateTree(ntree);
ntreeUpdateTree(CTX_data_main(C), ntree);
snode_notify(C, snode);
snode_dag_update(C, snode);

View File

@@ -474,7 +474,7 @@ void ED_node_shader_default(const bContext *C, ID *id)
}
}
ntreeUpdateTree(ntree);
ntreeUpdateTree(CTX_data_main(C), ntree);
}
/* assumes nothing being done in ntree yet, sets the default in/out node */
@@ -513,7 +513,7 @@ void ED_node_composit_default(const bContext *C, struct Scene *sce)
tosock = out->inputs.first;
nodeAddLink(sce->nodetree, in, fromsock, out, tosock);
ntreeUpdateTree(sce->nodetree);
ntreeUpdateTree(CTX_data_main(C), sce->nodetree);
// XXX ntreeCompositForceHidden(sce->nodetree);
}
@@ -545,7 +545,7 @@ void ED_node_texture_default(const bContext *C, Tex *tx)
tosock = out->inputs.first;
nodeAddLink(tx->nodetree, in, fromsock, out, tosock);
ntreeUpdateTree(tx->nodetree);
ntreeUpdateTree(CTX_data_main(C), tx->nodetree);
}
/* Here we set the active tree(s), even called for each redraw now, so keep it fast :) */
@@ -1222,7 +1222,7 @@ static int node_duplicate_exec(bContext *C, wmOperator *op)
break;
}
ntreeUpdateTree(snode->edittree);
ntreeUpdateTree(CTX_data_main(C), snode->edittree);
snode_notify(C, snode);
snode_dag_update(C, snode);
@@ -1557,7 +1557,7 @@ static int node_socket_toggle_exec(bContext *C, wmOperator *UNUSED(op))
}
}
ntreeUpdateTree(snode->edittree);
ntreeUpdateTree(CTX_data_main(C), snode->edittree);
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL);
@@ -1636,7 +1636,7 @@ static int node_delete_exec(bContext *C, wmOperator *UNUSED(op))
}
}
ntreeUpdateTree(snode->edittree);
ntreeUpdateTree(CTX_data_main(C), snode->edittree);
snode_notify(C, snode);
snode_dag_update(C, snode);
@@ -1679,7 +1679,7 @@ static int node_delete_reconnect_exec(bContext *C, wmOperator *UNUSED(op))
}
}
ntreeUpdateTree(snode->edittree);
ntreeUpdateTree(CTX_data_main(C), snode->edittree);
snode_notify(C, snode);
snode_dag_update(C, snode);
@@ -2071,7 +2071,7 @@ static int node_clipboard_paste_exec(bContext *C, wmOperator *op)
link->tonode->new_node, link->tosock->new_sock);
}
ntreeUpdateTree(snode->edittree);
ntreeUpdateTree(CTX_data_main(C), snode->edittree);
snode_notify(C, snode);
snode_dag_update(C, snode);
@@ -2156,7 +2156,7 @@ static int ntree_socket_add_exec(bContext *C, wmOperator *op)
/* make the new socket active */
sock->flag |= SELECT;
ntreeUpdateTree(ntree);
ntreeUpdateTree(CTX_data_main(C), ntree);
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL);
@@ -2202,7 +2202,7 @@ static int ntree_socket_remove_exec(bContext *C, wmOperator *UNUSED(op))
if (active_sock)
active_sock->flag |= SELECT;
ntreeUpdateTree(ntree);
ntreeUpdateTree(CTX_data_main(C), ntree);
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL);
@@ -2270,7 +2270,7 @@ static int ntree_socket_move_exec(bContext *C, wmOperator *op)
}
}
ntreeUpdateTree(ntree);
ntreeUpdateTree(CTX_data_main(C), ntree);
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL);

View File

@@ -363,7 +363,7 @@ static int node_group_ungroup_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
if (gnode->id && node_group_ungroup(snode->edittree, gnode)) {
ntreeUpdateTree(snode->nodetree);
ntreeUpdateTree(CTX_data_main(C), snode->nodetree);
}
else {
BKE_report(op->reports, RPT_WARNING, "Cannot ungroup");
@@ -556,7 +556,7 @@ static int node_group_separate_exec(bContext *C, wmOperator *op)
/* switch to parent tree */
ED_node_tree_pop(snode);
ntreeUpdateTree(snode->nodetree);
ntreeUpdateTree(CTX_data_main(C), snode->nodetree);
snode_notify(C, snode);
snode_dag_update(C, snode);
@@ -917,6 +917,7 @@ static int node_group_make_exec(bContext *C, wmOperator *op)
const char *node_idname = group_node_idname(C);
bNodeTree *ngroup;
bNode *gnode;
Main *bmain = CTX_data_main(C);
ED_preview_kill_jobs(C);
@@ -931,11 +932,11 @@ static int node_group_make_exec(bContext *C, wmOperator *op)
nodeSetActive(ntree, gnode);
if (ngroup) {
ED_node_tree_push(snode, ngroup, gnode);
ntreeUpdateTree(ngroup);
ntreeUpdateTree(bmain, ngroup);
}
}
ntreeUpdateTree(ntree);
ntreeUpdateTree(bmain, ntree);
snode_notify(C, snode);
snode_dag_update(C, snode);
@@ -967,6 +968,7 @@ static int node_group_insert_exec(bContext *C, wmOperator *op)
bNodeTree *ngroup;
const char *node_idname = group_node_idname(C);
bNode *gnode;
Main *bmain = CTX_data_main(C);
ED_preview_kill_jobs(C);
@@ -983,9 +985,9 @@ static int node_group_insert_exec(bContext *C, wmOperator *op)
nodeSetActive(ntree, gnode);
ED_node_tree_push(snode, ngroup, gnode);
ntreeUpdateTree(ngroup);
ntreeUpdateTree(bmain, ngroup);
ntreeUpdateTree(ntree);
ntreeUpdateTree(bmain, ntree);
snode_notify(C, snode);
snode_dag_update(C, snode);

View File

@@ -38,6 +38,7 @@
#include "BLI_blenlib.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_node.h"
@@ -173,7 +174,7 @@ static int snode_autoconnect_input(SpaceNode *snode, bNode *node_fr, bNodeSocket
link = nodeAddLink(ntree, node_fr, sock_fr, node_to, sock_to);
/* validate the new link */
ntreeUpdateTree(ntree);
ntreeUpdateTree(G.main, ntree);
if (!(link->flag & NODE_LINK_VALID)) {
nodeRemLink(ntree, link);
return 0;
@@ -256,7 +257,7 @@ static void snode_autoconnect(SpaceNode *snode, int allow_multiple, int replace)
}
if (numlinks > 0) {
ntreeUpdateTree(ntree);
ntreeUpdateTree(G.main, ntree);
}
BLI_freelistN(nodelist);
@@ -347,7 +348,7 @@ static int node_link_viewer(const bContext *C, bNode *tonode)
/* make sure the dependency sorting is updated */
snode->edittree->update |= NTREE_UPDATE_LINKS;
}
ntreeUpdateTree(snode->edittree);
ntreeUpdateTree(CTX_data_main(C), snode->edittree);
snode_update(snode, node);
}
@@ -532,7 +533,7 @@ static int node_link_modal(bContext *C, wmOperator *op, const wmEvent *event)
nodeRemLink(ntree, link);
}
ntreeUpdateTree(ntree);
ntreeUpdateTree(CTX_data_main(C), ntree);
snode_notify(C, snode);
snode_dag_update(C, snode);
@@ -714,7 +715,7 @@ static int node_make_link_exec(bContext *C, wmOperator *op)
node_deselect_all_input_sockets(snode, 0);
node_deselect_all_output_sockets(snode, 0);
ntreeUpdateTree(snode->edittree);
ntreeUpdateTree(CTX_data_main(C), snode->edittree);
snode_notify(C, snode);
snode_dag_update(C, snode);
@@ -797,7 +798,7 @@ static int cut_links_exec(bContext *C, wmOperator *op)
}
if (found) {
ntreeUpdateTree(snode->edittree);
ntreeUpdateTree(CTX_data_main(C), snode->edittree);
snode_notify(C, snode);
snode_dag_update(C, snode);
@@ -852,7 +853,7 @@ static int detach_links_exec(bContext *C, wmOperator *UNUSED(op))
}
}
ntreeUpdateTree(ntree);
ntreeUpdateTree(CTX_data_main(C), ntree);
snode_notify(C, snode);
snode_dag_update(C, snode);
@@ -881,7 +882,7 @@ static int node_show_cycles_exec(bContext *C, wmOperator *UNUSED(op))
SpaceNode *snode = CTX_wm_space_node(C);
/* this is just a wrapper around this call... */
ntreeUpdateTree(snode->nodetree);
ntreeUpdateTree(CTX_data_main(C), snode->nodetree);
snode_notify(C, snode);
return OPERATOR_FINISHED;
@@ -1361,7 +1362,7 @@ void ED_node_link_insert(ScrArea *sa)
nodeAddLink(snode->edittree, select, best_output, node, sockto);
ntreeUpdateTree(snode->edittree); /* needed for pointers */
ntreeUpdateTree(G.main, snode->edittree); /* needed for pointers */
snode_update(snode, select);
ED_node_tag_update_id(snode->id);
}

View File

@@ -38,6 +38,7 @@
#include "BLF_translation.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_scene.h"
@@ -85,7 +86,7 @@ static void node_link_item_apply(bNode *node, NodeLinkItem *item)
{
if (node->type == NODE_GROUP) {
node->id = (ID *)item->ngroup;
ntreeUpdateTree(item->ngroup);
ntreeUpdateTree(G.main, item->ngroup);
}
else {
/* nothing to do for now */
@@ -166,7 +167,7 @@ static void node_socket_disconnect(Main *bmain, bNodeTree *ntree, bNode *node_to
sock_to->flag |= SOCK_COLLAPSED;
nodeUpdate(ntree, node_to);
ntreeUpdateTree(ntree);
ntreeUpdateTree(bmain, ntree);
ED_node_tag_update_nodetree(bmain, ntree);
}
@@ -181,7 +182,7 @@ static void node_socket_remove(Main *bmain, bNodeTree *ntree, bNode *node_to, bN
sock_to->flag |= SOCK_COLLAPSED;
nodeUpdate(ntree, node_to);
ntreeUpdateTree(ntree);
ntreeUpdateTree(bmain, ntree);
ED_node_tag_update_nodetree(bmain, ntree);
}
@@ -267,7 +268,7 @@ static void node_socket_add_replace(const bContext *C, bNodeTree *ntree, bNode *
nodeUpdate(ntree, node_from);
nodeUpdate(ntree, node_to);
ntreeUpdateTree(ntree);
ntreeUpdateTree(CTX_data_main(C), ntree);
ED_node_tag_update_nodetree(CTX_data_main(C), ntree);
}

View File

@@ -741,7 +741,7 @@ static bNode *rna_NodeTree_node_new(bNodeTree *ntree, bContext *C, ReportList *r
ntreeTexCheckCyclics(ntree);
}
ntreeUpdateTree(ntree);
ntreeUpdateTree(CTX_data_main(C), ntree);
nodeUpdate(ntree, node);
WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
@@ -764,7 +764,7 @@ static void rna_NodeTree_node_remove(bNodeTree *ntree, ReportList *reports, Poin
nodeFreeNode(ntree, node);
RNA_POINTER_INVALIDATE(node_ptr);
ntreeUpdateTree(ntree); /* update group node socket links */
ntreeUpdateTree(G.main, ntree); /* update group node socket links */
WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
}
@@ -786,7 +786,7 @@ static void rna_NodeTree_node_clear(bNodeTree *ntree, ReportList *reports)
node = next_node;
}
ntreeUpdateTree(ntree);
ntreeUpdateTree(G.main, ntree);
WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
}
@@ -841,7 +841,7 @@ static bNodeLink *rna_NodeTree_link_new(bNodeTree *ntree, ReportList *reports,
if (tonode)
nodeUpdate(ntree, tonode);
ntreeUpdateTree(ntree);
ntreeUpdateTree(G.main, ntree);
WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
}
@@ -863,7 +863,7 @@ static void rna_NodeTree_link_remove(bNodeTree *ntree, ReportList *reports, Poin
nodeRemLink(ntree, link);
RNA_POINTER_INVALIDATE(link_ptr);
ntreeUpdateTree(ntree);
ntreeUpdateTree(G.main, ntree);
WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
}
@@ -881,7 +881,7 @@ static void rna_NodeTree_link_clear(bNodeTree *ntree, ReportList *reports)
link = next_link;
}
ntreeUpdateTree(ntree);
ntreeUpdateTree(G.main, ntree);
WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
}
@@ -969,7 +969,7 @@ static bNodeSocket *rna_NodeTree_inputs_new(bNodeTree *ntree, ReportList *report
sock = ntreeAddSocketInterface(ntree, SOCK_IN, type, name);
ntreeUpdateTree(ntree);
ntreeUpdateTree(G.main, ntree);
WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
return sock;
@@ -984,7 +984,7 @@ static bNodeSocket *rna_NodeTree_outputs_new(bNodeTree *ntree, ReportList *repor
sock = ntreeAddSocketInterface(ntree, SOCK_OUT, type, name);
ntreeUpdateTree(ntree);
ntreeUpdateTree(G.main, ntree);
WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
return sock;
@@ -1001,7 +1001,7 @@ static void rna_NodeTree_socket_remove(bNodeTree *ntree, ReportList *reports, bN
else {
ntreeRemoveSocketInterface(ntree, sock);
ntreeUpdateTree(ntree);
ntreeUpdateTree(G.main, ntree);
WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
}
}
@@ -1018,7 +1018,7 @@ static void rna_NodeTree_inputs_clear(bNodeTree *ntree, ReportList *reports)
ntreeRemoveSocketInterface(ntree, sock);
}
ntreeUpdateTree(ntree);
ntreeUpdateTree(G.main, ntree);
WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
}
@@ -1034,14 +1034,14 @@ static void rna_NodeTree_outputs_clear(bNodeTree *ntree, ReportList *reports)
ntreeRemoveSocketInterface(ntree, sock);
}
ntreeUpdateTree(ntree);
ntreeUpdateTree(G.main, ntree);
WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
}
static void rna_NodeTree_interface_update(bNodeTree *ntree, bContext *C)
{
ntree->update |= NTREE_UPDATE_GROUP;
ntreeUpdateTree(ntree);
ntreeUpdateTree(G.main, ntree);
ED_node_tag_update_nodetree(CTX_data_main(C), ntree);
}
@@ -1543,7 +1543,7 @@ static bNodeSocket *rna_Node_inputs_new(ID *id, bNode *node, ReportList *reports
BKE_report(reports, RPT_ERROR, "Unable to create socket");
}
else {
ntreeUpdateTree(ntree);
ntreeUpdateTree(G.main, ntree);
WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
}
@@ -1561,7 +1561,7 @@ static bNodeSocket *rna_Node_outputs_new(ID *id, bNode *node, ReportList *report
BKE_reportf(reports, RPT_ERROR, "Unable to create socket");
}
else {
ntreeUpdateTree(ntree);
ntreeUpdateTree(G.main, ntree);
WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
}
@@ -1578,7 +1578,7 @@ static void rna_Node_socket_remove(ID *id, bNode *node, ReportList *reports, bNo
else {
nodeRemoveSocket(ntree, node, sock);
ntreeUpdateTree(ntree);
ntreeUpdateTree(G.main, ntree);
WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
}
}
@@ -1593,7 +1593,7 @@ static void rna_Node_inputs_clear(ID *id, bNode *node)
nodeRemoveSocket(ntree, node, sock);
}
ntreeUpdateTree(ntree);
ntreeUpdateTree(G.main, ntree);
WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
}
@@ -1607,7 +1607,7 @@ static void rna_Node_outputs_clear(ID *id, bNode *node)
nodeRemoveSocket(ntree, node, sock);
}
ntreeUpdateTree(ntree);
ntreeUpdateTree(G.main, ntree);
WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
}
@@ -1637,7 +1637,7 @@ static void rna_Node_inputs_move(ID *id, bNode *node, int from_index, int to_ind
}
}
ntreeUpdateTree(ntree);
ntreeUpdateTree(G.main, ntree);
WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
}
@@ -1667,7 +1667,7 @@ static void rna_Node_outputs_move(ID *id, bNode *node, int from_index, int to_in
}
}
ntreeUpdateTree(ntree);
ntreeUpdateTree(G.main, ntree);
WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
}
@@ -2120,7 +2120,7 @@ static void rna_NodeSocketInterface_update(Main *bmain, Scene *UNUSED(scene), Po
return;
ntree->update |= NTREE_UPDATE_GROUP;
ntreeUpdateTree(ntree);
ntreeUpdateTree(G.main, ntree);
ED_node_tag_update_nodetree(bmain, ntree);
}
@@ -2246,7 +2246,7 @@ static void rna_NodeGroup_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *
bNode *node = (bNode *)ptr->data;
if (node->id)
ntreeUpdateTree((bNodeTree *)node->id);
ntreeUpdateTree(bmain, (bNodeTree *)node->id);
ED_node_tag_update_nodetree(bmain, ntree);
}

View File

@@ -36,6 +36,7 @@
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BKE_global.h"
#include "BKE_node.h"
#include "MEM_guardedalloc.h"
@@ -157,7 +158,7 @@ bNodeTreeExec *ntree_exec_begin(bNodeExecContext *context, bNodeTree *ntree, bNo
int totnodes, n;
/* ensure all sock->link pointers and node levels are correct */
ntreeUpdateTree(ntree);
ntreeUpdateTree(G.main, ntree);
/* get a dependency-sorted list of nodes */
ntreeGetDependencyList(ntree, &nodelist, &totnodes);