Fixed crash on location update before drape engine creation

This commit is contained in:
Roman Kuznetsov 2017-07-16 10:37:40 +03:00 committed by r.kuznetsov
parent b235d5b2c9
commit 84f6b9b0a8
2 changed files with 24 additions and 4 deletions

View file

@ -644,20 +644,37 @@ void RoutingManager::MatchLocationToRoute(location::GpsInfo & location,
void RoutingManager::OnLocationUpdate(location::GpsInfo & info)
{
location::RouteMatchingInfo routeMatchingInfo;
CheckLocationForRouting(info);
if (m_drapeEngine == nullptr)
m_gpsInfoCache = my::make_unique<location::GpsInfo>(info);
MatchLocationToRoute(info, routeMatchingInfo);
auto routeMatchingInfo = GetRouteMatchingInfo(info);
m_drapeEngine->SetGpsInfo(info, m_routingSession.IsNavigable(), routeMatchingInfo);
if (m_drapeEngine != nullptr)
m_drapeEngine->SetGpsInfo(info, m_routingSession.IsNavigable(), routeMatchingInfo);
if (IsTrackingReporterEnabled())
m_trackingReporter.AddLocation(info, m_routingSession.MatchTraffic(routeMatchingInfo));
}
location::RouteMatchingInfo RoutingManager::GetRouteMatchingInfo(location::GpsInfo & info)
{
location::RouteMatchingInfo routeMatchingInfo;
CheckLocationForRouting(info);
MatchLocationToRoute(info, routeMatchingInfo);
return routeMatchingInfo;
}
void RoutingManager::SetDrapeEngine(ref_ptr<df::DrapeEngine> engine, bool is3dAllowed)
{
m_drapeEngine = engine;
// Apply gps info which was set before drape engine creation.
if (m_gpsInfoCache != nullptr)
{
auto routeMatchingInfo = GetRouteMatchingInfo(*m_gpsInfoCache);
m_drapeEngine->SetGpsInfo(*m_gpsInfoCache, m_routingSession.IsNavigable(), routeMatchingInfo);
m_gpsInfoCache.reset();
}
// In case of the engine reinitialization recover route.
if (IsRoutingActive())
{

View file

@ -220,6 +220,7 @@ private:
bool IsTrackingReporterEnabled() const;
void MatchLocationToRoute(location::GpsInfo & info,
location::RouteMatchingInfo & routeMatchingInfo) const;
location::RouteMatchingInfo GetRouteMatchingInfo(location::GpsInfo & info);
RouteBuildingCallback m_routingCallback = nullptr;
Callbacks m_callbacks;
@ -233,5 +234,7 @@ private:
std::vector<dp::DrapeID> m_drapeSubroutes;
std::mutex m_drapeSubroutesMutex;
std::unique_ptr<location::GpsInfo> m_gpsInfoCache;
DECLARE_THREAD_CHECKER(m_threadChecker);
};