From 87c8ec0e5c36272da5a949ccd208cc24ebbc4c58 Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Thu, 7 Sep 2023 01:34:01 +0800 Subject: [PATCH] replay: fix concurrency issues (#29797) fix concurrency issues old-commit-hash: bbf133a2e505bee6dc502a3b636a59ae6b254798 --- tools/replay/replay.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/replay/replay.cc b/tools/replay/replay.cc index e323a9f64d..d8a68a06e9 100644 --- a/tools/replay/replay.cc +++ b/tools/replay/replay.cc @@ -151,9 +151,10 @@ void Replay::buildTimeline() { [(int)cereal::ControlsState::AlertStatus::CRITICAL] = TimelineType::AlertCritical, }; - for (auto it = segments_.cbegin(); it != segments_.cend() && !exit_; ++it) { + const auto &route_segments = route_->segments(); + for (auto it = route_segments.cbegin(); it != route_segments.cend() && !exit_; ++it) { LogReader log; - if (!log.load(route_->at(it->first).qlog.toStdString(), &exit_, + if (!log.load(it->second.qlog.toStdString(), &exit_, {cereal::Event::Which::CONTROLS_STATE, cereal::Event::Which::USER_FLAG}, !hasFlag(REPLAY_FLAG_NO_FILE_CACHE), 0, 3)) continue; @@ -227,7 +228,10 @@ void Replay::segmentLoadFinished(bool success) { if (!success) { Segment *seg = qobject_cast(sender()); rWarning("failed to load segment %d, removing it from current replay list", seg->seg_num); - segments_.erase(seg->seg_num); + updateEvents([&]() { + segments_.erase(seg->seg_num); + return true; + }); } queueSegment(); } @@ -456,7 +460,7 @@ void Replay::stream() { } if (eit == events_->end() && !hasFlag(REPLAY_FLAG_NO_LOOP)) { - int last_segment = segments_.rbegin()->first; + int last_segment = segments_.empty() ? 0 : segments_.rbegin()->first; if (current_segment_ >= last_segment && isSegmentMerged(last_segment)) { rInfo("reaches the end of route, restart from beginning"); QMetaObject::invokeMethod(this, std::bind(&Replay::seekTo, this, 0, false), Qt::QueuedConnection);