From 34510b8f1c35fa0a9ccaddcf7ca7573631038b93 Mon Sep 17 00:00:00 2001 From: Kiryl Kaveryn Date: Thu, 26 Dec 2024 18:04:43 +0400 Subject: [PATCH] [map] clear the gps tracker on save The prev solution was to clean up the tracker points before the new track recording starting. It was not fully correct solution because: 1. it causes the bug, when if we starts a recording, the `TrackRecordingUpdateHandler` is called by subscribers but receives the old `track info` from the previous track. It happens because the starting is an async call and it cleans up the gps collection a little bit later. 2. when the user finishes the track recording the collection is not properly cleared. The data will stay in the memory `forewer` until the next recording is started. And this data will be recovered on the next app launch too. There are no reason to store all the recorded data in memory until the new recording begins. This approach was Ok for the `previous path` feature (removed) but not for the TR. The data lifecycle for the both feature should be handled separately. Signed-off-by: Kiryl Kaveryn --- map/framework.cpp | 1 + map/gps_tracker.cpp | 5 +++++ map/gps_tracker.hpp | 1 + 3 files changed, 7 insertions(+) diff --git a/map/framework.cpp b/map/framework.cpp index b20207f3ff..8781e204e0 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -1752,6 +1752,7 @@ void Framework::StopTrackRecording() void Framework::SaveTrackRecordingWithName(std::string const & name) { GetBookmarkManager().SaveTrackRecording(name); + GpsTracker::Instance().Clear(); if (m_drapeEngine) m_drapeEngine->ClearGpsTrackPoints(); } diff --git a/map/gps_tracker.cpp b/map/gps_tracker.cpp index 23080815ed..9fa961adf4 100644 --- a/map/gps_tracker.cpp +++ b/map/gps_tracker.cpp @@ -60,6 +60,11 @@ void GpsTracker::SetEnabled(bool enabled) m_track.Clear(); } +void GpsTracker::Clear() +{ + m_track.Clear(); +} + bool GpsTracker::IsEnabled() const { return m_enabled; diff --git a/map/gps_tracker.hpp b/map/gps_tracker.hpp index 8cce4eab0f..6840ec0c63 100644 --- a/map/gps_tracker.hpp +++ b/map/gps_tracker.hpp @@ -14,6 +14,7 @@ public: bool IsEnabled() const; void SetEnabled(bool enabled); + void Clear(); bool IsEmpty() const; size_t GetTrackSize() const;