mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 08:47:17 +01:00
Dumb approach to recive some kind of asserts if the program crashes because a component was used after it was deleted.
This commit is contained in:
parent
3762b5e2ca
commit
ff6cacaf68
@ -6,7 +6,6 @@
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <cmath>
|
||||
#include <cassert>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <vcmp.h>
|
||||
|
@ -14,7 +14,7 @@
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CmdManager * _Cmd = nullptr;
|
||||
SQMOD_MANAGEDPTR_TYPE(CmdManager) _Cmd = SQMOD_MANAGEDPTR_MAKE(CmdManager, nullptr);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger CmdListener::Typename(HSQUIRRELVM vm)
|
||||
|
@ -21,7 +21,7 @@ class CmdListener;
|
||||
CSStr CmdArgSpecToStr(Uint8 spec);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
extern CmdManager * _Cmd;
|
||||
extern SQMOD_MANAGEDPTR_TYPE(CmdManager) _Cmd;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Manages command instances and processes executed commands.
|
||||
@ -188,10 +188,10 @@ public:
|
||||
{
|
||||
if (!_Cmd)
|
||||
{
|
||||
_Cmd = new CmdManager();
|
||||
_Cmd = SQMOD_MANAGEDPTR_MAKE(CmdManager, new CmdManager());
|
||||
}
|
||||
|
||||
return _Cmd;
|
||||
return SQMOD_MANAGEDPTR_GET(_Cmd);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
|
434
source/Core.cpp
434
source/Core.cpp
@ -46,7 +46,7 @@ extern Int32 RunCommand(Int32 invoker, CSStr command);
|
||||
extern void TerminateCommand();
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Core * _Core = NULL;
|
||||
SQMOD_MANAGEDPTR_TYPE(Core) _Core = SQMOD_MANAGEDPTR_MAKE(Core, nullptr);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Utility class used to release the destroy lock if unable to complete the process.
|
||||
@ -56,7 +56,7 @@ struct EntLockGuard
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Uint16 & m_Flags;
|
||||
Uint16 & m_Flags; // Reference to the guarded entity flags.
|
||||
|
||||
public:
|
||||
|
||||
@ -84,7 +84,7 @@ public:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Core::Core()
|
||||
: m_State(0)
|
||||
, m_VM(NULL)
|
||||
, m_VM(nullptr)
|
||||
, m_Scripts()
|
||||
, m_Options()
|
||||
, m_Blips()
|
||||
@ -371,7 +371,7 @@ void Core::Terminate()
|
||||
m_Scripts.clear();
|
||||
// Assertions during close may cause double delete!
|
||||
HSQUIRRELVM sq_vm = m_VM;
|
||||
m_VM = NULL;
|
||||
m_VM = nullptr;
|
||||
// Attempt to close the VM
|
||||
sq_close(sq_vm);
|
||||
}
|
||||
@ -442,7 +442,7 @@ SQInteger Core::RuntimeErrorHandler(HSQUIRRELVM vm)
|
||||
return 0;
|
||||
}
|
||||
|
||||
CSStr err_msg = NULL;
|
||||
CSStr err_msg = nullptr;
|
||||
|
||||
if (SQ_SUCCEEDED(sq_getstring(vm, 2, &err_msg)))
|
||||
{
|
||||
@ -890,7 +890,7 @@ void Core::DeallocBlip(Int32 id, bool destroy, Int32 header, Object & payload)
|
||||
// Release associated script callbacks
|
||||
ResetFunc(inst);
|
||||
// Prevent further use of the manager instance
|
||||
inst.mInst = NULL;
|
||||
inst.mInst = nullptr;
|
||||
// Release the script object, if any
|
||||
inst.mObj.Release();
|
||||
}
|
||||
@ -939,7 +939,7 @@ void Core::DeallocCheckpoint(Int32 id, bool destroy, Int32 header, Object & payl
|
||||
// Release associated script callbacks
|
||||
ResetFunc(inst);
|
||||
// Prevent further use of the manager instance
|
||||
inst.mInst = NULL;
|
||||
inst.mInst = nullptr;
|
||||
// Release the script object, if any
|
||||
inst.mObj.Release();
|
||||
}
|
||||
@ -988,7 +988,7 @@ void Core::DeallocForcefield(Int32 id, bool destroy, Int32 header, Object & payl
|
||||
// Release associated script callbacks
|
||||
ResetFunc(inst);
|
||||
// Prevent further use of the manager instance
|
||||
inst.mInst = NULL;
|
||||
inst.mInst = nullptr;
|
||||
// Release the script object, if any
|
||||
inst.mObj.Release();
|
||||
}
|
||||
@ -1037,7 +1037,7 @@ void Core::DeallocKeybind(Int32 id, bool destroy, Int32 header, Object & payload
|
||||
// Release associated script callbacks
|
||||
ResetFunc(inst);
|
||||
// Prevent further use of the manager instance
|
||||
inst.mInst = NULL;
|
||||
inst.mInst = nullptr;
|
||||
// Release the script object, if any
|
||||
inst.mObj.Release();
|
||||
}
|
||||
@ -1086,7 +1086,7 @@ void Core::DeallocObject(Int32 id, bool destroy, Int32 header, Object & payload)
|
||||
// Release associated script callbacks
|
||||
ResetFunc(inst);
|
||||
// Prevent further use of the manager instance
|
||||
inst.mInst = NULL;
|
||||
inst.mInst = nullptr;
|
||||
// Release the script object, if any
|
||||
inst.mObj.Release();
|
||||
}
|
||||
@ -1135,7 +1135,7 @@ void Core::DeallocPickup(Int32 id, bool destroy, Int32 header, Object & payload)
|
||||
// Release associated script callbacks
|
||||
ResetFunc(inst);
|
||||
// Prevent further use of the manager instance
|
||||
inst.mInst = NULL;
|
||||
inst.mInst = nullptr;
|
||||
// Release the script object, if any
|
||||
inst.mObj.Release();
|
||||
}
|
||||
@ -1184,7 +1184,7 @@ void Core::DeallocSprite(Int32 id, bool destroy, Int32 header, Object & payload)
|
||||
// Release associated script callbacks
|
||||
ResetFunc(inst);
|
||||
// Prevent further use of the manager instance
|
||||
inst.mInst = NULL;
|
||||
inst.mInst = nullptr;
|
||||
// Release the script object, if any
|
||||
inst.mObj.Release();
|
||||
}
|
||||
@ -1233,7 +1233,7 @@ void Core::DeallocTextdraw(Int32 id, bool destroy, Int32 header, Object & payloa
|
||||
// Release associated script callbacks
|
||||
ResetFunc(inst);
|
||||
// Prevent further use of the manager instance
|
||||
inst.mInst = NULL;
|
||||
inst.mInst = nullptr;
|
||||
// Release the script object, if any
|
||||
inst.mObj.Release();
|
||||
}
|
||||
@ -1282,7 +1282,7 @@ void Core::DeallocVehicle(Int32 id, bool destroy, Int32 header, Object & payload
|
||||
// Release associated script callbacks
|
||||
ResetFunc(inst);
|
||||
// Prevent further use of the manager instance
|
||||
inst.mInst = NULL;
|
||||
inst.mInst = nullptr;
|
||||
// Release the script object, if any
|
||||
inst.mObj.Release();
|
||||
}
|
||||
@ -1580,7 +1580,7 @@ void Core::DisconnectPlayer(Int32 id, Int32 header, Object & payload)
|
||||
// Release associated script callbacks
|
||||
ResetFunc(inst);
|
||||
// Prevent further use of the manager instance
|
||||
inst.mInst = NULL;
|
||||
inst.mInst = nullptr;
|
||||
// Release the script object, if any
|
||||
inst.mObj.Release();
|
||||
}
|
||||
@ -2565,7 +2565,7 @@ void Core::ResetInst(PlayerInst & inst)
|
||||
inst.mAuthority = 0;
|
||||
for (unsigned n = 0; n < SQMOD_PLAYER_MSG_PREFIXES; ++n)
|
||||
{
|
||||
inst.mPrefixes[n].clear();
|
||||
inst.mPrefixes[n].assign("");
|
||||
}
|
||||
inst.mMessageColor = 0x6599FFFF;
|
||||
inst.mAnnounceStyle = 1;
|
||||
@ -2594,247 +2594,247 @@ void Core::ResetInst(VehicleInst & inst)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::ResetFunc(BlipInst & inst)
|
||||
{
|
||||
inst.mOnDestroyed.Release();
|
||||
inst.mOnCustom.Release();
|
||||
inst.mOnDestroyed.ReleaseGently();
|
||||
inst.mOnCustom.ReleaseGently();
|
||||
}
|
||||
|
||||
void Core::ResetFunc(CheckpointInst & inst)
|
||||
{
|
||||
inst.mOnDestroyed.Release();
|
||||
inst.mOnCustom.Release();
|
||||
inst.mOnEntered.Release();
|
||||
inst.mOnExited.Release();
|
||||
inst.mOnDestroyed.ReleaseGently();
|
||||
inst.mOnCustom.ReleaseGently();
|
||||
inst.mOnEntered.ReleaseGently();
|
||||
inst.mOnExited.ReleaseGently();
|
||||
}
|
||||
|
||||
void Core::ResetFunc(ForcefieldInst & inst)
|
||||
{
|
||||
inst.mOnDestroyed.Release();
|
||||
inst.mOnCustom.Release();
|
||||
inst.mOnEntered.Release();
|
||||
inst.mOnExited.Release();
|
||||
inst.mOnDestroyed.ReleaseGently();
|
||||
inst.mOnCustom.ReleaseGently();
|
||||
inst.mOnEntered.ReleaseGently();
|
||||
inst.mOnExited.ReleaseGently();
|
||||
}
|
||||
|
||||
void Core::ResetFunc(KeybindInst & inst)
|
||||
{
|
||||
inst.mOnDestroyed.Release();
|
||||
inst.mOnCustom.Release();
|
||||
inst.mOnKeyPress.Release();
|
||||
inst.mOnKeyRelease.Release();
|
||||
inst.mOnDestroyed.ReleaseGently();
|
||||
inst.mOnCustom.ReleaseGently();
|
||||
inst.mOnKeyPress.ReleaseGently();
|
||||
inst.mOnKeyRelease.ReleaseGently();
|
||||
}
|
||||
|
||||
void Core::ResetFunc(ObjectInst & inst)
|
||||
{
|
||||
inst.mOnDestroyed.Release();
|
||||
inst.mOnCustom.Release();
|
||||
inst.mOnShot.Release();
|
||||
inst.mOnBump.Release();
|
||||
inst.mOnDestroyed.ReleaseGently();
|
||||
inst.mOnCustom.ReleaseGently();
|
||||
inst.mOnShot.ReleaseGently();
|
||||
inst.mOnBump.ReleaseGently();
|
||||
}
|
||||
|
||||
void Core::ResetFunc(PickupInst & inst)
|
||||
{
|
||||
inst.mOnDestroyed.Release();
|
||||
inst.mOnCustom.Release();
|
||||
inst.mOnRespawn.Release();
|
||||
inst.mOnClaimed.Release();
|
||||
inst.mOnCollected.Release();
|
||||
inst.mOnDestroyed.ReleaseGently();
|
||||
inst.mOnCustom.ReleaseGently();
|
||||
inst.mOnRespawn.ReleaseGently();
|
||||
inst.mOnClaimed.ReleaseGently();
|
||||
inst.mOnCollected.ReleaseGently();
|
||||
}
|
||||
|
||||
void Core::ResetFunc(PlayerInst & inst)
|
||||
{
|
||||
inst.mOnDestroyed.Release();
|
||||
inst.mOnCustom.Release();
|
||||
inst.mOnAway.Release();
|
||||
inst.mOnGameKeys.Release();
|
||||
inst.mOnRename.Release();
|
||||
inst.mOnRequestClass.Release();
|
||||
inst.mOnRequestSpawn.Release();
|
||||
inst.mOnSpawn.Release();
|
||||
inst.mOnStartTyping.Release();
|
||||
inst.mOnStopTyping.Release();
|
||||
inst.mOnChat.Release();
|
||||
inst.mOnCommand.Release();
|
||||
inst.mOnMessage.Release();
|
||||
inst.mOnHealth.Release();
|
||||
inst.mOnArmour.Release();
|
||||
inst.mOnWeapon.Release();
|
||||
inst.mOnMove.Release();
|
||||
inst.mOnWasted.Release();
|
||||
inst.mOnKilled.Release();
|
||||
inst.mOnTeamKill.Release();
|
||||
inst.mOnSpectate.Release();
|
||||
inst.mOnCrashreport.Release();
|
||||
inst.mOnBurning.Release();
|
||||
inst.mOnCrouching.Release();
|
||||
inst.mOnState.Release();
|
||||
inst.mOnAction.Release();
|
||||
inst.mOnStateNone.Release();
|
||||
inst.mOnStateNormal.Release();
|
||||
inst.mOnStateShooting.Release();
|
||||
inst.mOnStateDriver.Release();
|
||||
inst.mOnStatePassenger.Release();
|
||||
inst.mOnStateEnterDriver.Release();
|
||||
inst.mOnStateEnterPassenger.Release();
|
||||
inst.mOnStateExitVehicle.Release();
|
||||
inst.mOnStateUnspawned.Release();
|
||||
inst.mOnActionNone.Release();
|
||||
inst.mOnActionNormal.Release();
|
||||
inst.mOnActionAiming.Release();
|
||||
inst.mOnActionShooting.Release();
|
||||
inst.mOnActionJumping.Release();
|
||||
inst.mOnActionLieDown.Release();
|
||||
inst.mOnActionGettingUp.Release();
|
||||
inst.mOnActionJumpVehicle.Release();
|
||||
inst.mOnActionDriving.Release();
|
||||
inst.mOnActionDying.Release();
|
||||
inst.mOnActionWasted.Release();
|
||||
inst.mOnActionEmbarking.Release();
|
||||
inst.mOnActionDisembarking.Release();
|
||||
inst.mOnKeyPress.Release();
|
||||
inst.mOnKeyRelease.Release();
|
||||
inst.mOnEmbarking.Release();
|
||||
inst.mOnEmbarked.Release();
|
||||
inst.mOnDisembark.Release();
|
||||
inst.mOnPickupClaimed.Release();
|
||||
inst.mOnPickupCollected.Release();
|
||||
inst.mOnObjectShot.Release();
|
||||
inst.mOnObjectBump.Release();
|
||||
inst.mOnCheckpointEntered.Release();
|
||||
inst.mOnCheckpointExited.Release();
|
||||
inst.mOnForcefieldEntered.Release();
|
||||
inst.mOnForcefieldExited.Release();
|
||||
inst.mOnDestroyed.ReleaseGently();
|
||||
inst.mOnCustom.ReleaseGently();
|
||||
inst.mOnAway.ReleaseGently();
|
||||
inst.mOnGameKeys.ReleaseGently();
|
||||
inst.mOnRename.ReleaseGently();
|
||||
inst.mOnRequestClass.ReleaseGently();
|
||||
inst.mOnRequestSpawn.ReleaseGently();
|
||||
inst.mOnSpawn.ReleaseGently();
|
||||
inst.mOnStartTyping.ReleaseGently();
|
||||
inst.mOnStopTyping.ReleaseGently();
|
||||
inst.mOnChat.ReleaseGently();
|
||||
inst.mOnCommand.ReleaseGently();
|
||||
inst.mOnMessage.ReleaseGently();
|
||||
inst.mOnHealth.ReleaseGently();
|
||||
inst.mOnArmour.ReleaseGently();
|
||||
inst.mOnWeapon.ReleaseGently();
|
||||
inst.mOnMove.ReleaseGently();
|
||||
inst.mOnWasted.ReleaseGently();
|
||||
inst.mOnKilled.ReleaseGently();
|
||||
inst.mOnTeamKill.ReleaseGently();
|
||||
inst.mOnSpectate.ReleaseGently();
|
||||
inst.mOnCrashreport.ReleaseGently();
|
||||
inst.mOnBurning.ReleaseGently();
|
||||
inst.mOnCrouching.ReleaseGently();
|
||||
inst.mOnState.ReleaseGently();
|
||||
inst.mOnAction.ReleaseGently();
|
||||
inst.mOnStateNone.ReleaseGently();
|
||||
inst.mOnStateNormal.ReleaseGently();
|
||||
inst.mOnStateShooting.ReleaseGently();
|
||||
inst.mOnStateDriver.ReleaseGently();
|
||||
inst.mOnStatePassenger.ReleaseGently();
|
||||
inst.mOnStateEnterDriver.ReleaseGently();
|
||||
inst.mOnStateEnterPassenger.ReleaseGently();
|
||||
inst.mOnStateExitVehicle.ReleaseGently();
|
||||
inst.mOnStateUnspawned.ReleaseGently();
|
||||
inst.mOnActionNone.ReleaseGently();
|
||||
inst.mOnActionNormal.ReleaseGently();
|
||||
inst.mOnActionAiming.ReleaseGently();
|
||||
inst.mOnActionShooting.ReleaseGently();
|
||||
inst.mOnActionJumping.ReleaseGently();
|
||||
inst.mOnActionLieDown.ReleaseGently();
|
||||
inst.mOnActionGettingUp.ReleaseGently();
|
||||
inst.mOnActionJumpVehicle.ReleaseGently();
|
||||
inst.mOnActionDriving.ReleaseGently();
|
||||
inst.mOnActionDying.ReleaseGently();
|
||||
inst.mOnActionWasted.ReleaseGently();
|
||||
inst.mOnActionEmbarking.ReleaseGently();
|
||||
inst.mOnActionDisembarking.ReleaseGently();
|
||||
inst.mOnKeyPress.ReleaseGently();
|
||||
inst.mOnKeyRelease.ReleaseGently();
|
||||
inst.mOnEmbarking.ReleaseGently();
|
||||
inst.mOnEmbarked.ReleaseGently();
|
||||
inst.mOnDisembark.ReleaseGently();
|
||||
inst.mOnPickupClaimed.ReleaseGently();
|
||||
inst.mOnPickupCollected.ReleaseGently();
|
||||
inst.mOnObjectShot.ReleaseGently();
|
||||
inst.mOnObjectBump.ReleaseGently();
|
||||
inst.mOnCheckpointEntered.ReleaseGently();
|
||||
inst.mOnCheckpointExited.ReleaseGently();
|
||||
inst.mOnForcefieldEntered.ReleaseGently();
|
||||
inst.mOnForcefieldExited.ReleaseGently();
|
||||
}
|
||||
|
||||
void Core::ResetFunc(SpriteInst & inst)
|
||||
{
|
||||
inst.mOnDestroyed.Release();
|
||||
inst.mOnCustom.Release();
|
||||
inst.mOnDestroyed.ReleaseGently();
|
||||
inst.mOnCustom.ReleaseGently();
|
||||
}
|
||||
|
||||
void Core::ResetFunc(TextdrawInst & inst)
|
||||
{
|
||||
inst.mOnDestroyed.Release();
|
||||
inst.mOnCustom.Release();
|
||||
inst.mOnDestroyed.ReleaseGently();
|
||||
inst.mOnCustom.ReleaseGently();
|
||||
}
|
||||
|
||||
void Core::ResetFunc(VehicleInst & inst)
|
||||
{
|
||||
inst.mOnDestroyed.Release();
|
||||
inst.mOnCustom.Release();
|
||||
inst.mOnRespawn.Release();
|
||||
inst.mOnExplode.Release();
|
||||
inst.mOnHealth.Release();
|
||||
inst.mOnMove.Release();
|
||||
inst.mOnEmbarking.Release();
|
||||
inst.mOnEmbarked.Release();
|
||||
inst.mOnDisembark.Release();
|
||||
inst.mOnDestroyed.ReleaseGently();
|
||||
inst.mOnCustom.ReleaseGently();
|
||||
inst.mOnRespawn.ReleaseGently();
|
||||
inst.mOnExplode.ReleaseGently();
|
||||
inst.mOnHealth.ReleaseGently();
|
||||
inst.mOnMove.ReleaseGently();
|
||||
inst.mOnEmbarking.ReleaseGently();
|
||||
inst.mOnEmbarked.ReleaseGently();
|
||||
inst.mOnDisembark.ReleaseGently();
|
||||
}
|
||||
|
||||
void Core::ResetFunc()
|
||||
{
|
||||
mOnBlipCreated.Release();
|
||||
mOnCheckpointCreated.Release();
|
||||
mOnForcefieldCreated.Release();
|
||||
mOnKeybindCreated.Release();
|
||||
mOnObjectCreated.Release();
|
||||
mOnPickupCreated.Release();
|
||||
mOnPlayerCreated.Release();
|
||||
mOnSpriteCreated.Release();
|
||||
mOnTextdrawCreated.Release();
|
||||
mOnVehicleCreated.Release();
|
||||
mOnBlipDestroyed.Release();
|
||||
mOnCheckpointDestroyed.Release();
|
||||
mOnForcefieldDestroyed.Release();
|
||||
mOnKeybindDestroyed.Release();
|
||||
mOnObjectDestroyed.Release();
|
||||
mOnPickupDestroyed.Release();
|
||||
mOnPlayerDestroyed.Release();
|
||||
mOnSpriteDestroyed.Release();
|
||||
mOnTextdrawDestroyed.Release();
|
||||
mOnVehicleDestroyed.Release();
|
||||
mOnBlipCustom.Release();
|
||||
mOnCheckpointCustom.Release();
|
||||
mOnForcefieldCustom.Release();
|
||||
mOnKeybindCustom.Release();
|
||||
mOnObjectCustom.Release();
|
||||
mOnPickupCustom.Release();
|
||||
mOnPlayerCustom.Release();
|
||||
mOnSpriteCustom.Release();
|
||||
mOnTextdrawCustom.Release();
|
||||
mOnVehicleCustom.Release();
|
||||
mOnPlayerAway.Release();
|
||||
mOnPlayerGameKeys.Release();
|
||||
mOnPlayerRename.Release();
|
||||
mOnPlayerRequestClass.Release();
|
||||
mOnPlayerRequestSpawn.Release();
|
||||
mOnPlayerSpawn.Release();
|
||||
mOnPlayerStartTyping.Release();
|
||||
mOnPlayerStopTyping.Release();
|
||||
mOnPlayerChat.Release();
|
||||
mOnPlayerCommand.Release();
|
||||
mOnPlayerMessage.Release();
|
||||
mOnPlayerHealth.Release();
|
||||
mOnPlayerArmour.Release();
|
||||
mOnPlayerWeapon.Release();
|
||||
mOnPlayerMove.Release();
|
||||
mOnPlayerWasted.Release();
|
||||
mOnPlayerKilled.Release();
|
||||
mOnPlayerTeamKill.Release();
|
||||
mOnPlayerSpectate.Release();
|
||||
mOnPlayerCrashreport.Release();
|
||||
mOnPlayerBurning.Release();
|
||||
mOnPlayerCrouching.Release();
|
||||
mOnPlayerState.Release();
|
||||
mOnPlayerAction.Release();
|
||||
mOnStateNone.Release();
|
||||
mOnStateNormal.Release();
|
||||
mOnStateShooting.Release();
|
||||
mOnStateDriver.Release();
|
||||
mOnStatePassenger.Release();
|
||||
mOnStateEnterDriver.Release();
|
||||
mOnStateEnterPassenger.Release();
|
||||
mOnStateExitVehicle.Release();
|
||||
mOnStateUnspawned.Release();
|
||||
mOnActionNone.Release();
|
||||
mOnActionNormal.Release();
|
||||
mOnActionAiming.Release();
|
||||
mOnActionShooting.Release();
|
||||
mOnActionJumping.Release();
|
||||
mOnActionLieDown.Release();
|
||||
mOnActionGettingUp.Release();
|
||||
mOnActionJumpVehicle.Release();
|
||||
mOnActionDriving.Release();
|
||||
mOnActionDying.Release();
|
||||
mOnActionWasted.Release();
|
||||
mOnActionEmbarking.Release();
|
||||
mOnActionDisembarking.Release();
|
||||
mOnVehicleRespawn.Release();
|
||||
mOnVehicleExplode.Release();
|
||||
mOnVehicleHealth.Release();
|
||||
mOnVehicleMove.Release();
|
||||
mOnPickupRespawn.Release();
|
||||
mOnKeybindKeyPress.Release();
|
||||
mOnKeybindKeyRelease.Release();
|
||||
mOnVehicleEmbarking.Release();
|
||||
mOnVehicleEmbarked.Release();
|
||||
mOnVehicleDisembark.Release();
|
||||
mOnPickupClaimed.Release();
|
||||
mOnPickupCollected.Release();
|
||||
mOnObjectShot.Release();
|
||||
mOnObjectBump.Release();
|
||||
mOnCheckpointEntered.Release();
|
||||
mOnCheckpointExited.Release();
|
||||
mOnForcefieldEntered.Release();
|
||||
mOnForcefieldExited.Release();
|
||||
mOnServerFrame.Release();
|
||||
mOnServerStartup.Release();
|
||||
mOnServerShutdown.Release();
|
||||
mOnInternalCommand.Release();
|
||||
mOnLoginAttempt.Release();
|
||||
mOnCustomEvent.Release();
|
||||
mOnWorldOption.Release();
|
||||
mOnWorldToggle.Release();
|
||||
mOnScriptReload.Release();
|
||||
mOnScriptUnload.Release();
|
||||
mOnBlipCreated.ReleaseGently();
|
||||
mOnCheckpointCreated.ReleaseGently();
|
||||
mOnForcefieldCreated.ReleaseGently();
|
||||
mOnKeybindCreated.ReleaseGently();
|
||||
mOnObjectCreated.ReleaseGently();
|
||||
mOnPickupCreated.ReleaseGently();
|
||||
mOnPlayerCreated.ReleaseGently();
|
||||
mOnSpriteCreated.ReleaseGently();
|
||||
mOnTextdrawCreated.ReleaseGently();
|
||||
mOnVehicleCreated.ReleaseGently();
|
||||
mOnBlipDestroyed.ReleaseGently();
|
||||
mOnCheckpointDestroyed.ReleaseGently();
|
||||
mOnForcefieldDestroyed.ReleaseGently();
|
||||
mOnKeybindDestroyed.ReleaseGently();
|
||||
mOnObjectDestroyed.ReleaseGently();
|
||||
mOnPickupDestroyed.ReleaseGently();
|
||||
mOnPlayerDestroyed.ReleaseGently();
|
||||
mOnSpriteDestroyed.ReleaseGently();
|
||||
mOnTextdrawDestroyed.ReleaseGently();
|
||||
mOnVehicleDestroyed.ReleaseGently();
|
||||
mOnBlipCustom.ReleaseGently();
|
||||
mOnCheckpointCustom.ReleaseGently();
|
||||
mOnForcefieldCustom.ReleaseGently();
|
||||
mOnKeybindCustom.ReleaseGently();
|
||||
mOnObjectCustom.ReleaseGently();
|
||||
mOnPickupCustom.ReleaseGently();
|
||||
mOnPlayerCustom.ReleaseGently();
|
||||
mOnSpriteCustom.ReleaseGently();
|
||||
mOnTextdrawCustom.ReleaseGently();
|
||||
mOnVehicleCustom.ReleaseGently();
|
||||
mOnPlayerAway.ReleaseGently();
|
||||
mOnPlayerGameKeys.ReleaseGently();
|
||||
mOnPlayerRename.ReleaseGently();
|
||||
mOnPlayerRequestClass.ReleaseGently();
|
||||
mOnPlayerRequestSpawn.ReleaseGently();
|
||||
mOnPlayerSpawn.ReleaseGently();
|
||||
mOnPlayerStartTyping.ReleaseGently();
|
||||
mOnPlayerStopTyping.ReleaseGently();
|
||||
mOnPlayerChat.ReleaseGently();
|
||||
mOnPlayerCommand.ReleaseGently();
|
||||
mOnPlayerMessage.ReleaseGently();
|
||||
mOnPlayerHealth.ReleaseGently();
|
||||
mOnPlayerArmour.ReleaseGently();
|
||||
mOnPlayerWeapon.ReleaseGently();
|
||||
mOnPlayerMove.ReleaseGently();
|
||||
mOnPlayerWasted.ReleaseGently();
|
||||
mOnPlayerKilled.ReleaseGently();
|
||||
mOnPlayerTeamKill.ReleaseGently();
|
||||
mOnPlayerSpectate.ReleaseGently();
|
||||
mOnPlayerCrashreport.ReleaseGently();
|
||||
mOnPlayerBurning.ReleaseGently();
|
||||
mOnPlayerCrouching.ReleaseGently();
|
||||
mOnPlayerState.ReleaseGently();
|
||||
mOnPlayerAction.ReleaseGently();
|
||||
mOnStateNone.ReleaseGently();
|
||||
mOnStateNormal.ReleaseGently();
|
||||
mOnStateShooting.ReleaseGently();
|
||||
mOnStateDriver.ReleaseGently();
|
||||
mOnStatePassenger.ReleaseGently();
|
||||
mOnStateEnterDriver.ReleaseGently();
|
||||
mOnStateEnterPassenger.ReleaseGently();
|
||||
mOnStateExitVehicle.ReleaseGently();
|
||||
mOnStateUnspawned.ReleaseGently();
|
||||
mOnActionNone.ReleaseGently();
|
||||
mOnActionNormal.ReleaseGently();
|
||||
mOnActionAiming.ReleaseGently();
|
||||
mOnActionShooting.ReleaseGently();
|
||||
mOnActionJumping.ReleaseGently();
|
||||
mOnActionLieDown.ReleaseGently();
|
||||
mOnActionGettingUp.ReleaseGently();
|
||||
mOnActionJumpVehicle.ReleaseGently();
|
||||
mOnActionDriving.ReleaseGently();
|
||||
mOnActionDying.ReleaseGently();
|
||||
mOnActionWasted.ReleaseGently();
|
||||
mOnActionEmbarking.ReleaseGently();
|
||||
mOnActionDisembarking.ReleaseGently();
|
||||
mOnVehicleRespawn.ReleaseGently();
|
||||
mOnVehicleExplode.ReleaseGently();
|
||||
mOnVehicleHealth.ReleaseGently();
|
||||
mOnVehicleMove.ReleaseGently();
|
||||
mOnPickupRespawn.ReleaseGently();
|
||||
mOnKeybindKeyPress.ReleaseGently();
|
||||
mOnKeybindKeyRelease.ReleaseGently();
|
||||
mOnVehicleEmbarking.ReleaseGently();
|
||||
mOnVehicleEmbarked.ReleaseGently();
|
||||
mOnVehicleDisembark.ReleaseGently();
|
||||
mOnPickupClaimed.ReleaseGently();
|
||||
mOnPickupCollected.ReleaseGently();
|
||||
mOnObjectShot.ReleaseGently();
|
||||
mOnObjectBump.ReleaseGently();
|
||||
mOnCheckpointEntered.ReleaseGently();
|
||||
mOnCheckpointExited.ReleaseGently();
|
||||
mOnForcefieldEntered.ReleaseGently();
|
||||
mOnForcefieldExited.ReleaseGently();
|
||||
mOnServerFrame.ReleaseGently();
|
||||
mOnServerStartup.ReleaseGently();
|
||||
mOnServerShutdown.ReleaseGently();
|
||||
mOnInternalCommand.ReleaseGently();
|
||||
mOnLoginAttempt.ReleaseGently();
|
||||
mOnCustomEvent.ReleaseGently();
|
||||
mOnWorldOption.ReleaseGently();
|
||||
mOnWorldToggle.ReleaseGently();
|
||||
mOnScriptReload.ReleaseGently();
|
||||
mOnScriptUnload.ReleaseGently();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@ -17,7 +17,7 @@
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
extern Core * _Core;
|
||||
extern SQMOD_MANAGEDPTR_TYPE(Core) _Core;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
@ -471,10 +471,10 @@ public:
|
||||
{
|
||||
if (!_Core)
|
||||
{
|
||||
_Core = new Core();
|
||||
_Core = SQMOD_MANAGEDPTR_MAKE(Core, new Core());
|
||||
}
|
||||
|
||||
return _Core;
|
||||
return SQMOD_MANAGEDPTR_GET(_Core);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
|
@ -59,7 +59,7 @@ enum
|
||||
namespace SqMod {
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Logger * _Log = NULL;
|
||||
SQMOD_MANAGEDPTR_TYPE(Logger) _Log = SQMOD_MANAGEDPTR_MAKE(Logger, nullptr);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
|
@ -23,7 +23,7 @@ enum LogLvl
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
extern Logger * _Log;
|
||||
extern SQMOD_MANAGEDPTR_TYPE(Logger) _Log;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
class Logger
|
||||
@ -49,10 +49,10 @@ public:
|
||||
{
|
||||
if (!_Log)
|
||||
{
|
||||
return _Log = new Logger();
|
||||
return _Log = SQMOD_MANAGEDPTR_MAKE(Logger, new Logger());
|
||||
}
|
||||
|
||||
return _Log;
|
||||
return SQMOD_MANAGEDPTR_GET(_Log);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
111
source/Main.cpp
111
source/Main.cpp
@ -25,20 +25,20 @@ void DestroyComponents()
|
||||
// Destroy command component
|
||||
if (_Cmd)
|
||||
{
|
||||
delete _Cmd;
|
||||
_Cmd = NULL;
|
||||
SQMOD_MANAGEDPTR_DEL(CmdManager, _Cmd);
|
||||
SQMOD_MANAGEDPTR_MAKE(CmdManager, nullptr);
|
||||
}
|
||||
// Destroy core component
|
||||
if (_Core)
|
||||
{
|
||||
delete _Core;
|
||||
_Core = NULL;
|
||||
SQMOD_MANAGEDPTR_DEL(Core, _Core);
|
||||
SQMOD_MANAGEDPTR_MAKE(Core, nullptr);
|
||||
}
|
||||
// Destroy logger component
|
||||
if (_Log)
|
||||
{
|
||||
delete _Log;
|
||||
_Log = NULL;
|
||||
SQMOD_MANAGEDPTR_DEL(Logger, _Log);
|
||||
SQMOD_MANAGEDPTR_MAKE(Logger, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,22 +54,19 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * funcs, PluginCallback
|
||||
OutputMessage("--------------------------------------------------------------------");
|
||||
puts("");
|
||||
|
||||
_Log = Logger::Get();
|
||||
// Verify that core components are working
|
||||
if (!_Log)
|
||||
if (!Logger::Get())
|
||||
{
|
||||
puts("[SQMOD] Unable to start because the logging class could not be instantiated");
|
||||
return SQMOD_FAILURE;
|
||||
}
|
||||
_Core = Core::Get();
|
||||
if (!_Core)
|
||||
if (!Core::Get())
|
||||
{
|
||||
DestroyComponents();
|
||||
puts("[SQMOD] Unable to start because the central core class could not be instantiated");
|
||||
return SQMOD_FAILURE;
|
||||
}
|
||||
_Cmd = CmdManager::Get();
|
||||
if (!_Cmd)
|
||||
if (!CmdManager::Get())
|
||||
{
|
||||
DestroyComponents();
|
||||
puts("[SQMOD] Unable to start because the command class could not be instantiated");
|
||||
@ -775,49 +772,49 @@ void BindCallbacks()
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void UnbindCallbacks()
|
||||
{
|
||||
_Clbk->OnInitServer = NULL;
|
||||
_Clbk->OnShutdownServer = NULL;
|
||||
_Clbk->OnFrame = NULL;
|
||||
_Clbk->OnPlayerConnect = NULL;
|
||||
_Clbk->OnPlayerDisconnect = NULL;
|
||||
_Clbk->OnPlayerBeginTyping = NULL;
|
||||
_Clbk->OnPlayerEndTyping = NULL;
|
||||
_Clbk->OnPlayerRequestClass = NULL;
|
||||
_Clbk->OnPlayerRequestSpawn = NULL;
|
||||
_Clbk->OnPlayerSpawn = NULL;
|
||||
_Clbk->OnPlayerDeath = NULL;
|
||||
_Clbk->OnPlayerUpdate = NULL;
|
||||
_Clbk->OnPlayerRequestEnter = NULL;
|
||||
_Clbk->OnPlayerEnterVehicle = NULL;
|
||||
_Clbk->OnPlayerExitVehicle = NULL;
|
||||
_Clbk->OnPickupClaimPicked = NULL;
|
||||
_Clbk->OnPickupPickedUp = NULL;
|
||||
_Clbk->OnPickupRespawn = NULL;
|
||||
_Clbk->OnVehicleUpdate = NULL;
|
||||
_Clbk->OnVehicleExplode = NULL;
|
||||
_Clbk->OnVehicleRespawn = NULL;
|
||||
_Clbk->OnObjectShot = NULL;
|
||||
_Clbk->OnObjectBump = NULL;
|
||||
_Clbk->OnPublicMessage = NULL;
|
||||
_Clbk->OnCommandMessage = NULL;
|
||||
_Clbk->OnPrivateMessage = NULL;
|
||||
_Clbk->OnInternalCommand = NULL;
|
||||
_Clbk->OnLoginAttempt = NULL;
|
||||
_Clbk->OnEntityPoolChange = NULL;
|
||||
_Clbk->OnKeyBindDown = NULL;
|
||||
_Clbk->OnKeyBindUp = NULL;
|
||||
_Clbk->OnPlayerAwayChange = NULL;
|
||||
_Clbk->OnPlayerSpectate = NULL;
|
||||
_Clbk->OnPlayerCrashReport = NULL;
|
||||
_Clbk->OnServerPerformanceReport = NULL;
|
||||
_Clbk->OnPlayerNameChange = NULL;
|
||||
_Clbk->OnPlayerStateChange = NULL;
|
||||
_Clbk->OnPlayerActionChange = NULL;
|
||||
_Clbk->OnPlayerOnFireChange = NULL;
|
||||
_Clbk->OnPlayerCrouchChange = NULL;
|
||||
_Clbk->OnPlayerGameKeysChange = NULL;
|
||||
_Clbk->OnCheckpointEntered = NULL;
|
||||
_Clbk->OnCheckpointExited = NULL;
|
||||
_Clbk->OnSphereEntered = NULL;
|
||||
_Clbk->OnSphereExited = NULL;
|
||||
_Clbk->OnInitServer = nullptr;
|
||||
_Clbk->OnShutdownServer = nullptr;
|
||||
_Clbk->OnFrame = nullptr;
|
||||
_Clbk->OnPlayerConnect = nullptr;
|
||||
_Clbk->OnPlayerDisconnect = nullptr;
|
||||
_Clbk->OnPlayerBeginTyping = nullptr;
|
||||
_Clbk->OnPlayerEndTyping = nullptr;
|
||||
_Clbk->OnPlayerRequestClass = nullptr;
|
||||
_Clbk->OnPlayerRequestSpawn = nullptr;
|
||||
_Clbk->OnPlayerSpawn = nullptr;
|
||||
_Clbk->OnPlayerDeath = nullptr;
|
||||
_Clbk->OnPlayerUpdate = nullptr;
|
||||
_Clbk->OnPlayerRequestEnter = nullptr;
|
||||
_Clbk->OnPlayerEnterVehicle = nullptr;
|
||||
_Clbk->OnPlayerExitVehicle = nullptr;
|
||||
_Clbk->OnPickupClaimPicked = nullptr;
|
||||
_Clbk->OnPickupPickedUp = nullptr;
|
||||
_Clbk->OnPickupRespawn = nullptr;
|
||||
_Clbk->OnVehicleUpdate = nullptr;
|
||||
_Clbk->OnVehicleExplode = nullptr;
|
||||
_Clbk->OnVehicleRespawn = nullptr;
|
||||
_Clbk->OnObjectShot = nullptr;
|
||||
_Clbk->OnObjectBump = nullptr;
|
||||
_Clbk->OnPublicMessage = nullptr;
|
||||
_Clbk->OnCommandMessage = nullptr;
|
||||
_Clbk->OnPrivateMessage = nullptr;
|
||||
_Clbk->OnInternalCommand = nullptr;
|
||||
_Clbk->OnLoginAttempt = nullptr;
|
||||
_Clbk->OnEntityPoolChange = nullptr;
|
||||
_Clbk->OnKeyBindDown = nullptr;
|
||||
_Clbk->OnKeyBindUp = nullptr;
|
||||
_Clbk->OnPlayerAwayChange = nullptr;
|
||||
_Clbk->OnPlayerSpectate = nullptr;
|
||||
_Clbk->OnPlayerCrashReport = nullptr;
|
||||
_Clbk->OnServerPerformanceReport = nullptr;
|
||||
_Clbk->OnPlayerNameChange = nullptr;
|
||||
_Clbk->OnPlayerStateChange = nullptr;
|
||||
_Clbk->OnPlayerActionChange = nullptr;
|
||||
_Clbk->OnPlayerOnFireChange = nullptr;
|
||||
_Clbk->OnPlayerCrouchChange = nullptr;
|
||||
_Clbk->OnPlayerGameKeysChange = nullptr;
|
||||
_Clbk->OnCheckpointEntered = nullptr;
|
||||
_Clbk->OnCheckpointExited = nullptr;
|
||||
_Clbk->OnSphereEntered = nullptr;
|
||||
_Clbk->OnSphereExited = nullptr;
|
||||
}
|
||||
|
@ -5,7 +5,8 @@
|
||||
#include <sqconfig.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <stddef.h>
|
||||
#include <cstddef>
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@ -269,6 +270,143 @@ typedef LongInt< Uint64 > ULongInt;
|
||||
*/
|
||||
typedef std::basic_string< SQChar > String;
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* A simple managed pointer used to identify if components are still used after shutdown.
|
||||
*/
|
||||
template < typename T > class ManagedPtr
|
||||
{
|
||||
private:
|
||||
|
||||
T * m_Ptr;
|
||||
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Base constructor.
|
||||
*/
|
||||
ManagedPtr(T * ptr)
|
||||
: m_Ptr(ptr)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor. (disabled)
|
||||
*/
|
||||
ManagedPtr(const ManagedPtr & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor. (disabled)
|
||||
*/
|
||||
ManagedPtr(ManagedPtr && o)
|
||||
: m_Ptr(o.m_Ptr)
|
||||
{
|
||||
o.m_Ptr = nullptr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~ManagedPtr()
|
||||
{
|
||||
if (m_Ptr)
|
||||
{
|
||||
delete m_Ptr;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator. (disabled)
|
||||
*/
|
||||
ManagedPtr & operator = (const ManagedPtr & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator. (disabled)
|
||||
*/
|
||||
ManagedPtr & operator = (ManagedPtr && o)
|
||||
{
|
||||
if (m_Ptr != o.m_Ptr)
|
||||
{
|
||||
if (m_Ptr)
|
||||
{
|
||||
delete m_Ptr;
|
||||
}
|
||||
m_Ptr = o.m_Ptr;
|
||||
o.m_Ptr = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to boolean for use in boolean operations.
|
||||
*/
|
||||
operator bool () const
|
||||
{
|
||||
return m_Ptr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to the managed pointer type.
|
||||
*/
|
||||
operator T * () const
|
||||
{
|
||||
return m_Ptr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to the managed pointer type.
|
||||
*/
|
||||
operator const T * () const
|
||||
{
|
||||
return m_Ptr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Member operator for dereferencing the managed pointer.
|
||||
*/
|
||||
T * operator -> () const
|
||||
{
|
||||
assert(m_Ptr != nullptr);
|
||||
return m_Ptr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Indirection operator for obtaining a reference of the managed pointer.
|
||||
*/
|
||||
T & operator * () const
|
||||
{
|
||||
assert(m_Ptr != nullptr);
|
||||
return *m_Ptr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the managed pointer in it's raw form.
|
||||
*/
|
||||
T * Get() const
|
||||
{
|
||||
return m_Ptr;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#define SQMOD_MANAGEDPTR_TYPE(t) ManagedPtr< t >
|
||||
#define SQMOD_MANAGEDPTR_REF(t) ManagedPtr< t > &
|
||||
#define SQMOD_MANAGEDPTR_MAKE(t, p) ManagedPtr< t >(p)
|
||||
#define SQMOD_MANAGEDPTR_DEL(t, p) p = ManagedPtr< t >(nullptr)
|
||||
#define SQMOD_MANAGEDPTR_GET(p) p.Get();
|
||||
|
||||
#else
|
||||
|
||||
#define SQMOD_MANAGEDPTR_TYPE(t) t *
|
||||
#define SQMOD_MANAGEDPTR_REF(t) t *
|
||||
#define SQMOD_MANAGEDPTR_MAKE(t, p) p
|
||||
#define SQMOD_MANAGEDPTR_DEL(t, p) delete p
|
||||
#define SQMOD_MANAGEDPTR_GET(p) p
|
||||
|
||||
#endif // _DEBUG
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* FORWARD DECLARATIONS
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user