From da88fc87fdb66691d0c67ac20ccdb88e20df6ecb Mon Sep 17 00:00:00 2001 From: Sebastian Parborg Date: Wed, 7 Aug 2024 17:36:32 +0200 Subject: [PATCH] Fix: Try to mitigate frame sync race condition when stopping playback We would update the scene frame before we actually stopped the callback timers for automatic frame sync. This could lead to a race condition where the set frame would be overwritten before we stopped the callback timer. Pull Request: https://projects.blender.org/blender/blender/pulls/132022 --- source/blender/editors/screen/screen_ops.cc | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/source/blender/editors/screen/screen_ops.cc b/source/blender/editors/screen/screen_ops.cc index 2e893b94739..93370605e0c 100644 --- a/source/blender/editors/screen/screen_ops.cc +++ b/source/blender/editors/screen/screen_ops.cc @@ -5767,20 +5767,21 @@ static int screen_animation_cancel_exec(bContext *C, wmOperator *op) bScreen *screen = ED_screen_animation_playing(CTX_wm_manager(C)); if (screen) { - if (RNA_boolean_get(op->ptr, "restore_frame") && screen->animtimer) { + bool restore_start_frame = RNA_boolean_get(op->ptr, "restore_frame") && screen->animtimer; + int frame; + if (restore_start_frame) { ScreenAnimData *sad = static_cast(screen->animtimer->customdata); - Scene *scene = CTX_data_scene(C); - - /* reset current frame before stopping, and just send a notifier to deal with the rest - * (since playback still needs to be stopped) - */ - scene->r.cfra = sad->sfra; - - WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene); + frame = sad->sfra; } - /* call the other "toggling" operator to clean up now */ + /* Stop playback */ ED_screen_animation_play(C, 0, 0); + if (restore_start_frame) { + Scene *scene = CTX_data_scene(C); + /* reset current frame and just send a notifier to deal with the rest */ + scene->r.cfra = frame; + WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene); + } } return OPERATOR_PASS_THROUGH;