Skip to content

Commit

Permalink
chore(Debug/Scripting): improve debug errors during the unloading scr…
Browse files Browse the repository at this point in the history
…ipts (azerothcore#19643)

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

* add the script name to increase debug informations and ensure to derefence script pointers
  • Loading branch information
Grimdhex authored Aug 21, 2024
1 parent ef4e0c0 commit db7183a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/server/game/Scripting/ScriptMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit db7183a

Please sign in to comment.