1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-01-19 03:57:14 +01:00

Prevent exceptions thrown during the destruction of an entrity instance from blocking the release of it's resources.

This commit is contained in:
Sandu Liviu Catalin 2016-08-25 23:47:59 +03:00
parent dfbb0b9c46
commit 11d5cff63b

View File

@ -30,6 +30,23 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// --------------------------------------------------------------------------------------------
#define SQMOD_CATCH_EVENT_EXCEPTION(action) /*
*/ catch (const Sqrat::Exception & e) /*
*/ { /*
*/ LogErr("Squirrel exception caught " action); /*
*/ Logger::Get().Debug("%s", e.what()); /*
*/ } /*
*/ catch (const std::exception & e) /*
*/ { /*
*/ LogErr("Program exception caught " action " [%s]", e.what()); /*
*/ } /*
*/ catch (...) /*
*/ { /*
*/ LogErr("Unknown exception caught " action); /*
*/ } /*
*/
// ------------------------------------------------------------------------------------------------
extern bool RegisterAPI(HSQUIRRELVM vm);
@ -379,7 +396,7 @@ bool Core::Execute()
{
return false; // One of the scripts failed to execute
}
cLogDbg(m_Verbosity >= 1, "Completed execution of stage (%u) scripts", levels);
cLogDbg(m_Verbosity >= 2, "Completed execution of stage (%u) scripts", levels);
}
// Create the null entity instances
@ -617,7 +634,7 @@ bool Core::LoadScript(CSStr filepath, bool delay)
return false;
}
// At this point the script should be completely loaded
cLogDbg(m_Verbosity >= 2, "Successfully compiled script: %s", m_Scripts.back().mPath.c_str());
cLogDbg(m_Verbosity >= 3, "Successfully compiled script: %s", m_Scripts.back().mPath.c_str());
// Attempt to execute the compiled script code
try
@ -704,7 +721,7 @@ bool Core::DoScripts(Scripts::iterator itr, Scripts::iterator end)
return false;
}
cLogDbg(Get().m_Verbosity >= 2, "Successfully compiled script: %s", (*itr).mPath.c_str());
cLogDbg(Get().m_Verbosity >= 3, "Successfully compiled script: %s", (*itr).mPath.c_str());
// Should we delay the execution of this script?
if ((*itr).mDelay)
@ -905,9 +922,14 @@ void Core::BlipInst::Destroy(bool destroy, Int32 header, Object & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
{
// Don't leave exceptions to prevent us from releasing this instance
try
{
Core::Get().EmitBlipDestroyed(mID, header, payload);
}
SQMOD_CATCH_EVENT_EXCEPTION("while destroying blip")
}
// Is there a manager instance associated with this entity?
if (mInst)
{
@ -939,9 +961,14 @@ void Core::CheckpointInst::Destroy(bool destroy, Int32 header, Object & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
{
// Don't leave exceptions to prevent us from releasing this instance
try
{
Core::Get().EmitCheckpointDestroyed(mID, header, payload);
}
SQMOD_CATCH_EVENT_EXCEPTION("while destroying checkpoint")
}
// Is there a manager instance associated with this entity?
if (mInst)
{
@ -973,9 +1000,14 @@ void Core::KeybindInst::Destroy(bool destroy, Int32 header, Object & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
{
// Don't leave exceptions to prevent us from releasing this instance
try
{
Core::Get().EmitKeybindDestroyed(mID, header, payload);
}
SQMOD_CATCH_EVENT_EXCEPTION("while destroying keybind")
}
// Is there a manager instance associated with this entity?
if (mInst)
{
@ -1007,9 +1039,14 @@ void Core::ObjectInst::Destroy(bool destroy, Int32 header, Object & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
{
// Don't leave exceptions to prevent us from releasing this instance
try
{
Core::Get().EmitObjectDestroyed(mID, header, payload);
}
SQMOD_CATCH_EVENT_EXCEPTION("while destroying object")
}
// Is there a manager instance associated with this entity?
if (mInst)
{
@ -1041,9 +1078,14 @@ void Core::PickupInst::Destroy(bool destroy, Int32 header, Object & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
{
// Don't leave exceptions to prevent us from releasing this instance
try
{
Core::Get().EmitPickupDestroyed(mID, header, payload);
}
SQMOD_CATCH_EVENT_EXCEPTION("while destroying pickup")
}
// Is there a manager instance associated with this entity?
if (mInst)
{
@ -1075,9 +1117,14 @@ void Core::PlayerInst::Destroy(bool /*destroy*/, Int32 header, Object & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
{
// Don't leave exceptions to prevent us from releasing this instance
try
{
Core::Get().EmitPlayerDestroyed(mID, header, payload);
}
SQMOD_CATCH_EVENT_EXCEPTION("while destroying player")
}
// Is there a manager instance associated with this entity?
if (mInst)
{
@ -1103,9 +1150,14 @@ void Core::VehicleInst::Destroy(bool destroy, Int32 header, Object & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
{
// Don't leave exceptions to prevent us from releasing this instance
try
{
Core::Get().EmitVehicleDestroyed(mID, header, payload);
}
SQMOD_CATCH_EVENT_EXCEPTION("while destroying vehicle")
}
// Is there a manager instance associated with this entity?
if (mInst)
{