fix(core): make headless OpenGL display singletons thread-safe (#4332)

This commit is contained in:
Taku Fukada
2026-07-14 04:56:09 +09:00
committed by GitHub
parent c58080b491
commit d4ae69d3bc
4 changed files with 13 additions and 18 deletions

View File

@@ -29,6 +29,7 @@
### 🐞 Bug fixes ### 🐞 Bug fixes
- *...Add new stuff here...* - *...Add new stuff here...*
- [core] Fix thread-unsafe headless OpenGL display singleton initialization [#4332](https://github.com/maplibre/maplibre-native/pull/4332)
- [macos] Fix `mlt-cpp` and `mbgl-vendor-icu` not being included in the amalgamation - [macos] Fix `mlt-cpp` and `mbgl-vendor-icu` not being included in the amalgamation
- [core] Fix memory access violation exception in vector_tile_data.cpp [#632](https://github.com/maplibre/maplibre-native/pull/632) - [core] Fix memory access violation exception in vector_tile_data.cpp [#632](https://github.com/maplibre/maplibre-native/pull/632)
- [iOS] Fix a bug where the compass was determined to be misplaced when hidden [#498](https://github.com/maplibre/maplibre-native/pull/498). - [iOS] Fix a bug where the compass was determined to be misplaced when hidden [#498](https://github.com/maplibre/maplibre-native/pull/498).

View File

@@ -6,6 +6,7 @@
#include <EGL/egl.h> #include <EGL/egl.h>
#include <cassert> #include <cassert>
#include <memory>
#include <sstream> #include <sstream>
namespace mbgl { namespace mbgl {
@@ -51,12 +52,9 @@ public:
~EGLDisplayConfig() { eglTerminate(display); } ~EGLDisplayConfig() { eglTerminate(display); }
static std::shared_ptr<const EGLDisplayConfig> create() { static std::shared_ptr<const EGLDisplayConfig> create() {
static std::weak_ptr<const EGLDisplayConfig> instance; // C++11 magic static guarantees thread-safe one-shot initialization.
auto shared = instance.lock(); static const auto instance = std::make_shared<EGLDisplayConfig>(Key{});
if (!shared) { return instance;
instance = shared = std::make_shared<EGLDisplayConfig>(Key{});
}
return shared;
} }
public: public:

View File

@@ -3,6 +3,7 @@
#include <mbgl/util/logging.hpp> #include <mbgl/util/logging.hpp>
#include <cassert> #include <cassert>
#include <memory>
#ifdef CI_BUILD #ifdef CI_BUILD
#include <chrono> #include <chrono>
@@ -80,12 +81,9 @@ public:
} }
static std::shared_ptr<const GLXDisplayConfig> create() { static std::shared_ptr<const GLXDisplayConfig> create() {
static std::weak_ptr<const GLXDisplayConfig> instance; // C++11 magic static guarantees thread-safe one-shot initialization.
auto shared = instance.lock(); static const auto instance = std::make_shared<GLXDisplayConfig>(Key{});
if (!shared) { return instance;
instance = shared = std::make_shared<GLXDisplayConfig>(Key{});
}
return shared;
} }
public: public:

View File

@@ -6,6 +6,7 @@
#include <EGL/egl.h> #include <EGL/egl.h>
#include <cassert> #include <cassert>
#include <memory>
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
@@ -53,12 +54,9 @@ public:
~EGLDisplayConfig() { eglTerminate(display); } ~EGLDisplayConfig() { eglTerminate(display); }
static std::shared_ptr<const EGLDisplayConfig> create() { static std::shared_ptr<const EGLDisplayConfig> create() {
static std::weak_ptr<const EGLDisplayConfig> instance; // C++11 magic static guarantees thread-safe one-shot initialization.
auto shared = instance.lock(); static const auto instance = std::make_shared<EGLDisplayConfig>(Key{});
if (!shared) { return instance;
instance = shared = std::make_shared<EGLDisplayConfig>(Key{});
}
return shared;
} }
public: public: