mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 01:29:50 +00:00
Show an error when Engine.GetGUIObjectByName fails
It previously failed silently and just returned undefined which would often only cause errors later on. Printing an error as soon as that happens helps with debugging, by directly catching typos, for example. For cases where the queried object may not exist, a new Engine function called TryGetGUIObjectByName is introduced. It doesn't log any errors and behaves exactly as GetGUIObjectByName used to.
This commit is contained in:
+10
-1
@@ -434,7 +434,7 @@ bool CGUI::ObjectExists(const CStr& Name) const
|
||||
return m_pAllObjects.find(Name) != m_pAllObjects.end();
|
||||
}
|
||||
|
||||
IGUIObject* CGUI::FindObjectByName(const CStr& Name) const
|
||||
IGUIObject* CGUI::TryFindObjectByName(const CStr& Name) const
|
||||
{
|
||||
map_pObjects::const_iterator it = m_pAllObjects.find(Name);
|
||||
|
||||
@@ -444,6 +444,15 @@ IGUIObject* CGUI::FindObjectByName(const CStr& Name) const
|
||||
return it->second.get();
|
||||
}
|
||||
|
||||
IGUIObject* CGUI::FindObjectByName(const CStr& Name) const
|
||||
{
|
||||
IGUIObject* obj = TryFindObjectByName(Name);
|
||||
if (obj == nullptr)
|
||||
LOGERROR("Failed to get GUI object by name: object '%s' not found.\nNote: Use 'Engine.TryGetGUIObjectByName' to query for potentially non-existent objects instead.", Name);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
IGUIObject* CGUI::FindObjectUnderMouse()
|
||||
{
|
||||
IGUIObject* pNearest = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user