summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2016-01-14 18:40:51 +0200
committerThiago Marcos P. Santos <thiago@mapbox.com>2016-01-14 18:59:38 +0200
commitf9574e350c9634b5a4f9849fdfe66fbd84747b12 (patch)
tree6b91685dc65e673874078297d000e93ed25ca860 /src
parent4515bb00c0fd6c90050cf3befc4e848aaa7362c0 (diff)
downloadqtlocation-mapboxgl-f9574e350c9634b5a4f9849fdfe66fbd84747b12.tar.gz
[core] Fix crash on transitionFrameFn callback
This is a tricky one: We are storing a lambda at the member variable `transitionFrameFn` and capturing `this` at this lambda function. At some point when running the callback, we set `transitionFrameFn` to `nullptr`, effectively destroying the callback that is being executed. After this point, `this` is no longer valid, as the memory gets cleared and it might point to the correct location (or not). That is why it works on some compilers but not on g++ 5.3.1. Touching any `this->[smth]` is undefined after that. The fix is just move `transitionFrameFn = nullptr` to the last thing we do on the callback. This behaves similarly to calling `delete this` on a class method.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/transform.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index b38520b128..98b0804482 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -539,8 +539,11 @@ void Transform::startTransition(const CameraOptions& camera,
view.notifyMapChange(MapChangeRegionIsChanging);
} else {
transitionFinishFn();
- transitionFrameFn = nullptr;
transitionFinishFn = nullptr;
+
+ // This callback gets destroyed here,
+ // we can only return after this point.
+ transitionFrameFn = nullptr;
}
return result;
};