Raised This Month: $7 Target: $400
 1% 

Handle Crash when it gets deleted


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xerox8521
Senior Member
Join Date: Sep 2011
Old 08-18-2017 , 21:39   Handle Crash when it gets deleted
Reply With Quote #1

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/*parent*/, &tacc, &haccmyself->GetIdentity(), &err);
    
    if(
g_NavAreaHandle == 0)
    {
        
snprintf(errormaxlength"Could not create CNavArea handle type (err: %d)",err);
        return 
false;
    } 
This is in SDK_OnUnload
PHP Code:
handlesys->RemoveType(g_NavAreaHandlemyself->GetIdentity()); 

The handle destroy function

PHP Code:
void L4D2Hooks::OnHandleDestroy(HandleType_t typevoid *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(addrCallConv_ThisCall, &retInfoNULL0));
    }
    
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_NavAreaHandlepNavAreapContext->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 typevoidobject); 
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");

xerox8521 is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 08-19-2017 , 03:19   Re: Handle Crash when it gets deleted
Reply With Quote #2

The return value of GetLastKnownArea is probably not meant to be deleted by you -- and the CNavArea destructor you've created knows nothing about the real CNavArea class layout and will not be doing the job correctly anyway.
__________________
asherkin is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:17.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode