Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2015-10-12 13:15:05 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2015-10-12 13:15:05 +0300
commit07332dd2bbe62506bef89ffad22ad01766922c8e (patch)
tree274cffe797a273d9ab24834aeefcb8757d1ec7bc /source/blender/blenloader/intern/readblenentry.c
parent9cea429f787727d8a19b9dfe179a5b7ba2d92fd0 (diff)
Fix T34446: Make Local on linked mesh object: object gets removed if redo function is used.
Root of the issue is that we do not re-read lib data blocks and ID placholders (ID_ID bheads) in undo context (in `blo_read_file_internal`), because `BLO_read_from_memfile` copies lib datablocks and Main data directly from oldmain. The idea being, linked data do not change from undo/redo. This is valid as long as linked data was not changed by the undo step - but if some was deleted or localized, it will be missing from oldmain, leading to data loss (note that does not only concern objects, all linkable data types can be affected, at least in theory). This commit addresses that issue by carefully mixing reuse of needed data from oldmain, and "normal" re-reading of missing one. Makes us swimming in some rather dark waters, and gives a rather non-easy-to-follow code, but it seems to work quite well, and only other solution would be to get rid of that optimization (not re-reading all libs on undo/redo), which is not acceptable. Also, thanks to @carlosdp for initial investigation of the issue. Differential Revision: https://developer.blender.org/D1485
Diffstat (limited to 'source/blender/blenloader/intern/readblenentry.c')
-rw-r--r--source/blender/blenloader/intern/readblenentry.c55
1 files changed, 40 insertions, 15 deletions
diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c
index e8d7a46687f..6132a091116 100644
--- a/source/blender/blenloader/intern/readblenentry.c
+++ b/source/blender/blenloader/intern/readblenentry.c
@@ -303,7 +303,7 @@ BlendFileData *BLO_read_from_memfile(Main *oldmain, const char *filename, MemFil
{
BlendFileData *bfd = NULL;
FileData *fd;
- ListBase mainlist;
+ ListBase old_mainlist;
fd = blo_openblendermemfile(memfile, reports);
if (fd) {
@@ -314,9 +314,9 @@ BlendFileData *BLO_read_from_memfile(Main *oldmain, const char *filename, MemFil
blo_clear_proxy_pointers_from_lib(oldmain);
/* separate libraries from old main */
- blo_split_main(&mainlist, oldmain);
+ blo_split_main(&old_mainlist, oldmain);
/* add the library pointers in oldmap lookup */
- blo_add_library_pointer_map(&mainlist, fd);
+ blo_add_library_pointer_map(&old_mainlist, fd);
/* makes lookup of existing images in old main */
blo_make_image_pointer_map(fd, oldmain);
@@ -340,19 +340,44 @@ BlendFileData *BLO_read_from_memfile(Main *oldmain, const char *filename, MemFil
/* ensures relinked sounds are not freed */
blo_end_sound_pointer_map(fd, oldmain);
- /* move libraries from old main to new main */
- if (bfd && mainlist.first != mainlist.last) {
-
- /* Library structs themselves */
- bfd->main->library = oldmain->library;
- BLI_listbase_clear(&oldmain->library);
-
- /* add the Library mainlist to the new main */
- BLI_remlink(&mainlist, oldmain);
- BLI_addhead(&mainlist, bfd->main);
+ /* Still in-use libraries have already been moved from oldmain to new mainlist,
+ * but oldmain itself shall *never* be 'transferred' to new mainlist! */
+ BLI_assert(old_mainlist.first == oldmain);
+
+ if (bfd && old_mainlist.first != old_mainlist.last) {
+ /* Even though directly used libs have been already moved to new main, indirect ones have not.
+ * This is a bit annoying, but we have no choice but to keep them all for now - means some now unused
+ * data may remain in memory, but think we'll have to live with it. */
+ Main *libmain;
+ Main *newmain = bfd->main;
+ ListBase new_mainlist = {newmain, newmain};
+
+ for (libmain = oldmain->next; libmain; libmain = libmain->next) {
+ /* Note that LIB_INDIRECT does not work with libraries themselves, so we use non-NULL parent
+ * to detect indirect-linked ones... */
+ if (libmain->curlib && (libmain->curlib->parent != NULL)) {
+ BLI_remlink(&old_mainlist, libmain);
+ BLI_addtail(&new_mainlist, libmain);
+ }
+#if 0
+ else {
+ printf("Dropped Main for lib: %s\n", libmain->curlib->id.name);
+ }
+#endif
+ }
+ /* In any case, we need to move all lib datablocks themselves - those are 'first level data',
+ * getting rid of them would imply updating spaces & co to prevent invalid pointers access. */
+ BLI_movelisttolist(&newmain->library, &oldmain->library);
+
+ blo_join_main(&new_mainlist);
}
- blo_join_main(&mainlist);
-
+
+ /* printf("Remaining mains/libs in oldmain: %d\n", BLI_listbase_count(&fd->old_mainlist) - 1); */
+
+ /* That way, libs (aka mains) we did not reuse in new undone/redone state
+ * will be cleared together with oldmain... */
+ blo_join_main(&old_mainlist);
+
blo_freefiledata(fd);
}