chore(Debug/Scripting): improve debug errors during the unloading scripts (#19643)

* chore(Debug/Scripting): improve debug errors during script unloading

* add the script name to increase debug informations and ensure to derefence script pointers
This commit is contained in:
Grimdhex
2024-08-21 13:13:20 +02:00
committed by GitHub
parent ef4e0c0d4a
commit db7183a573

View File

@@ -30,9 +30,24 @@ namespace
template<typename T>
inline void SCR_CLEAR()
{
for (auto const& [scriptID, script] : ScriptRegistry<T>::ScriptPointerList)
for (auto& [scriptID, script] : ScriptRegistry<T>::ScriptPointerList)
{
delete script;
try
{
if(script)
{
delete script;
script = nullptr;
}
}
catch (const std::exception& e)
{
LOG_ERROR("scripts.unloading", "Failed to unload script {} with ID: {}. Error: {}", script->GetName(), scriptID, e.what());
}
catch (...)
{
LOG_ERROR("scripts.unloading", "Failed to unload script {} with ID: {}. Unknown error occurred.", script->GetName(), scriptID);
}
}
ScriptRegistry<T>::ScriptPointerList.clear();