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

@@ -55,13 +55,21 @@ public:
/// Dynamically cast this source to the given subtype.
template <class T>
requires(std::is_base_of_v<Source, T>)
T* as() {
return is<T>() ? reinterpret_cast<T*>(this) : nullptr;
if constexpr (std::is_same_v<T, Source>) {
return this;
}
return is<T>() ? static_cast<T*>(this) : nullptr;
}
template <class T>
requires(std::is_base_of_v<Source, T>)
const T* as() const {
return is<T>() ? reinterpret_cast<const T*>(this) : nullptr;
if constexpr (std::is_same_v<T, Source>) {
return this;
}
return is<T>() ? static_cast<const T*>(this) : nullptr;
}
SourceType getType() const;