From 89bde99674b50ad313f6b7d459f8293c4993ba06 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 15 Jun 2020 16:30:46 +0200 Subject: Fix (unreported) critical mistake in Collection liblink code in readfile.c. Prelimenary step to fix T77460. Not sure how or when that thing was done, but since that call walks around collections relationships, it's an utterly critical violation of liblinking principles (code here should never, ever 'get outside' of its own ID scope). This was wroking so far only because code called through this function (`BKE_collection_parent_relations_rebuild`) was only following parents pointers (in `BKE_collection_find_cycle()`), which would be either valid or non-existent. But next commit is going to change that to also check collection's objects instancing of other collections. --- source/blender/blenloader/intern/readfile.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'source/blender/blenloader/intern') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index cc53af2b4ff..12d1e93e183 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -6366,8 +6366,6 @@ static void lib_link_collection_data(FileData *fd, Library *lib, Collection *col for (CollectionChild *child = collection->children.first; child != NULL; child = child->next) { child->collection = newlibadr(fd, lib, child->collection); } - - BKE_collection_parent_relations_rebuild(collection); } static void lib_link_collection(FileData *fd, Main *UNUSED(bmain), Collection *collection) @@ -10111,18 +10109,9 @@ static void lib_link_all(FileData *fd, Main *bmain) * so simpler to just use it directly in this single call. */ BLO_main_validate_shapekeys(bmain, NULL); - if (fd->memfile != NULL) { - /* When doing redo, we perform a tremendous amount of esoteric magic tricks to avoid having to - * re-read all library data-blocks. - * Unfortunately, that means that we do not clear Collections' parents lists, which then get - * improperly extended in some cases by lib_link_scene() and lib_link_collection() calls above - * (when one local collection is parent of linked ones). - * I do not really see a way to address that issue, besides brute force call below which - * invalidates and re-creates all parenting relationships between collections. Yet another - * example of why it is such a bad idea to keep that kind of double-linked relationships info - * 'permanently' in our data structures... */ - BKE_main_collections_parent_relations_rebuild(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 -- cgit v1.2.3 From bf1e5a2133a3c35549e24850739f83af34eb15b3 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Mon, 15 Jun 2020 17:55:06 +0200 Subject: Blenloader: call blendRead and blendWrite of modifiers when available This is part of T76372. --- source/blender/blenloader/intern/readfile.c | 9 ++++++++- source/blender/blenloader/intern/writefile.c | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'source/blender/blenloader/intern') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 12d1e93e183..fcbbccedcda 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -5579,8 +5579,11 @@ static void direct_link_modifiers(BlendDataReader *reader, ListBase *lb, Object md = modifier_replace_with_fluid(reader->fd, ob, lb, md); is_allocated = true; } + + const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type); + /* if modifiers disappear, or for upward compatibility */ - if (NULL == BKE_modifier_get_info(md->type)) { + if (mti == NULL) { md->type = eModifierType_None; } @@ -5884,6 +5887,10 @@ static void direct_link_modifiers(BlendDataReader *reader, ListBase *lb, Object direct_link_curveprofile(reader, bmd->custom_profile); } } + + if (mti->blendRead != NULL) { + mti->blendRead(reader, md); + } } } diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 2b57a8e1f5e..b6f8849b46d 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -1839,6 +1839,10 @@ static void write_modifiers(BlendWriter *writer, ListBase *modbase) write_CurveProfile(writer, bmd->custom_profile); } } + + if (mti->blendWrite != NULL) { + mti->blendWrite(writer, md); + } } } -- cgit v1.2.3 From 6a0ebb80885be1b86588af57f989cafd9e64305d Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Mon, 15 Jun 2020 18:37:30 +0200 Subject: Refactor: use new blenloader api for laplacian deform modifier --- source/blender/blenloader/intern/readfile.c | 6 ------ source/blender/blenloader/intern/writefile.c | 5 ----- 2 files changed, 11 deletions(-) (limited to 'source/blender/blenloader/intern') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index fcbbccedcda..f3b92b1f6a4 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -5831,12 +5831,6 @@ static void direct_link_modifiers(BlendDataReader *reader, ListBase *lb, Object direct_link_curvemapping(reader, wmd->cmap_curve); } } - else if (md->type == eModifierType_LaplacianDeform) { - LaplacianDeformModifierData *lmd = (LaplacianDeformModifierData *)md; - - BLO_read_float3_array(reader, lmd->total_verts, &lmd->vertexco); - lmd->cache_system = NULL; - } else if (md->type == eModifierType_CorrectiveSmooth) { CorrectiveSmoothModifierData *csmd = (CorrectiveSmoothModifierData *)md; diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index b6f8849b46d..2cc6cecd815 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -1794,11 +1794,6 @@ static void write_modifiers(BlendWriter *writer, ListBase *modbase) write_curvemapping(writer, wmd->cmap_curve); } } - else if (md->type == eModifierType_LaplacianDeform) { - LaplacianDeformModifierData *lmd = (LaplacianDeformModifierData *)md; - - BLO_write_float3_array(writer, lmd->total_verts, lmd->vertexco); - } else if (md->type == eModifierType_CorrectiveSmooth) { CorrectiveSmoothModifierData *csmd = (CorrectiveSmoothModifierData *)md; -- cgit v1.2.3