diff --git a/MapboxGLAndroidSDK/src/cpp/style/sources/custom_geometry_source.cpp b/MapboxGLAndroidSDK/src/cpp/style/sources/custom_geometry_source.cpp index e43bf8fa1..b0deacfa5 100644 --- a/MapboxGLAndroidSDK/src/cpp/style/sources/custom_geometry_source.cpp +++ b/MapboxGLAndroidSDK/src/cpp/style/sources/custom_geometry_source.cpp @@ -110,10 +110,10 @@ namespace android { static auto& javaClass = jni::Class::Singleton(*_env); static auto releaseThreads = javaClass.GetMethod(*_env, "releaseThreads"); - assert(javaPeer); - - auto peer = jni::Cast(*_env, javaClass, javaPeer); - peer.Call(*_env, releaseThreads); + if(javaPeer) { + auto peer = jni::Cast(*_env, javaClass, javaPeer); + peer.Call(*_env, releaseThreads); + } }; bool CustomGeometrySource::isCancelled(jni::jint z, diff --git a/MapboxGLAndroidSDK/src/cpp/style/sources/source.cpp b/MapboxGLAndroidSDK/src/cpp/style/sources/source.cpp index 39f352a84..2b0b4fb51 100644 --- a/MapboxGLAndroidSDK/src/cpp/style/sources/source.cpp +++ b/MapboxGLAndroidSDK/src/cpp/style/sources/source.cpp @@ -76,6 +76,10 @@ static std::unique_ptr createSourcePeer(jni::JNIEnv& env, } Source::~Source() { + if (ownedSource) { + ownedSource.reset(); + ownedSource.release(); + } // Before being added to a map, the Java peer owns this C++ peer and cleans // up after itself correctly through the jni native peer bindings. // After being added to the map, the ownership is flipped and the C++ peer has a strong reference @@ -209,7 +213,7 @@ static std::unique_ptr createSourcePeer(jni::JNIEnv& env, // Release the strong reference to the java peer assert(javaPeer); - javaPeer.release(); + javaPeer.reset(); rendererFrontend = nullptr; }