[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.
This commit is contained in:
Thiago Marcos P. Santos
2016-01-14 18:40:51 +02:00
parent 4515bb00c0
commit f9574e350c

View File

@@ -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;
};