diff options
author | Tobrun Van Nuland <tobrun.van.nuland@gmail.com> | 2017-09-13 11:49:13 +0200 |
---|---|---|
committer | Tobrun Van Nuland <tobrun.van.nuland@gmail.com> | 2017-09-13 17:10:45 +0200 |
commit | e48ed3a22219b35bdd70a299fc56771573a2a842 (patch) | |
tree | c344d9ae79e1278f1161ba0ca08eb76997db4de9 | |
parent | 366a69785a2fffd0713897f53647cf18b7a0c645 (diff) | |
download | qtlocation-mapboxgl-upstream/9981-jni-null-check.tar.gz |
[android] - validate destroyed state for c++ callbacks to javaupstream/9981-jni-null-check
-rwxr-xr-x | platform/android/src/native_map_view.cpp | 20 | ||||
-rwxr-xr-x | platform/android/src/native_map_view.hpp | 1 |
2 files changed, 13 insertions, 8 deletions
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index d859d929d3..910ebc676e 100755 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -98,6 +98,8 @@ NativeMapView::NativeMapView(jni::JNIEnv& _env, * Called through NativeMapView#destroy() */ NativeMapView::~NativeMapView() { + destroyed = true; + _terminateContext(); _destroySurface(); _terminateDisplay(); @@ -176,9 +178,11 @@ void NativeMapView::deactivate() { * May be called from any thread */ void NativeMapView::invalidate() { - android::UniqueEnv _env = android::AttachEnv(); - static auto onInvalidate = javaClass.GetMethod<void ()>(*_env, "onInvalidate"); - javaPeer->Call(*_env, onInvalidate); + if (!destroyed) { + android::UniqueEnv _env = android::AttachEnv(); + static auto onInvalidate = javaClass.GetMethod<void ()>(*_env, "onInvalidate"); + javaPeer->Call(*_env, onInvalidate); + } } /** @@ -187,11 +191,11 @@ void NativeMapView::invalidate() { * May be called from any thread */ void NativeMapView::notifyMapChange(mbgl::MapChange change) { - assert(vm != nullptr); - - android::UniqueEnv _env = android::AttachEnv(); - static auto onMapChanged = javaClass.GetMethod<void (int)>(*_env, "onMapChanged"); - javaPeer->Call(*_env, onMapChanged, (int) change); + if (!destroyed) { + android::UniqueEnv _env = android::AttachEnv(); + static auto onMapChanged = javaClass.GetMethod<void (int)>(*_env, "onMapChanged"); + javaPeer->Call(*_env, onMapChanged, (int) change); + } } void NativeMapView::onCameraWillChange(MapObserver::CameraChangeMode mode) { diff --git a/platform/android/src/native_map_view.hpp b/platform/android/src/native_map_view.hpp index 24c88f4e3f..08c02087d0 100755 --- a/platform/android/src/native_map_view.hpp +++ b/platform/android/src/native_map_view.hpp @@ -315,6 +315,7 @@ private: bool snapshot = false; bool firstRender = true; double fps = 0.0; + std::atomic<bool> destroyed = {false}; // Minimum texture size according to OpenGL ES 2.0 specification. int width = 64; |