[android] reset renderer on the GL thread when map is destroyed

- ensures cleanup of resources on the right thread
This commit is contained in:
Ivo van Dongen
2017-09-18 13:40:26 +03:00
committed by Ivo van Dongen
parent 8b9794b1a7
commit 18bb6da109
2 changed files with 11 additions and 2 deletions

View File

@@ -27,8 +27,9 @@ MapRenderer::MapRenderer(jni::JNIEnv& _env, jni::Object<MapRenderer> obj,
MapRenderer::~MapRenderer() = default;
void MapRenderer::reset() {
assert (renderer);
renderer.reset();
// Make sure to destroy the renderer on the GL Thread
auto self = ActorRef<MapRenderer>(*this, mailbox);
self.ask(&MapRenderer::resetRenderer).wait();
// Lock to make sure there is no concurrent initialisation on the gl thread
std::lock_guard<std::mutex> lock(initialisationMutex);
@@ -91,6 +92,11 @@ void MapRenderer::requestSnapshot(SnapshotCallback callback) {
// Called on OpenGL thread //
void MapRenderer::resetRenderer() {
assert (renderer);
renderer.reset();
}
void MapRenderer::scheduleSnapshot(std::unique_ptr<SnapshotCallback> callback) {
snapshotCallback = std::move(callback);
requestRender();