Skip to content

Commit

Permalink
Fix null-pointer dereference MapRenderer Android (#2938)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimSylvester authored Oct 15, 2024
1 parent 79bb443 commit b94110a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions platform/android/MapboxGLAndroidSDK/src/cpp/map_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ MapRenderer::MapRenderer(jni::JNIEnv& _env,
pixelRatio(pixelRatio_),
localIdeographFontFamily(localIdeographFontFamily_ ? jni::Make<std::string>(_env, localIdeographFontFamily_)
: optional<std::string>{}),
mailboxData(this) {}
threadPool(Scheduler::GetBackground()),
mailboxData(this),
backend(std::make_unique<AndroidRendererBackend>()) {}

MapRenderer::MailboxData::MailboxData(Scheduler* scheduler_) : scheduler(scheduler_) {
MapRenderer::MailboxData::MailboxData(Scheduler* scheduler_)
: scheduler(scheduler_) {
assert(scheduler);
}

Expand Down Expand Up @@ -143,7 +146,7 @@ void MapRenderer::requestSnapshot(SnapshotCallback callback) {

void MapRenderer::resetRenderer() {
renderer.reset();
backend.reset();
backend = std::make_unique<AndroidRendererBackend>();
}

void MapRenderer::scheduleSnapshot(std::unique_ptr<SnapshotCallback> callback) {
Expand All @@ -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
Expand All @@ -190,6 +194,7 @@ void MapRenderer::onSurfaceCreated(JNIEnv&) {
std::lock_guard<std::mutex> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class MapRenderer : public Scheduler {
float pixelRatio;
optional<std::string> localIdeographFontFamily;

std::shared_ptr<ThreadPool> threadPool;
std::shared_ptr<Scheduler> threadPool;
const MailboxData mailboxData;

std::mutex initialisationMutex;
Expand Down

0 comments on commit b94110a

Please sign in to comment.