Commit 9aeb7118 authored by Ella Ge's avatar Ella Ge Committed by Commit Bot

Fix incorrect index in finding interpolate index

The crash in GetInterpolatedEventForPredictedEvent is due to the initial
value of 'idx' is set to -1, but it's an unsigned type.
This CL makes it initialize to 0.

Bug: 1030386
Change-Id: I44796c1813374f4c192ee3c125c5f957fbe57061
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1948048Reviewed-by: default avatarNavid Zolghadr <nzolghadr@chromium.org>
Commit-Queue: Ella Ge <eirage@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721381}
parent 0670ebfc
......@@ -94,24 +94,23 @@ void PredictionMetricsHandler::Reset() {
int PredictionMetricsHandler::GetInterpolatedEventForPredictedEvent(
const base::TimeTicks& interpolation_timestamp,
gfx::PointF* interpolated) {
size_t idx = -1;
while (idx + 1 < events_queue_.size() &&
interpolation_timestamp >= events_queue_[idx + 1].time_stamp)
size_t idx = 0;
while (idx < events_queue_.size() &&
interpolation_timestamp >= events_queue_[idx].time_stamp)
idx++;
DCHECK(idx >= 0);
if (idx < 0 || idx + 1 >= events_queue_.size())
if (idx == 0 || idx == events_queue_.size())
return -1;
float alpha =
(interpolation_timestamp - events_queue_[idx].time_stamp)
(interpolation_timestamp - events_queue_[idx - 1].time_stamp)
.InMillisecondsF() /
(events_queue_[idx + 1].time_stamp - events_queue_[idx].time_stamp)
(events_queue_[idx].time_stamp - events_queue_[idx - 1].time_stamp)
.InMillisecondsF();
*interpolated =
events_queue_[idx].pos +
ScaleVector2d(events_queue_[idx + 1].pos - events_queue_[idx].pos, alpha);
return idx;
events_queue_[idx - 1].pos +
ScaleVector2d(events_queue_[idx].pos - events_queue_[idx - 1].pos, alpha);
return idx - 1;
}
void PredictionMetricsHandler::ComputeMetrics() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment