Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Decouple style change and transitions update
Browse files Browse the repository at this point in the history
Update transitions in a separate call chain in order to avoid
infinite loop, in case map is modified from within the
transitions update callback.
  • Loading branch information
pozdnyakov committed Jul 9, 2019
1 parent 6b8df34 commit a53d381
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/mbgl/map/map_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <mbgl/storage/file_source.hpp>
#include <mbgl/style/style_impl.hpp>
#include <mbgl/util/exception.hpp>
#include <mbgl/actor/scheduler.hpp>

namespace mbgl {

Expand All @@ -19,7 +20,9 @@ Map::Impl::Impl(RendererFrontend& frontend_,
crossSourceCollisions(mapOptions.crossSourceCollisions()),
fileSource(std::move(fileSource_)),
style(std::make_unique<style::Style>(*fileSource, pixelRatio)),
annotationManager(*style) {
annotationManager(*style),
mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())),
actor(*this, mailbox) {
transform.setNorthOrientation(mapOptions.northOrientation());
style->impl->setObserver(this);
rendererFrontend.setObserver(*this);
Expand All @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions src/mbgl/map/map_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <mbgl/style/source.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/util/size.hpp>
#include <mbgl/actor/actor_ref.hpp>

namespace mbgl {

Expand Down Expand Up @@ -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;

Expand All @@ -74,6 +78,8 @@ class Map::Impl : public style::Observer, public RendererObserver {
bool loading = false;
bool rendererFullyLoaded;
std::unique_ptr<StillImageRequest> stillImageRequest;
std::shared_ptr<Mailbox> mailbox;
ActorRef<Map::Impl> actor;
};

} // namespace mbgl

0 comments on commit a53d381

Please sign in to comment.