From 35294c0d7fbe3fc1c034677905676dfe6d9908a7 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 11 Apr 2023 15:41:02 +0200 Subject: [PATCH] Fix #106722: Motion tracking data lost on recovering autosave This is mistake in the refactor of the DNA storage which unified the camera and object storage. The bit which was missed from the initial logic is that the autosave does not use regular file write. Detect this in the do-versioning code and rely on the new data format when it exists. A candidate for 3.5.1 release. --- .../blenloader/intern/versioning_400.cc | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_400.cc b/source/blender/blenloader/intern/versioning_400.cc index c56c8a2608d..00ae25ebeb5 100644 --- a/source/blender/blenloader/intern/versioning_400.cc +++ b/source/blender/blenloader/intern/versioning_400.cc @@ -49,32 +49,37 @@ static void version_motion_tracking_legacy_camera_object(MovieClip &movieclip) MovieTrackingObject *active_tracking_object = BKE_tracking_object_get_active(&tracking); MovieTrackingObject *tracking_camera_object = BKE_tracking_object_get_camera(&tracking); - /* Sanity check. - * The camera tracking object is not supposed to have tracking and reconstruction read into it - * yet. */ - BLI_assert(tracking_camera_object != nullptr); - BLI_assert(BLI_listbase_is_empty(&tracking_camera_object->tracks)); - BLI_assert(BLI_listbase_is_empty(&tracking_camera_object->plane_tracks)); - BLI_assert(tracking_camera_object->reconstruction.cameras == nullptr); - /* Move storage from tracking to the actual tracking object. */ + /* NOTE: The regular .blend file saving converts the new format to the legacy format, but the + * auto-save one does not do this. Likely, the regular saving clears the new storage before + * write, so it can be used to make a decision here. + * + * The idea is basically to not override the new storage if it exists. This is only supposed to + * happen for auto-save files. */ - tracking_camera_object->tracks = tracking.tracks_legacy; - tracking_camera_object->plane_tracks = tracking.plane_tracks_legacy; + if (BLI_listbase_is_empty(&tracking_camera_object->tracks)) { + tracking_camera_object->tracks = tracking.tracks_legacy; + active_tracking_object->active_track = tracking.act_track_legacy; + } - tracking_camera_object->reconstruction = tracking.reconstruction_legacy; - memset(&tracking.reconstruction_legacy, 0, sizeof(tracking.reconstruction_legacy)); + if (BLI_listbase_is_empty(&tracking_camera_object->plane_tracks)) { + tracking_camera_object->plane_tracks = tracking.plane_tracks_legacy; + active_tracking_object->active_plane_track = tracking.act_plane_track_legacy; + } - /* The active track in the tracking structure used to be shared across all tracking objects. */ - active_tracking_object->active_track = tracking.act_track_legacy; - active_tracking_object->active_plane_track = tracking.act_plane_track_legacy; + if (tracking_camera_object->reconstruction.cameras == nullptr) { + tracking_camera_object->reconstruction = tracking.reconstruction_legacy; + } - /* Clear pointers in the legacy storage. */ + /* Clear pointers in the legacy storage. + * Always do it, in the case something got missed in the logic above, so that the legacy storage + * is always ensured to be empty after load. */ BLI_listbase_clear(&tracking.tracks_legacy); BLI_listbase_clear(&tracking.plane_tracks_legacy); tracking.act_track_legacy = nullptr; tracking.act_plane_track_legacy = nullptr; + memset(&tracking.reconstruction_legacy, 0, sizeof(tracking.reconstruction_legacy)); } static void version_movieclips_legacy_camera_object(Main *bmain) -- 2.30.2