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 <bastien@blender.org>2022-07-28 17:26:02 +0300
committerBastien Montagne <bastien@blender.org>2022-07-28 17:29:57 +0300
commitea23e937cebdb85f096a9764749bfedbd31a45f6 (patch)
tree5bc5d48b52ba8dde05f753fa3e38ec4ab49b7a00 /source/blender/blenloader/intern/readfile.c
parentf3be8e66d79165a5f1949bb5d58f93fa3f2c4c50 (diff)
Cleanup/refactor: Readfile: Add dedicated function to insert ID pointers in libmap.
New `oldnewmap_lib_insert` does nothing special, it just wraps around existing `oldnewmap_insert`, but it's the logical counter part of `oldnewmap_liblookup`. It also helps tremendously when debuging complex ID pointers issues in readfile.c code.
Diffstat (limited to 'source/blender/blenloader/intern/readfile.c')
-rw-r--r--source/blender/blenloader/intern/readfile.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index ddb4ece1b07..e6e16019097 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -359,6 +359,12 @@ static void oldnewmap_insert(OldNewMap *onm, const void *oldaddr, void *newaddr,
oldnewmap_insert_or_replace(onm, entry);
}
+static void oldnewmap_lib_insert(
+ FileData *fd, const void *oldaddr, ID *newaddr, int nr)
+{
+ oldnewmap_insert(fd->libmap, oldaddr, newaddr, nr);
+}
+
void blo_do_versions_oldnewmap_insert(OldNewMap *onm, const void *oldaddr, void *newaddr, int nr)
{
oldnewmap_insert(onm, oldaddr, newaddr, nr);
@@ -1667,7 +1673,7 @@ void blo_add_library_pointer_map(ListBase *old_mainlist, FileData *fd)
int i = set_listbasepointers(ptr, lbarray);
while (i--) {
LISTBASE_FOREACH (ID *, id, lbarray[i]) {
- oldnewmap_insert(fd->libmap, id, id, GS(id->name));
+ oldnewmap_lib_insert(fd, id, id, GS(id->name));
}
}
}
@@ -3163,7 +3169,7 @@ static bool read_libblock_undo_restore_linked(FileData *fd, Main *main, const ID
/* Even though we found our linked ID, there is no guarantee its address
* is still the same. */
if (id_old != bhead->old) {
- oldnewmap_insert(fd->libmap, bhead->old, id_old, GS(id_old->name));
+ oldnewmap_lib_insert(fd, bhead->old, id_old, GS(id_old->name));
}
/* No need to do anything else for ID_LINK_PLACEHOLDER, it's assumed
@@ -3305,7 +3311,7 @@ static bool read_libblock_undo_restore(
/* Insert into library map for lookup by newly read datablocks (with pointer value bhead->old).
* Note that existing datablocks in memory (which pointer value would be id_old) are not
* remapped anymore, so no need to store this info here. */
- oldnewmap_insert(fd->libmap, bhead->old, id_old, bhead->code);
+ oldnewmap_lib_insert(fd, bhead->old, id_old, bhead->code);
*r_id_old = id_old;
return true;
@@ -3388,7 +3394,7 @@ static BHead *read_libblock(FileData *fd,
* Note that existing datablocks in memory (which pointer value would be id_old) are not remapped
* remapped anymore, so no need to store this info here. */
ID *id_target = id_old ? id_old : id;
- oldnewmap_insert(fd->libmap, bhead->old, id_target, bhead->code);
+ oldnewmap_lib_insert(fd, bhead->old, id_target, bhead->code);
if (r_id) {
*r_id = id_target;
@@ -4201,6 +4207,7 @@ static void expand_doit_library(void *fdhandle, Main *mainvar, void *old)
/* ID has not been read yet, add placeholder to the main of the
* library it belongs to, so that it will be read later. */
read_libblock(fd, libmain, bhead, fd->id_tag_extra | LIB_TAG_INDIRECT, false, &id);
+ BLI_assert(id != NULL);
id_sort_by_name(which_libbase(libmain, GS(id->name)), id, id->prev);
/* commented because this can print way too much */
@@ -4227,7 +4234,7 @@ static void expand_doit_library(void *fdhandle, Main *mainvar, void *old)
* (B) forest.blend: contains Forest collection linking in Tree from tree.blend.
* (C) shot.blend: links in both Tree from tree.blend and Forest from forest.blend.
*/
- oldnewmap_insert(fd->libmap, bhead->old, id, bhead->code);
+ oldnewmap_lib_insert(fd, bhead->old, id, bhead->code);
/* If "id" is a real data-block and not a placeholder, we need to
* update fd->libmap to replace ID_LINK_PLACEHOLDER with the real
@@ -4263,6 +4270,7 @@ static void expand_doit_library(void *fdhandle, Main *mainvar, void *old)
fd->id_tag_extra | LIB_TAG_NEED_EXPAND | LIB_TAG_INDIRECT,
false,
&id);
+ BLI_assert(id != NULL);
id_sort_by_name(which_libbase(mainvar, GS(id->name)), id, id->prev);
}
else {
@@ -4275,7 +4283,7 @@ static void expand_doit_library(void *fdhandle, Main *mainvar, void *old)
/* this is actually only needed on UI call? when ID was already read before,
* and another append happens which invokes same ID...
* in that case the lookup table needs this entry */
- oldnewmap_insert(fd->libmap, bhead->old, id, bhead->code);
+ oldnewmap_lib_insert(fd, bhead->old, id, bhead->code);
/* commented because this can print way too much */
// if (G.debug & G_DEBUG) printf("expand: already read %s\n", id->name);
}
@@ -4395,7 +4403,7 @@ static ID *link_named_part(
else {
/* already linked */
CLOG_WARN(&LOG, "Append: ID '%s' is already linked", id->name);
- oldnewmap_insert(fd->libmap, bhead->old, id, bhead->code);
+ oldnewmap_lib_insert(fd, bhead->old, id, bhead->code);
if (!force_indirect && (id->tag & LIB_TAG_INDIRECT)) {
id->tag &= ~LIB_TAG_INDIRECT;
id->flag &= ~LIB_INDIRECT_WEAK_LINK;