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

Commit

Permalink
[android] renderer frontend - add mutex to guard update parameters
Browse files Browse the repository at this point in the history
- solves a bunch of crashes
- solves the flikkering issue when zooming with pinch gestures
  • Loading branch information
ivovandongen committed Sep 8, 2017
1 parent 82f03a9 commit 117b899
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 16 additions & 3 deletions platform/android/src/android_renderer_frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,27 @@ void AndroidRendererFrontend::setObserver(RendererObserver& observer) {
}

void AndroidRendererFrontend::update(std::shared_ptr<UpdateParameters> params) {
updateParameters = std::move(params);
{
// Lock on the parameters
std::lock_guard<std::mutex> lock(updateMutex);
updateParameters = std::move(params);
}
asyncInvalidate.send();
}

// Called on OpenGL thread
void AndroidRendererFrontend::render() {
assert (glThread);
if (!updateParameters) return;

std::shared_ptr<UpdateParameters> params;
{
// Lock on the parameters
std::unique_lock<std::mutex> lock(updateMutex);
if (!updateParameters) return;

// Hold on to the update parameters during render
params = updateParameters;
}

// Process the gl thread mailbox
glThread->process();
Expand All @@ -121,7 +134,7 @@ void AndroidRendererFrontend::render() {
framebufferSizeChanged = false;
}

glThread->renderer->render(*updateParameters);
glThread->renderer->render(*params);
}

void AndroidRendererFrontend::onLowMemory() {
Expand Down
4 changes: 4 additions & 0 deletions platform/android/src/android_renderer_frontend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ class AndroidRendererFrontend : public RendererFrontend {
std::unique_ptr<AndroidRendererBackend> backend;
std::unique_ptr<AndroidGLThread> glThread;
std::unique_ptr<RendererObserver> rendererObserver;

std::mutex updateMutex;
std::shared_ptr<UpdateParameters> updateParameters;


util::AsyncTask asyncInvalidate;

util::RunLoop* mapRunLoop;
Expand Down

0 comments on commit 117b899

Please sign in to comment.