Merge branch 'thread_safe_static_init' into 'master'

Do thread safe local static based initialization

See merge request OpenMW/openmw!4822
This commit is contained in:
elsid 2025-08-02 08:39:23 +00:00
commit 3781485edd
6 changed files with 14 additions and 25 deletions

View File

@ -774,12 +774,10 @@ namespace MWGui
, mGlobalMapRender(std::make_unique<MWRender::GlobalMap>(localMapRender->getRoot(), workQueue))
, mEditNoteDialog()
{
static bool registered = false;
if (!registered)
{
[[maybe_unused]] static const bool registered = [] {
MyGUI::FactoryManager::getInstance().registerFactory<MarkerWidget>("Widget");
registered = true;
}
return true;
}();
mEditNoteDialog.setVisible(false);
mEditNoteDialog.eventOkClicked += MyGUI::newDelegate(this, &MapWindow::onNoteEditOk);

View File

@ -401,14 +401,12 @@ namespace MWRender
{
if (mViewMode == VM_FirstPerson)
{
static bool prototypeAdded = false;
if (!prototypeAdded)
{
[[maybe_unused]] static const bool prototypeAdded = [&] {
osg::ref_ptr<osgUtil::RenderBin> depthClearBin(new osgUtil::RenderBin);
depthClearBin->setDrawCallback(new DepthClearCallback());
osgUtil::RenderBin::addRenderBinPrototype("DepthClear", depthClearBin);
prototypeAdded = true;
}
return true;
}();
mObjectRoot->getOrCreateStateSet()->setRenderBinDetails(
RenderBin_FirstPerson, "DepthClear", osg::StateSet::OVERRIDE_RENDERBIN_DETAILS);
}

View File

@ -88,14 +88,13 @@ namespace MWRender
if (mProgramBlobber != nullptr)
{
static bool pipelineLogged = [&] {
[[maybe_unused]] static const bool pipelineLogged = [&] {
if (mUseCompute)
Log(Debug::Info) << "Initialized compute shader pipeline for water ripples";
else
Log(Debug::Info) << "Initialized fallback fragment shader pipeline for water ripples";
return true;
}();
(void)pipelineLogged;
}
setCullCallback(new osg::NodeCallback);

View File

@ -522,16 +522,14 @@ namespace MWSound
/* We need to make sure ffmpeg is initialized. Optionally silence warning
* output from the lib */
static bool done_init = false;
if (!done_init)
{
[[maybe_unused]] static const bool doneInit = [] {
// This is not needed anymore above FFMpeg version 4.0
#if LIBAVCODEC_VERSION_INT < 3805796
av_register_all();
#endif
av_log_set_level(AV_LOG_ERROR);
done_init = true;
}
return true;
}();
}
FFmpegDecoder::~FFmpegDecoder()

View File

@ -1273,13 +1273,12 @@ namespace MWWorld
const std::size_t leftCapacity = mPreloader->getMaxCacheSize() - mPreloader->getCacheSize();
if (cells.size() > leftCapacity)
{
static bool logged = [&] {
[[maybe_unused]] static const bool logged = [&] {
Log(Debug::Warning) << "Not enough cell preloader cache capacity to preload exterior cells, consider "
"increasing \"preload cell cache max\" up to "
<< (mPreloader->getCacheSize() + cells.size());
return true;
}();
(void)logged;
cells.resize(leftCapacity);
}

View File

@ -95,13 +95,10 @@ namespace SceneUtil
static void setReversed(bool reverseZ)
{
static bool init = false;
if (!init)
{
[[maybe_unused]] static const bool init = [&] {
AutoDepth::sReversed = reverseZ;
init = true;
}
return true;
}();
}
static bool isReversed()