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:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user