Hi, so i have been trying to mess around with the handle system now it works all fine until i try to either reload the plugin or use delete on the handle in SM. Im not sure why. Error is that the Programm terminated with signal 6. From the looks of the error code its like delete its called multiple times on the object itself ? Not sure
Game: L4D2
OS: Linux CentOS 7 64-Bit
SM Version:
Code:
SourceMod Version Information:
SourceMod Version: 1.9.0.6055
SourcePawn Engine: 1.9.0.6055, jit-x86 (build 1.9.0.6055)
SourcePawn API: v1 = 4, v2 = 12
Compiled on: Feb 9 2017 15:06:37
Built from: https://github.com/alliedmodders/sourcemod/commit/61f4684
Build ID: 6055:61f4684
http://www.sourcemod.net/
MM Version:
Code:
Metamod:Source Version Information
Metamod:Source version 1.11.0-dev+998
Plugin interface version: 15:14
SourceHook version: 5:5
Loaded As: Valve Server Plugin
Compiled on: Sep 18 2015 19:37:39
Built from: https://github.com/alliedmodders/metamod-source/commit/ebf29da
Build ID: 998:ebf29da
http://www.metamodsource.net/
This is in SDK_OnLoad:
PHP Code:
HandleError err;
TypeAccess tacc;
HandleAccess hacc;
handlesys->InitAccessDefaults(&tacc, &hacc);
tacc.access[HTypeAccess_Create] = true;
tacc.access[HTypeAccess_Inherit] = false;
tacc.ident = myself->GetIdentity();
hacc.access[HandleAccess_Read] = HANDLE_RESTRICT_OWNER;
hacc.access[HandleAccess_Delete] = HANDLE_RESTRICT_OWNER;
g_NavAreaHandle = handlesys->CreateType("CNavArea", this, 0 /*parent*/, &tacc, &hacc, myself->GetIdentity(), &err);
if(g_NavAreaHandle == 0)
{
snprintf(error, maxlength, "Could not create CNavArea handle type (err: %d)",err);
return false;
}
This is in SDK_OnUnload
PHP Code:
handlesys->RemoveType(g_NavAreaHandle, myself->GetIdentity());
The handle destroy function
PHP Code:
void L4D2Hooks::OnHandleDestroy(HandleType_t type, void *object)
{
if(type == g_NavAreaHandle && object != NULL)
{
delete (CNavArea *)object;
}
}
Created in this native:
PHP Code:
cell_t Native_GetNavArea(IPluginContext *pContext, const cell_t *params)
{
static ICallWrapper *pWrapper = NULL;
if(!pWrapper)
{
REGISTER_NATIVE_ADDR("CTerrorPlayer::GetLastKnownArea",
PassInfo retInfo;\
retInfo.flags = PASSFLAG_BYVAL;\
retInfo.size = sizeof(CBaseEntity *);\
retInfo.type = PassType_Basic;\
pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, &retInfo, NULL, 0));
}
unsigned char vstk[sizeof(CBaseEntity*)];
unsigned char *vptr = vstk;
CBaseEntity *pPlayer = UTIL_GetCBaseEntity(params[1], true);
if(!pPlayer)
{
return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
}
*(CBaseEntity**)vptr = pPlayer;
CNavArea *pNavArea = NULL;
pWrapper->Execute(vstk, &pNavArea);
if(pNavArea)
{
Handle_t NavArea = handlesys->CreateHandle(g_NavAreaHandle, pNavArea, pContext->GetIdentity(), myself->GetIdentity(), NULL);
if(NavArea == BAD_HANDLE)
{
delete pNavArea;
return BAD_HANDLE;
}
else
{
return NavArea; //Valid Handle return it
}
}
else
{
return BAD_HANDLE;
}
}
extension.h -
Not the entire file
PHP Code:
class L4D2Hooks :
public SDKExtension,
public ICommandTargetProcessor,
public IHandleTypeDispatch
{
public:
virtual void OnHandleDestroy(HandleType_t type, void* object);
In extension.cpp
PHP Code:
HandleType_t g_NavAreaHandle = 0;
Made a CNavArea.h/cpp
PHP Code:
#ifndef _INCLUDE_L4D2HOOKS_NAVAREA
#define _INCLUDE_L4D2HOOKS_NAVAREA
#include <IHandleSys.h>
class CNavArea
{
public:
CNavArea();
~CNavArea();
};
#endif // _INCLUDE_L4D2HOOKS_NAVAREA
PHP Code:
#include "extension.h"
#include "CNavArea.h"
CNavArea::CNavArea()
{
g_pSM->LogMessage(myself,"CNavArea created");
}
CNavArea::~CNavArea()
{
g_pSM->LogMessage(myself,"CNavArea destroyed");
}