From e48ed3a22219b35bdd70a299fc56771573a2a842 Mon Sep 17 00:00:00 2001 From: Tobrun Van Nuland Date: Wed, 13 Sep 2017 11:49:13 +0200 Subject: [android] - validate destroyed state for c++ callbacks to java --- platform/android/src/native_map_view.cpp | 20 ++++++++++++-------- 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(*_env, "onInvalidate"); - javaPeer->Call(*_env, onInvalidate); + if (!destroyed) { + android::UniqueEnv _env = android::AttachEnv(); + static auto onInvalidate = javaClass.GetMethod(*_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(*_env, "onMapChanged"); - javaPeer->Call(*_env, onMapChanged, (int) change); + if (!destroyed) { + android::UniqueEnv _env = android::AttachEnv(); + static auto onMapChanged = javaClass.GetMethod(*_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 destroyed = {false}; // Minimum texture size according to OpenGL ES 2.0 specification. int width = 64; -- cgit v1.2.1