From 5a8e15aebd11adf4333b81a24ef01a5befc3598f Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Tue, 16 Apr 2024 12:18:45 +0900 Subject: [PATCH] lottie: ++binary search stability. this ensures that the return value is not below 0, when the frame count is just 2. --- src/loaders/lottie/tvgLottieProperty.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/loaders/lottie/tvgLottieProperty.h b/src/loaders/lottie/tvgLottieProperty.h index 03907756..055c374d 100644 --- a/src/loaders/lottie/tvgLottieProperty.h +++ b/src/loaders/lottie/tvgLottieProperty.h @@ -195,17 +195,18 @@ struct LottieVectorFrame template uint32_t bsearch(T* frames, float frameNo) { - uint32_t low = 0; - uint32_t high = frames->count - 1; + int32_t low = 0; + int32_t high = int32_t(frames->count) - 1; while (low <= high) { auto mid = low + (high - low) / 2; auto frame = frames->data + mid; - if (mathEqual(frameNo, frame->no)) return mid; - else if (frameNo < frame->no) high = mid - 1; + if (frameNo < frame->no) high = mid - 1; else low = mid + 1; } if (high < low) low = high; + if (low < 0) low = 0; + return low; }