diff options
author | Łukasz Paczos <lukas.paczos@gmail.com> | 2019-08-16 14:54:36 +0200 |
---|---|---|
committer | Łukasz Paczos <lukasz.paczos@mapbox.com> | 2019-08-19 10:22:45 +0200 |
commit | bf34fb01900cb513dcc0fa5728f06504b62a7e26 (patch) | |
tree | 341d5fb5a765e636776cfcbd49826fe6a4e849cf /platform | |
parent | 98dbed241b94ac78dde001d58a3598ec01535bb6 (diff) | |
download | qtlocation-mapboxgl-bf34fb01900cb513dcc0fa5728f06504b62a7e26.tar.gz |
[android] check if the CustomGeometrySource's java peer is valid when the thread is shutting down
Diffstat (limited to 'platform')
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); |