[androd] - add weak references checks to all jni callbacks

This commit is contained in:
Tobrun
2018-12-12 13:02:14 +01:00
committed by Tobrun
parent e94a7fc405
commit aedbdc21d0
3 changed files with 24 additions and 6 deletions

View File

@@ -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);