From 10b503eabfb3c0c53b9a4bef8849f2511ae0ac16 Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Thu, 10 Mar 2016 14:03:04 -0300 Subject: [android] Attach thread on the RunLoop Needed because Looper could be used by Java and it would crash complaining that we didn't detach otherwise. --- platform/android/src/run_loop.cpp | 7 +++++++ platform/android/src/run_loop_impl.hpp | 5 +++++ 2 files changed, 12 insertions(+) (limited to 'platform/android') diff --git a/platform/android/src/run_loop.cpp b/platform/android/src/run_loop.cpp index b3b1fd2d95..e05d27a088 100644 --- a/platform/android/src/run_loop.cpp +++ b/platform/android/src/run_loop.cpp @@ -1,5 +1,6 @@ #include "run_loop_impl.hpp" +#include #include #include @@ -74,6 +75,9 @@ RunLoop* RunLoop::Get() { } RunLoop::RunLoop(Type) : impl(std::make_unique()) { + using namespace mbgl::android; + impl->detach = attach_jni_thread(theJVM, &impl->env, ThreadContext::getName()); + impl->loop = ALooper_prepare(0); assert(impl->loop); @@ -86,6 +90,9 @@ RunLoop::~RunLoop() { current.set(nullptr); ALooper_release(impl->loop); + + using namespace mbgl::android; + detach_jni_thread(theJVM, &impl->env, impl->detach); } LOOP_HANDLE RunLoop::getLoopHandle() { diff --git a/platform/android/src/run_loop_impl.hpp b/platform/android/src/run_loop_impl.hpp index a96ea1a1c9..2dd912994f 100644 --- a/platform/android/src/run_loop_impl.hpp +++ b/platform/android/src/run_loop_impl.hpp @@ -1,5 +1,7 @@ #pragma once +#include "jni.hpp" + #include #include @@ -34,6 +36,9 @@ public: private: friend RunLoop; + JNIEnv *env = nullptr; + bool detach = false; + ALooper* loop = nullptr; std::atomic running; -- cgit v1.2.1