summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorŁukasz Paczos <lukas.paczos@gmail.com>2019-08-16 14:54:36 +0200
committerŁukasz Paczos <lukas.paczos@gmail.com>2019-08-16 14:54:36 +0200
commit1e9ea4dc548cc48a174b487a22c12bd94362e246 (patch)
treea8e22fb6ba9e0725a9847464d8d4680567a4fe47
parent0f34eb7b253e83b8c4aef7ed6c83cd7b3801fa4c (diff)
downloadqtlocation-mapboxgl-upstream/lp-cgs-peer-reference-12551.tar.gz
[android] check if the CustomGeometrySource's java peer is valid when the thread is shutting downupstream/lp-cgs-peer-reference-12551
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CustomGeometrySourceTest.kt11
-rw-r--r--platform/android/src/style/sources/custom_geometry_source.cpp14
2 files changed, 15 insertions, 10 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CustomGeometrySourceTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CustomGeometrySourceTest.kt
index a6238ebf14..9c2eb3df81 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CustomGeometrySourceTest.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CustomGeometrySourceTest.kt
@@ -2,7 +2,6 @@ package com.mapbox.mapboxsdk.testapp.style
import android.support.test.espresso.Espresso.onView
import android.support.test.espresso.matcher.ViewMatchers.isRoot
-import com.mapbox.mapboxsdk.style.sources.CustomGeometrySource
import com.mapbox.mapboxsdk.style.sources.CustomGeometrySource.THREAD_POOL_LIMIT
import com.mapbox.mapboxsdk.style.sources.CustomGeometrySource.THREAD_PREFIX
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke
@@ -15,7 +14,6 @@ import com.mapbox.mapboxsdk.testapp.activity.style.GridSourceActivity.ID_GRID_LA
import com.mapbox.mapboxsdk.testapp.activity.style.GridSourceActivity.ID_GRID_SOURCE
import com.mapbox.mapboxsdk.testapp.utils.TestingAsyncUtils
import org.junit.Assert
-import org.junit.Ignore
import org.junit.Test
class CustomGeometrySourceTest : BaseTest() {
@@ -23,7 +21,6 @@ class CustomGeometrySourceTest : BaseTest() {
override fun getActivityClass(): Class<*> = GridSourceActivity::class.java
@Test
- @Ignore
fun sourceNotLeakingThreadsTest() {
validateTestSetup()
WaitAction.invoke(4000)
@@ -38,7 +35,6 @@ class CustomGeometrySourceTest : BaseTest() {
}
@Test
- @Ignore
fun threadsShutdownWhenSourceRemovedTest() {
validateTestSetup()
invoke(mapboxMap) { uiController, mapboxMap ->
@@ -48,13 +44,12 @@ class CustomGeometrySourceTest : BaseTest() {
TestingAsyncUtils.waitForLayer(uiController, mapView)
Assert.assertTrue("There should be no threads running when the source is removed.",
Thread.getAllStackTraces().keys.filter {
- it.name.startsWith(CustomGeometrySource.THREAD_PREFIX)
+ it.name.startsWith(THREAD_PREFIX)
}.count() == 0)
}
}
@Test
- @Ignore
fun threadsRestartedWhenSourceReAddedTest() {
validateTestSetup()
invoke(mapboxMap) { uiController, mapboxMap ->
@@ -67,8 +62,8 @@ class CustomGeometrySourceTest : BaseTest() {
TestingAsyncUtils.waitForLayer(uiController, mapView)
Assert.assertTrue("Threads should be restarted when the source is re-added to the map.",
Thread.getAllStackTraces().keys.filter {
- it.name.startsWith(CustomGeometrySource.THREAD_PREFIX)
- }.count() == CustomGeometrySource.THREAD_POOL_LIMIT)
+ it.name.startsWith(THREAD_PREFIX)
+ }.count() == THREAD_POOL_LIMIT)
}
}
} \ No newline at end of file
diff --git a/platform/android/src/style/sources/custom_geometry_source.cpp b/platform/android/src/style/sources/custom_geometry_source.cpp
index 057f5c99ba..dccca4cf46 100644
--- a/platform/android/src/style/sources/custom_geometry_source.cpp
+++ b/platform/android/src/style/sources/custom_geometry_source.cpp
@@ -65,7 +65,12 @@ namespace android {
static auto& javaClass = jni::Class<CustomGeometrySource>::Singleton(*_env);
static auto fetchTile = javaClass.GetMethod<void (jni::jint, jni::jint, jni::jint)>(*_env, "fetchTile");
- assert(javaPeer);
+ // The source is removed on the main thread, but it still exists on the Render thread until the frame is complete.
+ // This might cause fetchTile/cancelTile invocations when the Java thread is shutting down and the peer has already been released.
+ // See https://github.com/mapbox/mapbox-gl-native/issues/12551.
+ if(!javaPeer) {
+ return;
+ }
auto peer = jni::Cast(*_env, javaClass, javaPeer);
peer.Call(*_env, fetchTile, (int)tileID.z, (int)tileID.x, (int)tileID.y);
@@ -77,7 +82,12 @@ namespace android {
static auto& javaClass = jni::Class<CustomGeometrySource>::Singleton(*_env);
static auto cancelTile = javaClass.GetMethod<void (jni::jint, jni::jint, jni::jint)>(*_env, "cancelTile");
- assert(javaPeer);
+ // The source is removed on the main thread, but it still exists on the Render thread until the frame is complete.
+ // This might cause fetchTile/cancelTile invocations when the Java thread is shutting down and the peer has already been released.
+ // See https://github.com/mapbox/mapbox-gl-native/issues/12551.
+ if(!javaPeer) {
+ return;
+ }
auto peer = jni::Cast(*_env, javaClass, javaPeer);
peer.Call(*_env, cancelTile, (int)tileID.z, (int)tileID.x, (int)tileID.y);