Fix signal usage and possible race condition

This commit is contained in:
AdenKoperczak 2025-04-07 10:15:28 -04:00
parent 260b7c73a4
commit fe61f31c40
No known key found for this signature in database
GPG key ID: 9843017036F62EE7

View file

@ -44,7 +44,8 @@ public:
activeBoxOuter_ {std::make_shared<gl::draw::Rectangle>(context)}, activeBoxOuter_ {std::make_shared<gl::draw::Rectangle>(context)},
activeBoxInner_ {std::make_shared<gl::draw::Rectangle>(context)}, activeBoxInner_ {std::make_shared<gl::draw::Rectangle>(context)},
geoIcons_ {std::make_shared<gl::draw::GeoIcons>(context)}, geoIcons_ {std::make_shared<gl::draw::GeoIcons>(context)},
icons_ {std::make_shared<gl::draw::Icons>(context)} icons_ {std::make_shared<gl::draw::Icons>(context)},
renderMutex_ {}
{ {
auto& generalSettings = settings::GeneralSettings::Instance(); auto& generalSettings = settings::GeneralSettings::Instance();
@ -143,7 +144,10 @@ public:
float lastFontSize_ {0.0f}; float lastFontSize_ {0.0f};
QMargins lastColorTableMargins_ {}; QMargins lastColorTableMargins_ {};
double cursorScale_ {1}; double cursorScale_ {1};
boost::signals2::scoped_connection cursorScaleConnection_;
std::mutex renderMutex_;
std::string sweepTimeString_ {}; std::string sweepTimeString_ {};
bool sweepTimeNeedsUpdate_ {true}; bool sweepTimeNeedsUpdate_ {true};
@ -172,6 +176,11 @@ void OverlayLayerImpl::SetCusorLocation(common::Coordinate coordinate)
void OverlayLayerImpl::SetupGeoIcons() void OverlayLayerImpl::SetupGeoIcons()
{ {
const std::unique_lock lock {renderMutex_};
auto& generalSettings = settings::GeneralSettings::Instance();
cursorScale_ = generalSettings.cursor_icon_scale().GetValue();
const std::string& texturePath = const std::string& texturePath =
types::GetTexturePath(types::ImageTexture::Dot3); types::GetTexturePath(types::ImageTexture::Dot3);
cursorIconName_ = fmt::format( cursorIconName_ = fmt::format(
@ -219,15 +228,14 @@ void OverlayLayer::Initialize()
// Geo Icons // Geo Icons
auto& generalSettings = settings::GeneralSettings::Instance(); auto& generalSettings = settings::GeneralSettings::Instance();
p->cursorScale_ = generalSettings.cursor_icon_scale().GetValue();
p->SetupGeoIcons(); p->SetupGeoIcons();
generalSettings.cursor_icon_scale().RegisterValueChangedCallback( p->cursorScaleConnection_ =
[this](double value) generalSettings.cursor_icon_scale().changed_signal().connect(
{ [this]()
p->cursorScale_ = value; {
p->SetupGeoIcons(); p->SetupGeoIcons();
Q_EMIT NeedsRendering(); Q_EMIT NeedsRendering();
}); });
// Icons // Icons
p->icons_->StartIconSheets(); p->icons_->StartIconSheets();
@ -322,6 +330,8 @@ void OverlayLayer::Initialize()
void OverlayLayer::Render(const QMapLibre::CustomLayerRenderParameters& params) void OverlayLayer::Render(const QMapLibre::CustomLayerRenderParameters& params)
{ {
const std::unique_lock lock {p->renderMutex_};
gl::OpenGLFunctions& gl = context()->gl(); gl::OpenGLFunctions& gl = context()->gl();
auto radarProductView = context()->radar_product_view(); auto radarProductView = context()->radar_product_view();
auto& settings = context()->settings(); auto& settings = context()->settings();