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:
Vantha
2025-07-25 23:40:42 +02:00
committed by Ralph Sennhauser
parent 3647921bed
commit 6515c3fb1f
3 changed files with 22 additions and 2 deletions
+10 -1
View File
@@ -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;