summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Rex <julian.rex@mapbox.com>2018-04-07 01:03:11 -0400
committerJulian Rex <julian.rex@mapbox.com>2018-05-21 13:05:04 -0400
commit4418c141e903abc1e926b164cbdfb329c3138685 (patch)
tree56b26843fa36153f97663380574bc30c93b7de31
parent33a5b48367495cf458ad4923d641cb2495e6dbd3 (diff)
downloadqtlocation-mapboxgl-4418c141e903abc1e926b164cbdfb329c3138685.tar.gz
Added comments to clarify changes.
-rw-r--r--src/mbgl/map/transform.cpp41
1 files changed, 37 insertions, 4 deletions
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index 07e54d33bd..9ed10eeac0 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -595,16 +595,35 @@ void Transform::startTransition(const CameraOptions& camera,
}
observer.onCameraIsChanging();
} else {
+
+ // Use a temporary function to ensure that the transitionFinishFn
+ // lambda is only called once at the end of a transition.
+ //
+ // This addresses the symptons of https://github.com/mapbox/mapbox-gl-native/issues/11180
+ // where setting a shape source to nil (or similar) in the
+ // `onCameraDidChange` observer function causes `Map::Impl::onUpdate()`
+ // to be called which in turn calls this lambda (before the current
+ // iteration has completed), leading to an infinite loop.
+ //
+ // By using a temporary, and clearing transitionFinishFn we stop this
+ // recursion. (However it does not address the underlying problem of
+ // `onSourceChanged()` called from observer methods triggering
+ // `Map::Impl::onUpdate()`)
+ //
+ // This is now addressed at an earlier stage by a similar change
+ // below in `Transform::updateTransitions()`.
+
auto finish = transitionFinishFn;
transitionFinishFn = nullptr;
-
- // This callback gets destroyed here,
- // we can only return after this point.
transitionFrameFn = nullptr;
- if (finish)
+ if (finish) {
finish();
+ }
+
+ // This callback gets destroyed here,
+ // we can only return after this point.
}
};
@@ -628,6 +647,20 @@ bool Transform::inTransition() const {
}
void Transform::updateTransitions(const TimePoint& now) {
+ // Use a temporary function to ensure that the transitionFrameFn lambda is
+ // called only once per update.
+ //
+ // This addresses the symptons of https://github.com/mapbox/mapbox-gl-native/issues/11180
+ // where setting a shape source to nil (or similar) in the `onCameraIsChanging`
+ // observer function causes `Map::Impl::onUpdate()` to be called which
+ // in turn calls this function (before the current iteration has completed),
+ // leading to an infinite loop.
+ //
+ // By temporarily nulling the `transitionFrameFn` (and then restoring it
+ // after the temporary has been called) we stop this recursion. (However it
+ // does not address the underlying problem of `onSourceChanged()`
+ // called from observer methods triggering `Map::Impl::onUpdate()`)
+
auto transition = transitionFrameFn;
transitionFrameFn = nullptr;