Teardown traffic manager before drape engine destruction.

This commit is contained in:
Daria Volvenkova 2016-12-07 16:52:37 +03:00
parent 124b4ae6b0
commit 74bfefc2c9
3 changed files with 38 additions and 16 deletions

View file

@ -461,10 +461,7 @@ Framework::Framework()
Framework::~Framework()
{
m_trafficManager.SetDrapeEngine(nullptr);
m_drapeApi.SetEngine(nullptr);
m_drapeEngine.reset();
DestroyDrapeEngine();
m_model.SetOnMapDeregisteredCallback(nullptr);
}
@ -1753,8 +1750,13 @@ ref_ptr<df::DrapeEngine> Framework::GetDrapeEngine()
void Framework::DestroyDrapeEngine()
{
GpsTracker::Instance().Disconnect();
m_drapeEngine.reset();
if (m_drapeEngine != nullptr)
{
m_drapeApi.SetEngine(nullptr);
m_trafficManager.Teardown();
GpsTracker::Instance().Disconnect();
m_drapeEngine.reset();
}
}
void Framework::SetRenderingEnabled(ref_ptr<dp::OGLContextFactory> contextFactory)

View file

@ -51,6 +51,11 @@ TrafficManager::TrafficManager(GetMwmsByRectFn const & getMwmsByRectFn, size_t m
}
TrafficManager::~TrafficManager()
{
ASSERT(m_isTeardowned, ());
}
void TrafficManager::Teardown()
{
{
lock_guard<mutex> lock(m_mutex);
@ -58,6 +63,10 @@ TrafficManager::~TrafficManager()
}
m_condition.notify_one();
m_thread.join();
#ifdef DEBUG
m_isTeardowned = true;
#endif
}
void TrafficManager::SetStateListener(TrafficStateChangedFn const & onStateChangedFn)
@ -313,21 +322,26 @@ void TrafficManager::OnTrafficDataResponse(traffic::TrafficInfo && info)
it->second.m_isWaitingForResponse = false;
it->second.m_lastAvailability = info.GetAvailability();
// Update cache.
size_t constexpr kElementSize = sizeof(traffic::TrafficInfo::RoadSegmentId) + sizeof(traffic::SpeedGroup);
size_t const dataSize = info.GetColoring().size() * kElementSize;
m_currentCacheSizeBytes += (dataSize - it->second.m_dataSize);
it->second.m_dataSize = dataSize;
CheckCacheSize();
if (!info.GetColoring().empty())
{
// Update cache.
size_t constexpr kElementSize = sizeof(traffic::TrafficInfo::RoadSegmentId) + sizeof(traffic::SpeedGroup);
size_t const dataSize = info.GetColoring().size() * kElementSize;
m_currentCacheSizeBytes += (dataSize - it->second.m_dataSize);
it->second.m_dataSize = dataSize;
CheckCacheSize();
}
UpdateState();
}
m_drapeEngine->UpdateTraffic(info);
if (!info.GetColoring().empty())
{
m_drapeEngine->UpdateTraffic(info);
// Update traffic colors for routing.
m_observer.OnTrafficInfoAdded(move(info));
// Update traffic colors for routing.
m_observer.OnTrafficInfoAdded(move(info));
}
}
void TrafficManager::CheckCacheSize()

View file

@ -61,6 +61,8 @@ public:
traffic::TrafficObserver & observer);
~TrafficManager();
void Teardown();
void SetStateListener(TrafficStateChangedFn const & onStateChangedFn);
void SetDrapeEngine(ref_ptr<df::DrapeEngine> engine);
void SetCurrentDataVersion(int64_t dataVersion);
@ -139,4 +141,8 @@ private:
vector<MwmSet::MwmId> m_requestedMwms;
mutex m_mutex;
threads::SimpleThread m_thread;
#ifdef DEBUG
bool m_isTeardowned = false;
#endif
};