Fix segfault this-capture GeoJsonSource which may be deleted (#3536)

Co-authored-by: Tim Sylvester <tim@wetdogweather.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Bart Louwers
2025-06-06 23:38:19 +02:00
committed by GitHub
parent f6de3bc0e9
commit b0e2e2ce85
11 changed files with 96 additions and 46 deletions

View File

@@ -8,6 +8,7 @@
#include "../../android_renderer_frontend.hpp"
#include <jni/jni.hpp>
#include <functional>
namespace mbgl {
namespace android {
@@ -63,12 +64,21 @@ public:
jni::Local<jni::Long> getMinimumTileUpdateInterval(JNIEnv&);
protected:
template <typename T = style::Source>
T& getSource() {
return *ownedSource->as<T>();
}
std::weak_ptr<std::reference_wrapper<style::Source>> getWeakSource() const { return source; }
private:
// Set on newly created sources until added to the map.
std::unique_ptr<mbgl::style::Source> ownedSource;
// Raw pointer that is valid at all times.
mbgl::style::Source& source;
// Reference that is valid at all times.
std::shared_ptr<std::reference_wrapper<mbgl::style::Source>> source;
protected:
// Set when the source is added to a map.
jni::Global<jni::Object<Source>> javaPeer;