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

Commit 148cfe9

Browse files
committed
[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.
1 parent 0ca96fd commit 148cfe9

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

src/mbgl/map/map_impl.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <mbgl/actor/scheduler.hpp>
12
#include <mbgl/layermanager/layer_manager.hpp>
23
#include <mbgl/map/map_impl.hpp>
34
#include <mbgl/renderer/update_parameters.hpp>
@@ -11,15 +12,17 @@ Map::Impl::Impl(RendererFrontend& frontend_,
1112
MapObserver& observer_,
1213
std::shared_ptr<FileSource> fileSource_,
1314
const MapOptions& mapOptions)
14-
: observer(observer_),
15-
rendererFrontend(frontend_),
16-
transform(observer, mapOptions.constrainMode(), mapOptions.viewportMode()),
17-
mode(mapOptions.mapMode()),
18-
pixelRatio(mapOptions.pixelRatio()),
19-
crossSourceCollisions(mapOptions.crossSourceCollisions()),
20-
fileSource(std::move(fileSource_)),
21-
style(std::make_unique<style::Style>(*fileSource, pixelRatio)),
22-
annotationManager(*style) {
15+
: observer(observer_),
16+
rendererFrontend(frontend_),
17+
transform(observer, mapOptions.constrainMode(), mapOptions.viewportMode()),
18+
mode(mapOptions.mapMode()),
19+
pixelRatio(mapOptions.pixelRatio()),
20+
crossSourceCollisions(mapOptions.crossSourceCollisions()),
21+
fileSource(std::move(fileSource_)),
22+
style(std::make_unique<style::Style>(*fileSource, pixelRatio)),
23+
annotationManager(*style),
24+
mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())),
25+
actor(*this, mailbox) {
2326
transform.setNorthOrientation(mapOptions.northOrientation());
2427
style->impl->setObserver(this);
2528
rendererFrontend.setObserver(*this);
@@ -39,12 +42,16 @@ void Map::Impl::onSourceChanged(style::Source& source) {
3942
}
4043

4144
void Map::Impl::onUpdate() {
42-
// Don't load/render anything in still mode until explicitly requested.
43-
if (mode != MapMode::Continuous && !stillImageRequest) {
44-
return;
45+
if (mode == MapMode::Continuous) {
46+
actor.invoke(&Map::Impl::updateInternal, Clock::now());
47+
} else if (stillImageRequest) {
48+
updateInternal(Clock::time_point::max());
4549
}
50+
}
4651

47-
TimePoint timePoint = mode == MapMode::Continuous ? Clock::now() : Clock::time_point::max();
52+
void Map::Impl::updateInternal(TimePoint timePoint) {
53+
// Don't load/render anything in still mode until explicitly requested.
54+
assert(mode == MapMode::Continuous || stillImageRequest);
4855

4956
transform.updateTransitions(timePoint);
5057

src/mbgl/map/map_impl.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <mbgl/actor/actor_ref.hpp>
34
#include <mbgl/annotation/annotation_manager.hpp>
45
#include <mbgl/map/map.hpp>
56
#include <mbgl/map/map_observer.hpp>
@@ -51,6 +52,9 @@ class Map::Impl : public style::Observer, public RendererObserver {
5152
// Map
5253
void jumpTo(const CameraOptions&);
5354

55+
// Internal
56+
void updateInternal(TimePoint timePoint);
57+
5458
MapObserver& observer;
5559
RendererFrontend& rendererFrontend;
5660

@@ -74,6 +78,8 @@ class Map::Impl : public style::Observer, public RendererObserver {
7478
bool loading = false;
7579
bool rendererFullyLoaded;
7680
std::unique_ptr<StillImageRequest> stillImageRequest;
81+
std::shared_ptr<Mailbox> mailbox;
82+
ActorRef<Map::Impl> actor;
7783
};
7884

7985
} // namespace mbgl

0 commit comments

Comments
 (0)