[Bf-blender-cvs] [e5fbeba] master: Images: Solve broken forward compatibility with packed images

Sergey Sharybin noreply at git.blender.org
Tue May 26 11:46:58 CEST 2015


Commit: e5fbeba0b3a6e9eea4a8747e97033bbd0d7f017b
Author: Sergey Sharybin
Date:   Tue May 26 14:43:50 2015 +0500
Branches: master
https://developer.blender.org/rBe5fbeba0b3a6e9eea4a8747e97033bbd0d7f017b

Images: Solve broken forward compatibility with packed images

Use first packed image as legacy image->packedfile, so saving .blend file with
latest builds makes it so packed images are not lost when opening with previous
releases.

This will only work reliably if mutliview is not used, otherwise it'll be only
first view in the .blend file, which is rather expected since previous releases
are not aware of views.

===================================================================

M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/makesdna/DNA_image_types.h

===================================================================

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index c736e54..a22e882 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -1536,9 +1536,6 @@ void blo_make_packed_pointer_map(FileData *fd, Main *oldmain)
 	
 	for (ima = oldmain->image.first; ima; ima = ima->id.next) {
 		ImagePackedFile *imapf;
-		if (ima->packedfile)
-			insert_packedmap(fd, ima->packedfile);
-
 		for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next)
 			if (imapf->packedfile)
 				insert_packedmap(fd, imapf->packedfile);
@@ -1577,8 +1574,6 @@ void blo_end_packed_pointer_map(FileData *fd, Main *oldmain)
 	
 	for (ima = oldmain->image.first; ima; ima = ima->id.next) {
 		ImagePackedFile *imapf;
-		ima->packedfile = newpackedadr(fd, ima->packedfile);
-
 		for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next)
 			imapf->packedfile = newpackedadr(fd, imapf->packedfile);
 	}
@@ -3437,6 +3432,7 @@ static void direct_link_image(FileData *fd, Image *ima)
 	link_list(fd, &(ima->views));
 	link_list(fd, &(ima->packedfiles));
 
+	ima->packedfile = NULL;
 	for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) {
 		imapf->packedfile = direct_link_packedfile(fd, imapf->packedfile);
 	}
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 43f9fcc..fc46471 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2161,6 +2161,13 @@ static void write_images(WriteData *wd, ListBase *idbase)
 	ima= idbase->first;
 	while (ima) {
 		if (ima->id.us>0 || wd->current) {
+			/* Some trickery to keep forward compatibility of packed images. */
+			BLI_assert(ima->packedfile == NULL);
+			if (ima->packedfiles.first != NULL) {
+				imapf = ima->packedfiles.first;
+				ima->packedfile = imapf->packedfile;
+			}
+
 			/* write LibData */
 			writestruct(wd, ID_IM, "Image", 1, ima);
 			if (ima->id.properties) IDP_WriteProperty(ima->id.properties, wd);
@@ -2179,6 +2186,8 @@ static void write_images(WriteData *wd, ListBase *idbase)
 			for (iv = ima->views.first; iv; iv = iv->next)
 				writestruct(wd, DATA, "ImageView", 1, iv);
 			writestruct(wd, DATA, "Stereo3dFormat", 1, ima->stereo3d_format);
+
+			ima->packedfile = NULL;
 		}
 		ima= ima->id.next;
 	}
diff --git a/source/blender/makesdna/DNA_image_types.h b/source/blender/makesdna/DNA_image_types.h
index da5eee0..0e2a41a 100644
--- a/source/blender/makesdna/DNA_image_types.h
+++ b/source/blender/makesdna/DNA_image_types.h
@@ -115,7 +115,7 @@ typedef struct Image {
 	unsigned int bindcode;	/* only for current image... */
 	unsigned int *repbind;	/* for repeat of parts of images */
 	
-	struct PackedFile *packedfile; /* deprecated */
+	struct PackedFile *packedfile DNA_DEPRECATED; /* deprecated */
 	struct ListBase packedfiles;
 	struct PreviewImage *preview;




More information about the Bf-blender-cvs mailing list