From 27d2d0a23a7fbf6080d02aa3d0aaaac6330fdf1e Mon Sep 17 00:00:00 2001 From: Christoph Lendenfeld Date: Tue, 10 Jun 2025 16:40:07 +0200 Subject: [PATCH] Fix: Crash when snapping to first key using subframes When pressing Ctrl to snap the playhead while scrubbing, Blender could crash while trying to snap to the first key. This would happen if the current frame was higher than the left keyframe, but the difference was less than the `BEZT_BINARYSEARCH_THRESH`. Pull Request: https://projects.blender.org/blender/blender/pulls/140122 --- source/blender/editors/animation/keyframes_keylist.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/blender/editors/animation/keyframes_keylist.cc b/source/blender/editors/animation/keyframes_keylist.cc index 9677a182032..a8a8743a398 100644 --- a/source/blender/editors/animation/keyframes_keylist.cc +++ b/source/blender/editors/animation/keyframes_keylist.cc @@ -274,10 +274,12 @@ const ActKeyColumn *ED_keylist_find_closest(const AnimKeylist *keylist, const fl if (ED_keylist_is_empty(keylist)) { return nullptr; } - if (cfra <= keylist->runtime.key_columns.first().cfra) { + /* Need to check against BEZT_BINARYSEARCH_THRESH because `ED_keylist_find_prev` does so as well. + * Not doing that here could cause that function to return a nullptr. */ + if (cfra - keylist->runtime.key_columns.first().cfra < BEZT_BINARYSEARCH_THRESH) { return &keylist->runtime.key_columns.first(); } - if (cfra >= keylist->runtime.key_columns.last().cfra) { + if (cfra - keylist->runtime.key_columns.last().cfra > BEZT_BINARYSEARCH_THRESH) { keylist->runtime.key_columns.last(); } const ActKeyColumn *prev = ED_keylist_find_prev(keylist, cfra);