diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/map_renderer.cpp b/platform/android/MapboxGLAndroidSDK/src/cpp/map_renderer.cpp index 07a66f22695..dfd50158810 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/map_renderer.cpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/map_renderer.cpp @@ -22,9 +22,12 @@ MapRenderer::MapRenderer(jni::JNIEnv& _env, pixelRatio(pixelRatio_), localIdeographFontFamily(localIdeographFontFamily_ ? jni::Make(_env, localIdeographFontFamily_) : optional{}), - mailboxData(this) {} + threadPool(Scheduler::GetBackground()), + mailboxData(this), + backend(std::make_unique()) {} -MapRenderer::MailboxData::MailboxData(Scheduler* scheduler_) : scheduler(scheduler_) { +MapRenderer::MailboxData::MailboxData(Scheduler* scheduler_) + : scheduler(scheduler_) { assert(scheduler); } @@ -143,7 +146,7 @@ void MapRenderer::requestSnapshot(SnapshotCallback callback) { void MapRenderer::resetRenderer() { renderer.reset(); - backend.reset(); + backend = std::make_unique(); } void MapRenderer::scheduleSnapshot(std::unique_ptr callback) { @@ -165,6 +168,7 @@ void MapRenderer::render(JNIEnv&) { } // Activate the backend + assert(backend); gfx::BackendScope backendGuard { *backend }; // Ensure that the "current" scheduler on the render thread is @@ -190,6 +194,7 @@ void MapRenderer::onSurfaceCreated(JNIEnv&) { std::lock_guard lock(initialisationMutex); // The GL context is already active if get a new surface. + assert(backend); gfx::BackendScope backendGuard { *backend, gfx::BackendScope::ScopeType::Implicit }; // The android system will have already destroyed the underlying diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/map_renderer.hpp b/platform/android/MapboxGLAndroidSDK/src/cpp/map_renderer.hpp index e37d37cfc89..68b6788f2c9 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/map_renderer.hpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/map_renderer.hpp @@ -114,7 +114,7 @@ class MapRenderer : public Scheduler { float pixelRatio; optional localIdeographFontFamily; - std::shared_ptr threadPool; + std::shared_ptr threadPool; const MailboxData mailboxData; std::mutex initialisationMutex;