[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55478] trunk/blender/source/blender/ blenloader/intern: Fix for a node compatibility code bug ( reported by kopias in IRC).

Lukas Toenne lukas.toenne at googlemail.com
Thu Mar 21 19:33:38 CET 2013


Revision: 55478
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55478
Author:   lukastoenne
Date:     2013-03-21 18:33:38 +0000 (Thu, 21 Mar 2013)
Log Message:
-----------
Fix for a node compatibility code bug (reported by kopias in IRC). Compatibility data (links with NULL fromnode/tonode pointers) was created for all node trees in library data, including local scene/material/... trees, but on loading was only actually removed for node groups. Now cleans up all trees in the library to be sure, and only generate new compat data for actual group trees.

Modified Paths:
--------------
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/blenloader/intern/writefile.c

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2013-03-21 18:07:03 UTC (rev 55477)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2013-03-21 18:33:38 UTC (rev 55478)
@@ -2458,9 +2458,13 @@
 		 *
 		 * XXX this should actually be part of do_versions,
 		 * but needs valid typeinfo pointers to create interface nodes.
+		 *
+		 * Note: theoretically only needed in node groups (main->nodetree),
+		 * but due to a temporary bug such links could have been added in all trees,
+		 * so have to clean up all of them ...
 		 */
 		
-		for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next) {
+		FOREACH_NODETREE(main, ntree, id) {
 			if (ntree->flag & NTREE_DO_VERSIONS_CUSTOMNODES_GROUP) {
 				bNode *input_node = NULL, *output_node = NULL;
 				int num_inputs = 0, num_outputs = 0;
@@ -2540,6 +2544,7 @@
 				ntree->flag &= ~(NTREE_DO_VERSIONS_CUSTOMNODES_GROUP | NTREE_DO_VERSIONS_CUSTOMNODES_GROUP_CREATE_INTERFACE);
 			}
 		}
+		FOREACH_NODETREE_END
 	}
 	
 	/* verify all group user nodes */
@@ -9011,8 +9016,7 @@
 	
 	/* Set flag for delayed do_versions in lib_verify_nodetree. It needs valid typeinfo pointers ... */
 	{
-		bNodeTree *ntree;
-		for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next) {
+		FOREACH_NODETREE(main, ntree, id) {
 			/* XXX This should be kept without version check for now!
 			 * As long as USE_NODE_COMPAT_CUSTOMNODES is active, files will write links
 			 * to tree interface sockets for forward compatibility. These links need to be removed again
@@ -9027,6 +9031,7 @@
 			if (!MAIN_VERSION_ATLEAST(main, 266, 2))
 				ntree->flag |= NTREE_DO_VERSIONS_CUSTOMNODES_GROUP_CREATE_INTERFACE;
 		}
+		FOREACH_NODETREE_END
 	}
 
 	if (!MAIN_VERSION_ATLEAST(main, 266, 3)) {

Modified: trunk/blender/source/blender/blenloader/intern/writefile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/writefile.c	2013-03-21 18:07:03 UTC (rev 55477)
+++ trunk/blender/source/blender/blenloader/intern/writefile.c	2013-03-21 18:33:38 UTC (rev 55478)
@@ -2789,115 +2789,70 @@
 }
 
 #ifdef USE_NODE_COMPAT_CUSTOMNODES
-static void customnodes_add_deprecated_nodetree_data(bNodeTree *ntree)
+static void customnodes_add_deprecated_data(Main *mainvar)
 {
-	bNodeLink *link, *last_link = ntree->links.last;
-	/* Forward compatibility for group nodes: add links to node tree interface sockets.
-	 * These links are invalid by new rules (missing node pointer)!
-	 * They will be removed again in customnodes_free_deprecated_data,
-	 * cannot do this directly lest bNodeLink pointer mapping becomes ambiguous.
-	 * When loading files with such links in a new Blender version
-	 * they will be removed as well.
-	 */
-	for (link = ntree->links.first; link; link = link->next) {
-		bNode *fromnode = link->fromnode, *tonode = link->tonode;
-		bNodeSocket *fromsock = link->fromsock, *tosock = link->tosock;
+	FOREACH_NODETREE(mainvar, ntree, id) {
+		bNodeLink *link, *last_link = ntree->links.last;
 		
-		/* check both sides of the link, to handle direct input-to-output links */
-		if (fromnode->type == NODE_GROUP_INPUT) {
-			fromnode = NULL;
-			fromsock = ntreeFindSocketInterface(ntree, SOCK_IN, fromsock->identifier);
-		}
-		/* only the active output node defines links */
-		if (tonode->type == NODE_GROUP_OUTPUT && (tonode->flag & NODE_DO_OUTPUT)) {
-			tonode = NULL;
-			tosock = ntreeFindSocketInterface(ntree, SOCK_OUT, tosock->identifier);
-		}
+		/* only do this for node groups */
+		if (id != &ntree->id)
+			continue;
 		
-		if (!fromnode || !tonode) {
-			/* Note: not using nodeAddLink here, it asserts existing node pointers */
-			bNodeLink *tlink = MEM_callocN(sizeof(bNodeLink), "group node link");
-			tlink->fromnode = fromnode;
-			tlink->fromsock = fromsock;
-			tlink->tonode = tonode;
-			tlink->tosock= tosock;
-			tosock->link = tlink;
-			tlink->flag |= NODE_LINK_VALID;
-			BLI_addtail(&ntree->links, tlink);
+		/* Forward compatibility for group nodes: add links to node tree interface sockets.
+		 * These links are invalid by new rules (missing node pointer)!
+		 * They will be removed again in customnodes_free_deprecated_data,
+		 * cannot do this directly lest bNodeLink pointer mapping becomes ambiguous.
+		 * When loading files with such links in a new Blender version
+		 * they will be removed as well.
+		 */
+		for (link = ntree->links.first; link; link = link->next) {
+			bNode *fromnode = link->fromnode, *tonode = link->tonode;
+			bNodeSocket *fromsock = link->fromsock, *tosock = link->tosock;
+			
+			/* check both sides of the link, to handle direct input-to-output links */
+			if (fromnode->type == NODE_GROUP_INPUT) {
+				fromnode = NULL;
+				fromsock = ntreeFindSocketInterface(ntree, SOCK_IN, fromsock->identifier);
+			}
+			/* only the active output node defines links */
+			if (tonode->type == NODE_GROUP_OUTPUT && (tonode->flag & NODE_DO_OUTPUT)) {
+				tonode = NULL;
+				tosock = ntreeFindSocketInterface(ntree, SOCK_OUT, tosock->identifier);
+			}
+			
+			if (!fromnode || !tonode) {
+				/* Note: not using nodeAddLink here, it asserts existing node pointers */
+				bNodeLink *tlink = MEM_callocN(sizeof(bNodeLink), "group node link");
+				tlink->fromnode = fromnode;
+				tlink->fromsock = fromsock;
+				tlink->tonode = tonode;
+				tlink->tosock= tosock;
+				tosock->link = tlink;
+				tlink->flag |= NODE_LINK_VALID;
+				BLI_addtail(&ntree->links, tlink);
+			}
+			
+			/* don't check newly created compatibility links */
+			if (link == last_link)
+				break;
 		}
-		
-		/* don't check newly created compatibility links */
-		if (link == last_link)
-			break;
 	}
+	FOREACH_NODETREE_END
 }
 
-static void customnodes_add_deprecated_data(Main *mainvar)
+static void customnodes_free_deprecated_data(Main *mainvar)
 {
-	bNodeTree *ntree;
-	Scene *scene;
-	Material *mat;
-	World *world;
-	Lamp *lamp;
-	Tex *tex;
-	
-	for (ntree = mainvar->nodetree.first; ntree; ntree = ntree->id.next)
-		customnodes_add_deprecated_nodetree_data(ntree);
-	for (scene = mainvar->scene.first; scene; scene = scene->id.next)
-		if (scene->nodetree)
-			customnodes_add_deprecated_nodetree_data(scene->nodetree);
-	for (mat = mainvar->mat.first; mat; mat = mat->id.next)
-		if (mat->nodetree)
-			customnodes_add_deprecated_nodetree_data(mat->nodetree);
-	for (world = mainvar->world.first; world; world = world->id.next)
-		if (world->nodetree)
-			customnodes_add_deprecated_nodetree_data(world->nodetree);
-	for (lamp = mainvar->lamp.first; lamp; lamp = lamp->id.next)
-		if (lamp->nodetree)
-			customnodes_add_deprecated_nodetree_data(lamp->nodetree);
-	for (tex = mainvar->tex.first; tex; tex = tex->id.next)
-		if (tex->nodetree)
-			customnodes_add_deprecated_nodetree_data(tex->nodetree);
-}
-
-static void customnodes_free_deprecated_nodetree_data(bNodeTree *ntree)
-{
-	bNodeLink *link, *next_link;
-	
-	for (link = ntree->links.first; link; link = next_link) {
-		next_link = link->next;
-		if (link->fromnode == NULL || link->tonode == NULL)
-			nodeRemLink(ntree, link);
+	FOREACH_NODETREE(mainvar, ntree, id) {
+		bNodeLink *link, *next_link;
+		
+		for (link = ntree->links.first; link; link = next_link) {
+			next_link = link->next;
+			if (link->fromnode == NULL || link->tonode == NULL)
+				nodeRemLink(ntree, link);
+		}
 	}
+	FOREACH_NODETREE_END
 }
-
-static void customnodes_free_deprecated_data(Main *mainvar)
-{
-	bNodeTree *ntree;
-	Scene *scene;
-	Material *mat;
-	World *world;
-	Lamp *lamp;
-	Tex *tex;
-	
-	for (ntree = mainvar->nodetree.first; ntree; ntree = ntree->id.next)
-		customnodes_free_deprecated_nodetree_data(ntree);
-	for (scene = mainvar->scene.first; scene; scene = scene->id.next)
-		if (scene->nodetree)
-			customnodes_free_deprecated_nodetree_data(scene->nodetree);
-	for (mat = mainvar->mat.first; mat; mat = mat->id.next)
-		if (mat->nodetree)
-			customnodes_free_deprecated_nodetree_data(mat->nodetree);
-	for (world = mainvar->world.first; world; world = world->id.next)
-		if (world->nodetree)
-			customnodes_free_deprecated_nodetree_data(world->nodetree);
-	for (lamp = mainvar->lamp.first; lamp; lamp = lamp->id.next)
-		if (lamp->nodetree)
-			customnodes_free_deprecated_nodetree_data(lamp->nodetree);
-	for (tex = mainvar->tex.first; tex; tex = tex->id.next)
-		if (tex->nodetree)
-			customnodes_free_deprecated_nodetree_data(tex->nodetree);
-}
 #endif
 
 static void write_brushes(WriteData *wd, ListBase *idbase)




More information about the Bf-blender-cvs mailing list