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

Commit

Permalink
[android] - checking is renderer is not destroyed before delivering t…
Browse files Browse the repository at this point in the history
…he snapshot
  • Loading branch information
LukasPaczos authored and tobrun committed May 2, 2018
1 parent a6d70c2 commit cf4b4e7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 27 deletions.
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

0 comments on commit cf4b4e7

Please sign in to comment.