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

Commit a53d381

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 6b8df34 commit a53d381

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/mbgl/map/map_impl.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <mbgl/storage/file_source.hpp>
55
#include <mbgl/style/style_impl.hpp>
66
#include <mbgl/util/exception.hpp>
7+
#include <mbgl/actor/scheduler.hpp>
78

89
namespace mbgl {
910

@@ -19,7 +20,9 @@ Map::Impl::Impl(RendererFrontend& frontend_,
1920
crossSourceCollisions(mapOptions.crossSourceCollisions()),
2021
fileSource(std::move(fileSource_)),
2122
style(std::make_unique<style::Style>(*fileSource, pixelRatio)),
22-
annotationManager(*style) {
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
@@ -12,6 +12,7 @@
1212
#include <mbgl/style/source.hpp>
1313
#include <mbgl/style/style.hpp>
1414
#include <mbgl/util/size.hpp>
15+
#include <mbgl/actor/actor_ref.hpp>
1516

1617
namespace mbgl {
1718

@@ -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)