[Bf-blender-cvs] [302625eb37e] master: Fix (studio-reported) crash in readfile code.

Bastien Montagne noreply at git.blender.org
Mon Feb 8 15:59:35 CET 2021


Commit: 302625eb37e6df6a7a5a889c9dd7edbaa640e086
Author: Bastien Montagne
Date:   Thu Feb 4 15:21:29 2021 +0100
Branches: master
https://developer.blender.org/rB302625eb37e6df6a7a5a889c9dd7edbaa640e086

Fix (studio-reported) crash in readfile code.

Essentially, `lib_link_all` would perform some post-processing over data
in given `bmain` that **may** fail when not all data from all libraries
has been properly loaded yet.

This happens when `lib_link_all` is called from `read_libraries`, where
the bmains are split by libraries.

Now those post-processing is put into its own utils function, which
asserts that it is only called on a merged bmain.

Bonus point, this will avoid re-runing those not-so-cheap operations
more than once on the same data.

Reproducible in r1442 of Sprite repository when opening
`pro/animation_test/rex/performance/rex_crowdcamping/rex_crowdcamping.lighting.blend`

NOTE: Not so sure why we have to call `lib_link_all` several times (once
for each library, and then once on the whole merged bmain, including
local IDs then). So that it can get called for libs while we still have
that specific .blend file handle around?
In any case, the overhead here is minimal since we do ensure a data-block is
never lib-linked more than once, so this is not a serious concern right now.

Differential Revision: https://developer.blender.org/D10307

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

M	source/blender/blenloader/intern/readfile.c

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

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 89d4fe0b222..b86896b1a8e 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -3918,6 +3918,24 @@ static void lib_link_all(FileData *fd, Main *bmain)
   }
   FOREACH_MAIN_ID_END;
 
+#ifndef NDEBUG
+  /* Double check we do not have any 'need link' tag remaining, this should never be the case once
+   * this function has run. */
+  FOREACH_MAIN_ID_BEGIN (bmain, id) {
+    BLI_assert((id->tag & LIB_TAG_NEED_LINK) == 0);
+  }
+  FOREACH_MAIN_ID_END;
+#endif
+}
+
+/* Checks to perform after `lib_link_all`.
+ * Those operations cannot perfom properly in a split bmain case, since some data from other
+ * bmain's (aka libraries) may not have been processed yet. */
+static void after_liblink_merged_bmain_process(Main *bmain)
+{
+  /* We only expect a merged Main here, not a split one. */
+  BLI_assert((bmain->prev == NULL) && (bmain->next == NULL));
+
   /* Check for possible cycles in scenes' 'set' background property. */
   lib_link_scenes_check_set(bmain);
 
@@ -3928,15 +3946,6 @@ static void lib_link_all(FileData *fd, Main *bmain)
   /* We have to rebuild that runtime information *after* all data-blocks have been properly linked.
    */
   BKE_main_collections_parent_relations_rebuild(bmain);
-
-#ifndef NDEBUG
-  /* Double check we do not have any 'need link' tag remaining, this should never be the case once
-   * this function has run. */
-  FOREACH_MAIN_ID_BEGIN (bmain, id) {
-    BLI_assert((id->tag & LIB_TAG_NEED_LINK) == 0);
-  }
-  FOREACH_MAIN_ID_END;
-#endif
 }
 
 /** \} */
@@ -4159,6 +4168,7 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
     blo_join_main(&mainlist);
 
     lib_link_all(fd, bfd->main);
+    after_liblink_merged_bmain_process(bfd->main);
 
     /* Skip in undo case. */
     if (fd->memfile == NULL) {
@@ -5107,6 +5117,7 @@ static void library_link_end(Main *mainl,
   mainl = NULL; /* blo_join_main free's mainl, cant use anymore */
 
   lib_link_all(*fd, mainvar);
+  after_liblink_merged_bmain_process(mainvar);
 
   /* Some versioning code does expect some proper userrefcounting, e.g. in conversion from
    * groups to collections... We could optimize out that first call when we are reading a



More information about the Bf-blender-cvs mailing list