Warn only once per missing icon

Mods may dynamically request icons
(e.g., [icon=\"emblem_${civ}\"], [icon=\"icon_${res}\"]) that
don't exist when another mod introduced the new civ or resource
but hasn't added that icon.
This results in excessive error log spam during normal gameplay.
This commit is contained in:
Atrik
2026-03-26 22:25:34 +01:00
committed by Atrik
parent 1fc267080d
commit a8ee3c2b92
3 changed files with 20 additions and 1 deletions
+6
View File
@@ -1333,6 +1333,12 @@ void CGUI::Xeromyces_ReadIcon(const XMBData& xmb, XMBElement element)
m_Icons.emplace(name, std::move(icon));
}
void CGUI::ReportMissingIcon(const CStr& name) const
{
if (m_MissingIconsReported.insert(name).second)
LOGWARNING("Trying to use an icon, imgleft or imgright-tag with an undefined icon (\"%s\").", name);
}
void CGUI::Xeromyces_ReadTooltip(const XMBData& xmb, XMBElement element)
{
std::unique_ptr<IGUIObject> object{std::make_unique<CTooltip>(*this)};
+13
View File
@@ -264,6 +264,15 @@ public:
*/
const SGUIIcon& GetIcon(const CStr& name) const { return m_Icons.at(name); }
/**
* Log a warning when text markup refers to an icon that doesn't exist.
* Mods may reference icons dynamically (e.g. an icon name
* built from a civ or resource identifier) that can be temporarily
* missing while dependent mods are updated together; each distinct
* missing icon name is only logged once per GUI page to avoid log spam.
*/
void ReportMissingIcon(const CStr& name) const;
/**
* Check if a style exists
*/
@@ -725,6 +734,10 @@ private:
// Icons
std::map<CStr, const SGUIIcon> m_Icons;
// Icons that have already been reported as missing, to avoid repeating
// the same warning every time referencing text is regenerated.
mutable std::unordered_set<CStr> m_MissingIconsReported;
public:
struct ModuleArtifact
{
+1 -1
View File
@@ -113,7 +113,7 @@ void CGUIString::GenerateTextCall(const CGUI& pGUI, SFeedback& Feedback, CStrInt
if (!pGUI.HasIcon(path))
{
if (pObject)
LOGERROR("Trying to use an icon, imgleft or imgright-tag with an undefined icon (\"%s\").", path.c_str());
pGUI.ReportMissingIcon(path);
continue;
}