summaryrefslogtreecommitdiff
path: root/platform/android
diff options
context:
space:
mode:
authorŁukasz Paczos <lukas.paczos@gmail.com>2018-04-30 18:32:37 +0200
committerTobrun <tobrun@mapbox.com>2018-05-02 12:20:45 +0200
commitcf4b4e728c26e444514f6ba792c207692350eb57 (patch)
tree16911ecd17c539cf9298cd082d2adce30f30c593 /platform/android
parenta6d70c2db73daf6b490be976b86a1c826a2edc3e (diff)
downloadqtlocation-mapboxgl-cf4b4e728c26e444514f6ba792c207692350eb57.tar.gz
[android] - checking is renderer is not destroyed before delivering the snapshot
Diffstat (limited to 'platform/android')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java8
-rw-r--r--platform/android/src/map_renderer.cpp23
-rw-r--r--platform/android/src/map_renderer.hpp6
3 files changed, 10 insertions, 27 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
index f1c70325a0..fcee5bd179 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
@@ -37,11 +37,11 @@ public abstract class MapRenderer implements MapRendererScheduler {
}
public void onPause() {
- nativeOnPause();
+ // Implement if needed
}
public void onResume() {
- nativeOnResume();
+ // Implement if needed
}
public void onStop() {
@@ -124,10 +124,6 @@ public abstract class MapRenderer implements MapRendererScheduler {
private native void nativeRender();
- private native void nativeOnResume();
-
- private native void nativeOnPause();
-
private long frames;
private long timeElapsed;
diff --git a/platform/android/src/map_renderer.cpp b/platform/android/src/map_renderer.cpp
index f7e16b7091..ba6fdc63b0 100644
--- a/platform/android/src/map_renderer.cpp
+++ b/platform/android/src/map_renderer.cpp
@@ -29,6 +29,7 @@ MapRenderer::MapRenderer(jni::JNIEnv& _env, jni::Object<MapRenderer> obj,
MapRenderer::~MapRenderer() = default;
void MapRenderer::reset() {
+ destroyed = true;
// Make sure to destroy the renderer on the GL Thread
auto self = ActorRef<MapRenderer>(*this, mailbox);
self.ask(&MapRenderer::resetRenderer).wait();
@@ -88,8 +89,10 @@ void MapRenderer::requestSnapshot(SnapshotCallback callback) {
self.invoke(
&MapRenderer::scheduleSnapshot,
std::make_unique<SnapshotCallback>([&, callback=std::move(callback), runloop=util::RunLoop::Get()](PremultipliedImage image) {
- runloop->invoke([callback=std::move(callback), image=std::move(image)]() mutable {
- callback(std::move(image));
+ runloop->invoke([callback=std::move(callback), image=std::move(image), renderer=std::move(this)]() mutable {
+ if (renderer && !renderer->destroyed) {
+ callback(std::move(image));
+ }
});
snapshotCallback.reset();
})
@@ -136,7 +139,7 @@ void MapRenderer::render(JNIEnv&) {
renderer->render(*params);
// Deliver the snapshot if requested
- if (snapshotCallback && !paused) {
+ if (snapshotCallback) {
snapshotCallback->operator()(backend->readFramebuffer());
snapshotCallback.reset();
}
@@ -174,14 +177,6 @@ void MapRenderer::onSurfaceChanged(JNIEnv&, jint width, jint height) {
requestRender();
}
-void MapRenderer::onResume(JNIEnv&) {
- paused = false;
-}
-
-void MapRenderer::onPause(JNIEnv&) {
- paused = true;
-}
-
// Static methods //
jni::Class<MapRenderer> MapRenderer::javaClass;
@@ -200,11 +195,7 @@ void MapRenderer::registerNative(jni::JNIEnv& env) {
METHOD(&MapRenderer::onSurfaceCreated,
"nativeOnSurfaceCreated"),
METHOD(&MapRenderer::onSurfaceChanged,
- "nativeOnSurfaceChanged"),
- METHOD(&MapRenderer::onResume,
- "nativeOnResume"),
- METHOD(&MapRenderer::onPause,
- "nativeOnPause"));
+ "nativeOnSurfaceChanged"));
}
MapRenderer& MapRenderer::getNativePeer(JNIEnv& env, jni::Object<MapRenderer> jObject) {
diff --git a/platform/android/src/map_renderer.hpp b/platform/android/src/map_renderer.hpp
index 5fb5ef1a61..97d2db4a91 100644
--- a/platform/android/src/map_renderer.hpp
+++ b/platform/android/src/map_renderer.hpp
@@ -98,10 +98,6 @@ private:
void onSurfaceChanged(JNIEnv&, jint width, jint height);
- void onResume(JNIEnv&);
-
- void onPause(JNIEnv&);
-
private:
GenericUniqueWeakObject<MapRenderer> javaPeer;
@@ -124,7 +120,7 @@ private:
std::mutex updateMutex;
bool framebufferSizeChanged = false;
- std::atomic<bool> paused {false};
+ std::atomic<bool> destroyed {false};
std::unique_ptr<SnapshotCallback> snapshotCallback;
};