[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [51535] trunk/blender/source/blender/ blenloader/intern/readfile.c: Fix for direct_link of local ID data blocks ( node trees in material/lamp/world/scene/texture).

Lukas Toenne lukas.toenne at googlemail.com
Tue Oct 23 14:38:47 CEST 2012


Revision: 51535
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=51535
Author:   lukastoenne
Date:     2012-10-23 12:38:47 +0000 (Tue, 23 Oct 2012)
Log Message:
-----------
Fix for direct_link of local ID data blocks (node trees in material/lamp/world/scene/texture). These data blocks also need to link the id properties group in their ID base, otherwise custom properties stored in such local node trees will lead to dangling pointers on file load.

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

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2012-10-23 12:25:08 UTC (rev 51534)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2012-10-23 12:38:47 UTC (rev 51535)
@@ -1631,6 +1631,19 @@
 {
 }
 
+/* ************ READ ID *************** */
+
+static void direct_link_id(FileData *fd, ID *id)
+{
+	/*link direct data of ID properties*/
+	if (id->properties) {
+		id->properties = newdataadr(fd, id->properties);
+		if (id->properties) { /* this case means the data was written incorrectly, it should not happen */
+			IDP_DirectLinkProperty(id->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
+		}
+	}
+}
+
 /* ************ READ CurveMapping *************** */
 
 /* cuma itself has been read! */
@@ -2712,8 +2725,10 @@
 		direct_link_curvemapping(fd, la->curfalloff);
 
 	la->nodetree= newdataadr(fd, la->nodetree);
-	if (la->nodetree)
+	if (la->nodetree) {
+		direct_link_id(fd, &la->nodetree->id);
 		direct_link_nodetree(fd, la->nodetree);
+	}
 	
 	la->preview = direct_link_preview_image(fd, la->preview);
 }
@@ -2879,8 +2894,10 @@
 	}
 	
 	wrld->nodetree = newdataadr(fd, wrld->nodetree);
-	if (wrld->nodetree)
+	if (wrld->nodetree) {
+		direct_link_id(fd, &wrld->nodetree->id);
 		direct_link_nodetree(fd, wrld->nodetree);
+	}
 	
 	wrld->preview = direct_link_preview_image(fd, wrld->preview);
 }
@@ -3187,8 +3204,10 @@
 	tex->ot = newdataadr(fd, tex->ot);
 	
 	tex->nodetree = newdataadr(fd, tex->nodetree);
-	if (tex->nodetree)
+	if (tex->nodetree) {
+		direct_link_id(fd, &tex->nodetree->id);
 		direct_link_nodetree(fd, tex->nodetree);
+	}
 	
 	tex->preview = direct_link_preview_image(fd, tex->preview);
 	
@@ -3247,8 +3266,10 @@
 	ma->ramp_spec = newdataadr(fd, ma->ramp_spec);
 	
 	ma->nodetree = newdataadr(fd, ma->nodetree);
-	if (ma->nodetree)
+	if (ma->nodetree) {
+		direct_link_id(fd, &ma->nodetree->id);
 		direct_link_nodetree(fd, ma->nodetree);
+	}
 	
 	ma->preview = direct_link_preview_image(fd, ma->preview);
 	ma->gpumaterial.first = ma->gpumaterial.last = NULL;
@@ -5079,8 +5100,10 @@
 	link_list(fd, &(sce->r.layers));
 	
 	sce->nodetree = newdataadr(fd, sce->nodetree);
-	if (sce->nodetree)
+	if (sce->nodetree) {
+		direct_link_id(fd, &sce->nodetree->id);
 		direct_link_nodetree(fd, sce->nodetree);
+	}
 
 	direct_link_view_settings(fd, &sce->view_settings);
 }
@@ -6450,6 +6473,8 @@
 	bhead = read_data_into_oldnewmap(fd, bhead, allocname);
 	
 	/* init pointers direct data */
+	direct_link_id(fd, id);
+	
 	switch (GS(id->name)) {
 		case ID_WM:
 			direct_link_windowmanager(fd, (wmWindowManager *)id);
@@ -6546,14 +6571,6 @@
 			break;
 	}
 	
-	/*link direct data of ID properties*/
-	if (id->properties) {
-		id->properties = newdataadr(fd, id->properties);
-		if (id->properties) { /* this case means the data was written incorrectly, it should not happen */
-			IDP_DirectLinkProperty(id->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
-		}
-	}
-	
 	oldnewmap_free_unused(fd->datamap);
 	oldnewmap_clear(fd->datamap);
 	




More information about the Bf-blender-cvs mailing list