From a53d3815a9c8e291629322aecad9bd8f1dcf5095 Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Tue, 9 Jul 2019 19:03:17 +0300 Subject: [PATCH] [core] Decouple style change and transitions update Update transitions in a separate call chain in order to avoid infinite loop, in case map is modified from within the transitions update callback. --- src/mbgl/map/map_impl.cpp | 17 ++++++++++++----- src/mbgl/map/map_impl.hpp | 6 ++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/mbgl/map/map_impl.cpp b/src/mbgl/map/map_impl.cpp index ce36583ab3b..c8392309f19 100644 --- a/src/mbgl/map/map_impl.cpp +++ b/src/mbgl/map/map_impl.cpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace mbgl { @@ -19,7 +20,9 @@ Map::Impl::Impl(RendererFrontend& frontend_, crossSourceCollisions(mapOptions.crossSourceCollisions()), fileSource(std::move(fileSource_)), style(std::make_unique(*fileSource, pixelRatio)), - annotationManager(*style) { + annotationManager(*style), + mailbox(std::make_shared(*Scheduler::GetCurrent())), + actor(*this, mailbox) { transform.setNorthOrientation(mapOptions.northOrientation()); style->impl->setObserver(this); rendererFrontend.setObserver(*this); @@ -39,12 +42,16 @@ void Map::Impl::onSourceChanged(style::Source& source) { } void Map::Impl::onUpdate() { - // Don't load/render anything in still mode until explicitly requested. - if (mode != MapMode::Continuous && !stillImageRequest) { - return; + if (mode == MapMode::Continuous) { + actor.invoke(&Map::Impl::updateInternal, Clock::now()); + } else if (stillImageRequest) { + updateInternal(Clock::time_point::max()); } +} - TimePoint timePoint = mode == MapMode::Continuous ? Clock::now() : Clock::time_point::max(); +void Map::Impl::updateInternal(TimePoint timePoint) { + // Don't load/render anything in still mode until explicitly requested. + assert(mode == MapMode::Continuous || stillImageRequest); transform.updateTransitions(timePoint); diff --git a/src/mbgl/map/map_impl.hpp b/src/mbgl/map/map_impl.hpp index 13a68fb25e0..dac54a87403 100644 --- a/src/mbgl/map/map_impl.hpp +++ b/src/mbgl/map/map_impl.hpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace mbgl { @@ -51,6 +52,9 @@ class Map::Impl : public style::Observer, public RendererObserver { // Map void jumpTo(const CameraOptions&); + // Internal + void updateInternal(TimePoint timePoint); + MapObserver& observer; RendererFrontend& rendererFrontend; @@ -74,6 +78,8 @@ class Map::Impl : public style::Observer, public RendererObserver { bool loading = false; bool rendererFullyLoaded; std::unique_ptr stillImageRequest; + std::shared_ptr mailbox; + ActorRef actor; }; } // namespace mbgl