Improve weak pointer use (#3510)

Co-authored-by: Bart Louwers <bart@emeel.net>
This commit is contained in:
Tim Sylvester
2025-05-30 10:45:02 -07:00
committed by GitHub
parent 5ac3a2e901
commit 317c971114
9 changed files with 38 additions and 44 deletions

View File

@@ -66,14 +66,9 @@ MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env,
}
MapSnapshotter::~MapSnapshotter() {
auto guard = weakScheduler.lock();
if (weakScheduler && weakScheduler.get() != mbgl::Scheduler::GetCurrent()) {
if (auto guard = weakScheduler.lock(); weakScheduler && weakScheduler.get() != Scheduler::GetCurrent()) {
snapshotter->cancel();
weakScheduler->schedule([ptr = snapshotter.release()]() mutable {
if (ptr) {
delete ptr;
}
});
weakScheduler->schedule([ptr = snapshotter.release()]() { delete ptr; });
}
}