From f49d438ced7c5874dbf43976d9901a462176f541 Mon Sep 17 00:00:00 2001 From: Sebastian Parborg Date: Fri, 20 Aug 2021 16:30:34 +0200 Subject: Cleanup and remove SEQ_ALL_BEGIN macro We now use a for_each function with callback to iterate through all sequences in the scene. This has the benefit that we now only loop over the sequences in the scene once. Before we would loop over them twice and allocate memory to store temporary data. The allocation of temporary data lead to unintentional memory leaks if the code used returns to exit out of the iteration loop. The new for_each callback method doesn't allocate any temporary data and only iterates though all sequences once. Reviewed By: Richard Antalik, Bastien Montagne Differential Revision: http://developer.blender.org/D12278 --- source/blender/blenloader/intern/versioning_250.c | 80 +++++++++++++---------- 1 file changed, 47 insertions(+), 33 deletions(-) (limited to 'source/blender/blenloader/intern/versioning_250.c') diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c index 436645c2241..54e673b51eb 100644 --- a/source/blender/blenloader/intern/versioning_250.c +++ b/source/blender/blenloader/intern/versioning_250.c @@ -638,6 +638,46 @@ static void do_versions_socket_default_value_259(bNodeSocket *sock) } } +static bool seq_sound_proxy_update_cb(Sequence *seq, void *user_data) +{ + Main *bmain = (Main *)user_data; + if (seq->type == SEQ_TYPE_SOUND_HD) { + char str[FILE_MAX]; + BLI_join_dirfile(str, sizeof(str), seq->strip->dir, seq->strip->stripdata->name); + BLI_path_abs(str, BKE_main_blendfile_path(bmain)); + seq->sound = BKE_sound_new_file(bmain, str); + } +#define SEQ_USE_PROXY_CUSTOM_DIR (1 << 19) +#define SEQ_USE_PROXY_CUSTOM_FILE (1 << 21) + /* don't know, if anybody used that this way, but just in case, upgrade to new way... */ + if ((seq->flag & SEQ_USE_PROXY_CUSTOM_FILE) && !(seq->flag & SEQ_USE_PROXY_CUSTOM_DIR)) { + BLI_snprintf(seq->strip->proxy->dir, FILE_MAXDIR, "%s/BL_proxy", seq->strip->dir); + } +#undef SEQ_USE_PROXY_CUSTOM_DIR +#undef SEQ_USE_PROXY_CUSTOM_FILE + return true; +} + +static bool seq_set_volume_cb(Sequence *seq, void *UNUSED(user_data)) +{ + seq->volume = 1.0f; + return true; +} + +static bool seq_set_sat_cb(Sequence *seq, void *UNUSED(user_data)) +{ + if (seq->sat == 0.0f) { + seq->sat = 1.0f; + } + return true; +} + +static bool seq_set_pitch_cb(Sequence *seq, void *UNUSED(user_data)) +{ + seq->pitch = 1.0f; + return true; +} + /* NOLINTNEXTLINE: readability-function-size */ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) { @@ -660,7 +700,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) #endif bSound *sound; - Sequence *seq; for (sound = bmain->sounds.first; sound; sound = sound->id.next) { if (sound->newpackedfile) { @@ -671,23 +710,7 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) for (scene = bmain->scenes.first; scene; scene = scene->id.next) { if (scene->ed && scene->ed->seqbasep) { - SEQ_ALL_BEGIN (scene->ed, seq) { - if (seq->type == SEQ_TYPE_SOUND_HD) { - char str[FILE_MAX]; - BLI_join_dirfile(str, sizeof(str), seq->strip->dir, seq->strip->stripdata->name); - BLI_path_abs(str, BKE_main_blendfile_path(bmain)); - seq->sound = BKE_sound_new_file(bmain, str); - } -#define SEQ_USE_PROXY_CUSTOM_DIR (1 << 19) -#define SEQ_USE_PROXY_CUSTOM_FILE (1 << 21) - /* don't know, if anybody used that this way, but just in case, upgrade to new way... */ - if ((seq->flag & SEQ_USE_PROXY_CUSTOM_FILE) && !(seq->flag & SEQ_USE_PROXY_CUSTOM_DIR)) { - BLI_snprintf(seq->strip->proxy->dir, FILE_MAXDIR, "%s/BL_proxy", seq->strip->dir); - } -#undef SEQ_USE_PROXY_CUSTOM_DIR -#undef SEQ_USE_PROXY_CUSTOM_FILE - } - SEQ_ALL_END; + SEQ_for_each_callback(&scene->ed->seqbase, seq_sound_proxy_update_cb, bmain); } } @@ -1391,7 +1414,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) if (!MAIN_VERSION_ATLEAST(bmain, 250, 17)) { Scene *sce; - Sequence *seq; /* initialize to sane default so toggling on border shows something */ for (sce = bmain->scenes.first; sce; sce = sce->id.next) { @@ -1406,11 +1428,9 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) if ((sce->r.ffcodecdata.flags & FFMPEG_MULTIPLEX_AUDIO) == 0) { sce->r.ffcodecdata.audio_codec = 0x0; /* `CODEC_ID_NONE` */ } - - SEQ_ALL_BEGIN (sce->ed, seq) { - seq->volume = 1.0f; + if (sce->ed) { + SEQ_for_each_callback(&sce->ed->seqbase, seq_set_volume_cb, NULL); } - SEQ_ALL_END; } /* particle brush strength factor was changed from int to float */ @@ -1678,13 +1698,9 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) } for (scene = bmain->scenes.first; scene; scene = scene->id.next) { - Sequence *seq; - SEQ_ALL_BEGIN (scene->ed, seq) { - if (seq->sat == 0.0f) { - seq->sat = 1.0f; - } + if (scene->ed) { + SEQ_for_each_callback(&scene->ed->seqbase, seq_set_sat_cb, NULL); } - SEQ_ALL_END; } /* GSOC 2010 Sculpt - New settings for Brush */ @@ -2159,15 +2175,13 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) if (!MAIN_VERSION_ATLEAST(bmain, 259, 1)) { { Scene *scene; - Sequence *seq; for (scene = bmain->scenes.first; scene; scene = scene->id.next) { scene->r.ffcodecdata.audio_channels = 2; scene->audio.volume = 1.0f; - SEQ_ALL_BEGIN (scene->ed, seq) { - seq->pitch = 1.0f; + if (scene->ed) { + SEQ_for_each_callback(&scene->ed->seqbase, seq_set_pitch_cb, NULL); } - SEQ_ALL_END; } } -- cgit v1.2.3