From 42f6aada98a655bce975a8dc24aa67e33200fbd9 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Mon, 2 Nov 2020 14:26:49 +0100 Subject: Fix crash opening some 2.4x .blend files with drivers or NLA editor For example, outlinertest.blend from test240.zip. --- source/blender/blenloader/intern/readfile.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source/blender/blenloader/intern/readfile.c') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index c49808c3718..5a6324eb8e1 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -2527,7 +2527,9 @@ static void direct_link_ipo(BlendDataReader *reader, Ipo *ipo) /* Undo generic endian switching. */ if (BLO_read_requires_endian_switch(reader)) { BLI_endian_switch_int16(&ipo->blocktype); - BLI_endian_switch_int16(&icu->driver->blocktype); + if (icu->driver != NULL) { + BLI_endian_switch_int16(&icu->driver->blocktype); + } } } } -- cgit v1.2.3 From 5610ccdc080497042a24592432ade575e2fab489 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Tue, 3 Nov 2020 11:39:36 +0100 Subject: Add a callback to `IDTypeInfo` to allow preservation of some data accross memfile undos This is essentially adding that new callback, and using it only for already existing Scene's 3DCursor. Note that the place where this is called has been moved again, after all have been lib-linked, such that those callbacks may also work on ID pointers. Maniphest Tasks: T71759 Differential Revision: https://developer.blender.org/D9237 --- source/blender/blenloader/intern/readfile.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'source/blender/blenloader/intern/readfile.c') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index ae640891eab..c2a18033b44 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -5672,15 +5672,6 @@ static void read_libblock_undo_restore_at_old_address(FileData *fd, Main *main, const short idcode = GS(id->name); - /* XXX 3DCursor (witch is UI data and as such should not be affected by undo) is stored in - * Scene... So this requires some special handling, previously done in `blo_lib_link_restore()`, - * but this cannot work anymore when we overwrite existing memory... */ - if (idcode == ID_SCE) { - Scene *scene_old = (Scene *)id_old; - Scene *scene = (Scene *)id; - SWAP(View3DCursor, scene_old->cursor, scene->cursor); - } - Main *old_bmain = fd->old_mainlist->first; ListBase *old_lb = which_libbase(old_bmain, idcode); ListBase *new_lb = which_libbase(main, idcode); @@ -5692,6 +5683,11 @@ static void read_libblock_undo_restore_at_old_address(FileData *fd, Main *main, * process). So we can pass NULL for the Main pointer parameter. */ BKE_lib_id_swap_full(NULL, id, id_old); + /* Special temporary usage of this pointer, necessary for the `undo_preserve` call after + * lib-linking to restore some data that should never be affected by undo, e.g. the 3D cursor of + * #Scene. */ + id_old->orig_id = id; + BLI_addtail(new_lb, id_old); BLI_addtail(old_lb, id); } @@ -6123,6 +6119,18 @@ static void lib_link_all(FileData *fd, Main *bmain) } id->tag &= ~LIB_TAG_NEED_LINK; + + /* Some data that should be persistent, like the 3DCursor or the tool settings, are + * stored in IDs affected by undo, like Scene. So this requires some specific handling. */ + if (id_type->blend_read_undo_preserve != NULL && id->orig_id != NULL) { + id_type->blend_read_undo_preserve(&reader, id, id->orig_id); + } + } + FOREACH_MAIN_ID_END; + + /* Cleanup `ID.orig_id`, this is now reserved for depsgraph/COW usage only. */ + FOREACH_MAIN_ID_BEGIN (bmain, id) { + id->orig_id = NULL; } FOREACH_MAIN_ID_END; -- cgit v1.2.3 From 2a6a26bbd77071ee475c440f59c1b52b231fad5d Mon Sep 17 00:00:00 2001 From: Richard Antalik Date: Thu, 5 Nov 2020 14:05:25 +0100 Subject: Rename extern rendering and proxy functions Replace BKE_sequencer wirh SEQ_render or SEQ_proxy prefixes. In cases where function is very generic, only SEQ prefix is used. Reviewed By: sergey Differential Revision: https://developer.blender.org/D9439 --- source/blender/blenloader/intern/readfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/blenloader/intern/readfile.c') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index c2a18033b44..28d39a35014 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -4393,7 +4393,7 @@ static void direct_link_scene(BlendDataReader *reader, Scene *sce) seq->strip->proxy->anim = NULL; } else if (seq->flag & SEQ_USE_PROXY) { - BKE_sequencer_proxy_set(seq, true); + SEQ_proxy_set(seq, true); } /* need to load color balance to it could be converted to modifier */ -- cgit v1.2.3 From 7cb20d841da16d0bffb63154403267500e9941f5 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 6 Nov 2020 11:25:27 +1100 Subject: Cleanup: follow our code style for float literals --- source/blender/blenloader/intern/readfile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source/blender/blenloader/intern/readfile.c') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 28d39a35014..080e22c68b9 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -2661,8 +2661,8 @@ static void direct_link_constraints(BlendDataReader *reader, ListBase *lb) case CONSTRAINT_TYPE_KINEMATIC: { bKinematicConstraint *data = con->data; - con->lin_error = 0.f; - con->rot_error = 0.f; + con->lin_error = 0.0f; + con->rot_error = 0.0f; /* version patch for runtime flag, was not cleared in some case */ data->flag &= ~CONSTRAINT_IK_AUTO; -- cgit v1.2.3 From a51455918cb9289224d56fa0e756c6abc801dc32 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 6 Nov 2020 15:00:07 +1100 Subject: Cleanup: de-duplicate code for instancing objects when linking Ref D8843 --- source/blender/blenloader/intern/readfile.c | 77 +++++++++++++++-------------- 1 file changed, 40 insertions(+), 37 deletions(-) (limited to 'source/blender/blenloader/intern/readfile.c') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 080e22c68b9..855d320a63d 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -7069,6 +7069,31 @@ static bool object_in_any_collection(Main *bmain, Object *ob) return false; } +/** + * Shared operations to perform on the object's base after adding it to the scene. + */ +static void object_base_instance_init( + Object *ob, bool set_selected, bool set_active, ViewLayer *view_layer, const View3D *v3d) +{ + Base *base = BKE_view_layer_base_find(view_layer, ob); + + if (v3d != NULL) { + base->local_view_bits |= v3d->local_view_uuid; + } + + if (set_selected) { + if (base->flag & BASE_SELECTABLE) { + base->flag |= BASE_SELECTED; + } + } + + if (set_active) { + view_layer->basact = base; + } + + BKE_scene_object_base_flag_sync_from_base(base); +} + static void add_loose_objects_to_scene(Main *mainvar, Main *bmain, Scene *scene, @@ -7114,19 +7139,12 @@ static void add_loose_objects_to_scene(Main *mainvar, ob->mode = OB_MODE_OBJECT; BKE_collection_object_add(bmain, active_collection, ob); - Base *base = BKE_view_layer_base_find(view_layer, ob); - if (v3d != NULL) { - base->local_view_bits |= v3d->local_view_uuid; - } - - if ((flag & FILE_AUTOSELECT) && (base->flag & BASE_SELECTABLE)) { - /* Do NOT make base active here! screws up GUI stuff, - * if you want it do it at the editor level. */ - base->flag |= BASE_SELECTED; - } - - BKE_scene_object_base_flag_sync_from_base(base); + const bool set_selected = (flag & FILE_AUTOSELECT) != 0; + /* Do NOT make base active here! screws up GUI stuff, + * if you want it do it at the editor level. */ + const bool set_active = false; + object_base_instance_init(ob, set_selected, set_active, view_layer, v3d); ob->id.tag &= ~LIB_TAG_INDIRECT; ob->id.flag &= ~LIB_INDIRECT_WEAK_LINK; @@ -7172,19 +7190,12 @@ static void add_loose_object_data_to_scene(Main *mainvar, BKE_object_materials_test(bmain, ob, ob->data); BKE_collection_object_add(bmain, active_collection, ob); - Base *base = BKE_view_layer_base_find(view_layer, ob); - if (v3d != NULL) { - base->local_view_bits |= v3d->local_view_uuid; - } - - if ((flag & FILE_AUTOSELECT) && (base->flag & BASE_SELECTABLE)) { - /* Do NOT make base active here! screws up GUI stuff, - * if you want it do it at the editor level. */ - base->flag |= BASE_SELECTED; - } - - BKE_scene_object_base_flag_sync_from_base(base); + const bool set_selected = (flag & FILE_AUTOSELECT) != 0; + /* Do NOT make base active here! screws up GUI stuff, + * if you want it do it at the editor level. */ + bool set_active = false; + object_base_instance_init(ob, set_selected, set_active, view_layer, v3d); copy_v3_v3(ob->loc, scene->cursor.location); } @@ -7218,23 +7229,15 @@ static void add_collections_to_scene(Main *mainvar, ob->empty_drawsize = U.collection_instance_empty_size; BKE_collection_object_add(bmain, active_collection, ob); - Base *base = BKE_view_layer_base_find(view_layer, ob); - - if (v3d != NULL) { - base->local_view_bits |= v3d->local_view_uuid; - } - if ((flag & FILE_AUTOSELECT) && (base->flag & BASE_SELECTABLE)) { - base->flag |= BASE_SELECTED; - } + const bool set_selected = (flag & FILE_AUTOSELECT) != 0; + /* TODO: why is it OK to make this active here but not in other situations? + * See other callers of #object_base_instance_init */ + const bool set_active = set_selected; + object_base_instance_init(ob, set_selected, set_active, view_layer, v3d); - BKE_scene_object_base_flag_sync_from_base(base); DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION); - if (flag & FILE_AUTOSELECT) { - view_layer->basact = base; - } - /* Assign the collection. */ ob->instance_collection = collection; id_us_plus(&collection->id); -- cgit v1.2.3