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
- *...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
- [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).

View File

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

View File

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

View File

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