AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Invalid cellvector handle (https://forums.alliedmods.net/showthread.php?t=309345)

edon1337 07-22-2018 18:08

Invalid cellvector handle
 
Am I missing something here?

PHP Code:

enum _:OriginDimensions
{
    
Float:ORIGIN]
}

new Array:
g_aOrigins;

public 
plugin_init( )
{
    
SsInit1000.0 );
    
SsScan( );
    
SsDump( );
    
    
RetrieveOrigins( );
}

public 
plugin_precache( )
{
    
g_aOrigins ArrayCreateOriginDimensions );
}

public 
RoundStarted( )
{
    
ArrayClearg_aOrigins );
    
RetrieveOrigins( );
    
    
GetRandomOriginfOrigin );
    
    
// code
}

RetrieveOrigins( )
{
    new 
Float:fOrigin];
    
    for( new 
i=1<= MAX_ORIGINSi++ )
    {
        if( 
SsGetOriginfOrigin ) )
        {
            
SaveOriginfOrigin );
        }
    }
}

SaveOriginFloat:fOrigin] )
{
    new 
eDataOriginDimensions ];

    
eDataORIGIN ][ ] = _:fOrigin];
    
eDataORIGIN ][ ] = _:fOrigin];
    
eDataORIGIN ][ ] = _:fOrigin];
    
    
ArrayPushArrayg_aOriginseData );
}

GetRandomOriginFloat:fOrigin] )
{
    new 
eDataOriginDimensions ];

    new 
iRandomEntry random_num0ArraySizeg_aOrigins ) );
    
    
ArrayGetArrayg_aOriginsiRandomEntryeData );

    
fOrigin] = eDataORIGIN ][ ];
    
fOrigin] = eDataORIGIN ][ ];
    
fOrigin] = eDataORIGIN ][ ];
    
    
ArrayDeleteItemg_aOriginsiRandomEntry );


Quote:

L 07/22/2018 - 23:21:53: Invalid cellvector handle provided (1:0:0)
L 07/22/2018 - 23:21:53: [AMXX] Displaying debug trace (plugin "CsBattleRoyale.amxx")
L 07/22/2018 - 23:21:53: [AMXX] Run time error 10: native error (native "ArrayGetArray")
L 07/22/2018 - 23:21:53: [AMXX] [0] CsBattleRoyale.sma::GetRandomOrigin (line 1011)
L 07/22/2018 - 23:21:53: [AMXX] [1] CsBattleRoyale.sma::RoundStarted (line 375)

OciXCrom 07-22-2018 18:36

Re: Invalid cellvector handle
 
The line numbers.
ArrayCreate() was not called before using ArrayGetArray().

edon1337 07-22-2018 18:50

Re: Invalid cellvector handle
 
Quote:

Originally Posted by OciXCrom (Post 2605482)
The line numbers.
ArrayCreate() was not called before using ArrayGetArray().

It's already obvious, how many times is ArrayGetArray being used? Once.

Quote:

Originally Posted by OciXCrom (Post 2605482)
ArrayCreate() was not called before using ArrayGetArray().

Don't really get it, I'm using ArrayClear not ArrayDestroy, so why would I have to call ArrayCreate every time?

maqi 07-22-2018 20:06

Re: Invalid cellvector handle
 
You are trying to get from an empty array.

OciXCrom 07-22-2018 21:07

Re: Invalid cellvector handle
 
If the array was empty, the error would have been "invalid index", not "invalid handle". The only way this error can show if is either ArrayCreate() wasn't called or ArrayDestroy() was used. Check your entire plugin_precache() function, something may be preventing the code from reaching ArrayCreate() - check your error logs for other errors in the plugin, especially when starting the server.

maqi 07-22-2018 21:25

Re: Invalid cellvector handle
 
I think you are wrong. It's always the same error, where the first parameter indicates the handle id, the second index to get and the third size of the array, as the size is 0, there is nothing to get, therefor the error.

Code:

// ArrayGetArray(Array:which, item, any:output[]);
static cell AMX_NATIVE_CALL ArrayGetArray(AMX* amx, cell* params)
{
        CellVector* vec=HandleToVector(amx, params[1]);

        if (vec==NULL)
        {
                return 0;
        }

        if (vec->GetArray(params[2],get_amxaddr(amx, params[3]))!=1)
        {
                LogError(amx, AMX_ERR_NATIVE, "Invalid cellvector handle provided (%d:%d:%d)", params[1], params[2], vec->Size());
                return 0;
        }

        return 1;
}


Natsheh 07-23-2018 07:41

Re: Invalid cellvector handle
 
Check if the array is not empty.

edon1337 07-23-2018 07:46

Re: Invalid cellvector handle
 
Quote:

Originally Posted by Natsheh (Post 2605564)
Check if the array is not empty.

Is there a native for it or do I check manually each item?

maqi 07-23-2018 07:47

Re: Invalid cellvector handle
 
ArraySize()

OciXCrom 07-23-2018 07:57

Re: Invalid cellvector handle
 
Quote:

Originally Posted by maqi (Post 2605507)
I think you are wrong. It's always the same error, where the first parameter indicates the handle id, the second index to get and the third size of the array, as the size is 0, there is nothing to get, therefor the error.

Code:

// ArrayGetArray(Array:which, item, any:output[]);
static cell AMX_NATIVE_CALL ArrayGetArray(AMX* amx, cell* params)
{
        CellVector* vec=HandleToVector(amx, params[1]);

        if (vec==NULL)
        {
                return 0;
        }

        if (vec->GetArray(params[2],get_amxaddr(amx, params[3]))!=1)
        {
                LogError(amx, AMX_ERR_NATIVE, "Invalid cellvector handle provided (%d:%d:%d)", params[1], params[2], vec->Size());
                return 0;
        }

        return 1;
}


Um, where did you even find that? The code in github is completelly different:

PHP Code:

// native ArrayGetArray(Array:which, item, any:output[], size = -1);
static cell AMX_NATIVE_CALL ArrayGetArray(AMXamxcellparams)
{
    
CellArrayvec ArrayHandles.lookup(params[1]);

    if (!
vec)
    {
        
LogError(amxAMX_ERR_NATIVE"Invalid array handle provided (%d)"params[1]);
        return 
0;
    }

    
size_t idx = (size_t)params[2];

    if (
idx >= vec->size())
    {
        
LogError(amxAMX_ERR_NATIVE"Invalid index %d (count: %d)"idxvec->size());
        return 
0;
    }

    
cell *blk vec->at(idx);
    
size_t indexes vec->blocksize();

    if (*
params sizeof(cell) == 4)
    {
        if (
params[4] != -&& (size_t)params[4] <= vec->blocksize())
        {
            
indexes params[4];
        }
    }

    
cell *addr get_amxaddr(amxparams[3]);

    
memcpy(addrblksizeof(cell) * indexes);

    return 
indexes;


I assume it's much different in 1.8.2.


All times are GMT -4. The time now is 19:43.

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