1
0
forked from 0ad/0ad

Report and tolerate XML GUI object setting errors when parsing XML attribute strings as values for settings that don't exist on the GUI object.

Following e326ebae46, 80b1876b77, d6db5a466d, ... the XML errors were
silently ignored.
Following 1a49ccb294 it led to a crash (m_Setting access for an item
that does not exist).

Differential Revision: https://code.wildfiregames.com/D2297
Tested on: clang 8.0.1, Jenkins

This was SVN commit r22911.
This commit is contained in:
elexis 2019-09-16 16:13:25 +00:00
parent 61e3f1ec0d
commit 4d4bf579b2
2 changed files with 8 additions and 6 deletions

View File

@ -715,11 +715,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
if (attr.Name == attr_z)
ManuallySetZ = true;
const CStr settingName = pFile->GetAttributeString(attr.Name);
if (object->SettingExists(settingName))
object->SetSettingFromString(settingName, attr.Value.FromUTF8(), false);
else
LOGERROR("GUI: (object: %s) Can't set \"%s\" to \"%s\"", object->GetPresentableName(), settingName, attr.Value);
object->SetSettingFromString(pFile->GetAttributeString(attr.Name), attr.Value.FromUTF8(), false);
}
// Check if name isn't set, generate an internal name in that case.

View File

@ -148,7 +148,13 @@ const T& IGUIObject::GetSetting(const CStr& Setting) const
bool IGUIObject::SetSettingFromString(const CStr& Setting, const CStrW& Value, const bool SendMessage)
{
return m_Settings[Setting]->FromString(Value, SendMessage);
const std::map<CStr, IGUISetting*>::iterator it = m_Settings.find(Setting);
if (it == m_Settings.end())
{
LOGERROR("GUI object '%s' has no property called '%s', can't set parse and set value '%s'", GetPresentableName().c_str(), Setting.c_str(), Value.ToUTF8().c_str());
return false;
}
return it->second->FromString(Value, SendMessage);
}
template <typename T>