summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobrun <tobrun.van.nuland@gmail.com>2018-12-12 13:02:14 +0100
committerTobrun <tobrun.van.nuland@gmail.com>2018-12-12 13:02:14 +0100
commit5f579cd5e3629a05c7bddc8ba2596e6a84ca629b (patch)
tree4c65ce4a43948f57fc20031fe0633102e95aa3b0
parentbd4b5ffb165e7bcd789f613d74d64dcd9af4c892 (diff)
downloadqtlocation-mapboxgl-upstream/tvn-null-check-weakreference.tar.gz
[androd] - add weak references checks to all jni callbacksupstream/tvn-null-check-weakreference
-rw-r--r--platform/android/src/map_renderer.cpp10
-rwxr-xr-xplatform/android/src/native_map_view.cpp10
-rw-r--r--platform/android/src/snapshotter/map_snapshotter.cpp10
3 files changed, 24 insertions, 6 deletions
diff --git a/platform/android/src/map_renderer.cpp b/platform/android/src/map_renderer.cpp
index 13790c4544..e9eb82864d 100644
--- a/platform/android/src/map_renderer.cpp
+++ b/platform/android/src/map_renderer.cpp
@@ -58,7 +58,10 @@ void MapRenderer::schedule(std::weak_ptr<Mailbox> scheduled) {
static auto& javaClass = jni::Class<MapRenderer>::Singleton(*_env);
static auto queueEvent = javaClass.GetMethod<void(
jni::Object<MapRendererRunnable>)>(*_env, "queueEvent");
- javaPeer.get(*_env).Call(*_env, queueEvent, peer);
+ auto weakReference = javaPeer.get(*_env);
+ if (weakReference) {
+ weakReference.Call(*_env, queueEvent, peer);
+ }
// Release the c++ peer as it will be destroyed on GC of the Java Peer
runnable.release();
@@ -68,7 +71,10 @@ void MapRenderer::requestRender() {
android::UniqueEnv _env = android::AttachEnv();
static auto& javaClass = jni::Class<MapRenderer>::Singleton(*_env);
static auto onInvalidate = javaClass.GetMethod<void()>(*_env, "requestRender");
- javaPeer.get(*_env).Call(*_env, onInvalidate);
+ auto weakReference = javaPeer.get(*_env);
+ if (weakReference) {
+ weakReference.Call(*_env, onInvalidate);
+ }
}
void MapRenderer::update(std::shared_ptr<UpdateParameters> params) {
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp
index 872022c8e4..c76b5c2610 100755
--- a/platform/android/src/native_map_view.cpp
+++ b/platform/android/src/native_map_view.cpp
@@ -225,7 +225,10 @@ void NativeMapView::onDidBecomeIdle() {
android::UniqueEnv _env = android::AttachEnv();
static auto& javaClass = jni::Class<NativeMapView>::Singleton(*_env);
static auto onDidBecomeIdle = javaClass.GetMethod<void ()>(*_env, "onDidBecomeIdle");
- javaPeer.get(*_env).Call(*_env, onDidBecomeIdle);
+ auto weakReference = javaPeer.get(*_env);
+ if (weakReference) {
+ weakReference.Call(*_env, onDidBecomeIdle);
+ }
}
void NativeMapView::onDidFinishLoadingStyle() {
@@ -501,7 +504,10 @@ void NativeMapView::scheduleSnapshot(jni::JNIEnv&) {
// invoke Mapview#OnSnapshotReady
static auto& javaClass = jni::Class<NativeMapView>::Singleton(*_env);
static auto onSnapshotReady = javaClass.GetMethod<void (jni::Object<Bitmap>)>(*_env, "onSnapshotReady");
- javaPeer.get(*_env).Call(*_env, onSnapshotReady, bitmap);
+ auto weakReference = javaPeer.get(*_env);
+ if (weakReference) {
+ weakReference.Call(*_env, onSnapshotReady, bitmap);
+ }
});
}
diff --git a/platform/android/src/snapshotter/map_snapshotter.cpp b/platform/android/src/snapshotter/map_snapshotter.cpp
index a5f44a1d4c..8eb1d02605 100644
--- a/platform/android/src/snapshotter/map_snapshotter.cpp
+++ b/platform/android/src/snapshotter/map_snapshotter.cpp
@@ -89,14 +89,20 @@ void MapSnapshotter::start(JNIEnv& env) {
if (err) {
// error handler callback
static auto onSnapshotFailed = javaClass.GetMethod<void (jni::String)>(*_env, "onSnapshotFailed");
- javaPeer.get(*_env).Call(*_env, onSnapshotFailed, jni::Make<jni::String>(*_env, util::toString(err)));
+ auto weakReference = javaPeer.get(*_env);
+ if (weakReference) {
+ weakReference.Call(*_env, onSnapshotFailed, jni::Make<jni::String>(*_env, util::toString(err)));
+ }
} else {
// Create the wrapper
auto mapSnapshot = android::MapSnapshot::New(*_env, std::move(image), pixelRatio, attributions, showLogo, pointForFn, latLngForFn);
// invoke callback
static auto onSnapshotReady = javaClass.GetMethod<void (jni::Object<MapSnapshot>)>(*_env, "onSnapshotReady");
- javaPeer.get(*_env).Call(*_env, onSnapshotReady, mapSnapshot);
+ auto weakReference = javaPeer.get(*_env);
+ if (weakReference) {
+ weakReference.Call(*_env, onSnapshotReady, mapSnapshot);
+ }
}
deactivateFilesource(*_env);