Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Check if renderer is not destroyed before delivering snapshot #11800

Merged
merged 1 commit into from
May 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public void onStart() {
}

public void onPause() {
nativeOnPause();
// Implement if needed
}

public void onResume() {
nativeOnResume();
// Implement if needed
}

public void onStop() {
Expand Down Expand Up @@ -124,10 +124,6 @@ private native void nativeInitialize(MapRenderer self,

private native void nativeRender();

private native void nativeOnResume();

private native void nativeOnPause();

private long frames;
private long timeElapsed;

Expand Down
23 changes: 7 additions & 16 deletions platform/android/src/map_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
})
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
6 changes: 1 addition & 5 deletions platform/android/src/map_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ class MapRenderer : public Scheduler {

void onSurfaceChanged(JNIEnv&, jint width, jint height);

void onResume(JNIEnv&);

void onPause(JNIEnv&);

private:
GenericUniqueWeakObject<MapRenderer> javaPeer;

Expand All @@ -124,7 +120,7 @@ class MapRenderer : public Scheduler {
std::mutex updateMutex;

bool framebufferSizeChanged = false;
std::atomic<bool> paused {false};
std::atomic<bool> destroyed {false};

std::unique_ptr<SnapshotCallback> snapshotCallback;
};
Expand Down