diff --git a/src/animation/offline/animation_builder.cc b/src/animation/offline/animation_builder.cc index 5fd3d520d..51e44b72b 100644 --- a/src/animation/offline/animation_builder.cc +++ b/src/animation/offline/animation_builder.cc @@ -196,10 +196,9 @@ void CopyTimePoints(const span& _times, float _inv_duration, } uint16_t TimePointToIndex(const span& _timepoints, float _time) { - const float* found = std::find(_timepoints.begin(), _timepoints.end(), _time); - if (found == _timepoints.end()) { - assert(found != _timepoints.end()); - } + const float* found = + std::lower_bound(_timepoints.begin(), _timepoints.end(), _time); + assert(found != _timepoints.end() && *found == _time); const ptrdiff_t distance = found - _timepoints.begin(); assert(distance >= 0 && distance < std::numeric_limits::max()); return static_cast(distance); diff --git a/test/animation/offline/animation_builder_tests.cc b/test/animation/offline/animation_builder_tests.cc index 5cf3bde7f..040b0d42f 100644 --- a/test/animation/offline/animation_builder_tests.cc +++ b/test/animation/offline/animation_builder_tests.cc @@ -402,9 +402,17 @@ TEST(ManyKeys, SamplingJob) { raw_animation.tracks[0].translations.push_back(key2); } - // Track 1 has no key + // Track 1 has lots of keys + { + for (size_t i = 0; i < kMaxKey; ++i) { + const RawAnimation::TranslationKey key = {i * 1.f / kMaxKey, + ozz::math::Float3(0, 0, 0)}; + raw_animation.tracks[1].translations.push_back(key); + } + } - // Track 2 has lots of keys + // Track 2 has lots of keys (same timepoints as track 1 as number of + // trackpoints is limited) { for (size_t i = 0; i < kMaxKey; ++i) { const RawAnimation::TranslationKey key = {