Raised This Month: $51 Target: $400
 12% 

What exactly am I doing wrong? Sourcemod bug??


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 12-05-2016 , 16:43   What exactly am I doing wrong? Sourcemod bug??
Reply With Quote #1

Right, so I have made a quick system which adds weapons to an array then respawns them.

But it appears that midway through my loop, my client index becomes invalid, this makes no sense whatsoever.

Here are the error logs:

PHP Code:
L 12/05/2016 21:38:48: [manicure.smxClient is named SM9(); [1]
L 12/05/2016 21:38:48: [manicure.smxClient is named Console [2]
L 12/05/2016 21:38:48: [manicure.smxClient is named Console [3]
L 12/05/2016 21:38:48: [manicure.smxClient is named Console [4]
L 12/05/2016 21:38:48: [manicure.smxClient is named Console [5]
L 12/05/2016 21:38:48: [SMException reportedEntity index 0 is not a valid client
L 12
/05/2016 21:38:48: [SMBlamingmanicure.smx
L 12
/05/2016 21:38:48: [SMCall stack trace:
L 12/05/2016 21:38:48: [SM]   [0GivePlayerItem
L 12
/05/2016 21:38:48: [SM]   [1Line 417C:\Users\Michael\Documents\manicure.sp::Timer_GiveWeapons
L 12
/05/2016 21:38:48: [SMException reportedInvalid Handle 0 (error4)
L 12/05/2016 21:38:48: [SMBlamingmanicure.smx
L 12
/05/2016 21:38:48: [SMCall stack trace:
L 12/05/2016 21:38:48: [SM]   [0ArrayList.Length.get
L 12
/05/2016 21:38:48: [SM]   [1Line 392C:\Users\Michael\Documents\manicure.sp::Timer_GiveWeapons
L 12
/05/2016 21:38:48: [SMException reportedInvalid Handle 0 (error4)
L 12/05/2016 21:38:48: [SMBlamingmanicure.smx
L 12
/05/2016 21:38:48: [SMCall stack trace:
L 12/05/2016 21:38:48: [SM]   [0ArrayList.Clear
L 12
/05/2016 21:38:48: [SM]   [1Line 422C:\Users\Michael\Documents\manicure.sp::Timer_GiveWeapons
L 12
/05/2016 21:38:48: [SMException reportedStack leak detectedsp:4402556 should be 4402564
Here is the code:
PHP Code:
stock void AddToWeaponRespawnArray(int iClientint iWeapon = -1, const char[] chClassName)
{
    if (
g_alGiveWeapons[iClient] == null) {
        
g_alGiveWeapons[iClient] = new ArrayList(128);
    }
    
    
CEconItemView ceItemint iReserveAmmo = -1int iClipAmmo = -1;
    
    if (
IsValidEntity(iWeapon)) {
        
ceItem PTaH_GetEconItemViewFromWeapon(iWeapon);
        
iReserveAmmo GetEntProp(iWeaponProp_Send"m_iPrimaryReserveAmmoCount");
        
iClipAmmo GetEntProp(iWeaponProp_Send"m_iClip1");
    }
    
    
int iValues[4];
    
    
iValues[0] = iReserveAmmo;
    
iValues[1] = iClipAmmo;
    
iValues[2] = view_as<int>(ceItem);
    
iValues[3] = StringToInt(chClassName);
    
    
g_alGiveWeapons[iClient].PushArray(iValues);
}

public 
Action Timer_GiveWeapons(Handle hTimerint iSerial)
{
    
int iClient GetClientFromSerial(iSerial);
    
    if (!
IsValidClient(iClient)) {
        return 
Plugin_Stop;
    }
    
    if (!
IsPlayerAlive(iClient)) {
        return 
Plugin_Continue;
    }
    
    
char chBuffer[64]; int iValues[4];
    
    for (
int i 0g_alGiveWeapons[iClient].Lengthi++) {
        
LogError("Client is named %N [1]"iClient);
        
        
g_alGiveWeapons[iClient].GetArray(iiValues);
        
        
LogError("Client is named %N [2]"iClient);
        
        
int iReserveAmmo iValues[0]; int iClipAmmo iValues[1];
        
        
LogError("Client is named %N [3]"iClient);
        
        
CEconItemView ceItem view_as<CEconItemView>(iValues[2]); 
        
        
LogError("Client is named %N [4]"iClient);
        
        
IntToString(iValues[2], chBuffer64);
        
        
LogError("Client is named %N [5]"iClient);
        
        if (
StrEqual(chBuffer"weapon_c4"false)) {
            
PTaH_GivePlayerItem(iClient"weapon_c4"ceItem);
        } else {
            if (
iReserveAmmo > -|| iClipAmmo > -1) {
                
CSGOItems_GiveWeapon(iClientchBufferiReserveAmmoiClipAmmoCSGOItems_GetActiveWeaponSlot(iClient));
            } else {
                
GivePlayerItem(iClientchBuffer);
            }
        }
    }
    
    
g_alGiveWeapons[iClient].Clear();
    
g_bGivingWeaponsPending[iClient] = false;
    
delete g_alGiveWeapons[iClient];
    
    
g_hGiveTimer[iClient] = null;
    return 
Plugin_Stop;

Should I file a bug report?
SM9 is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 12-05-2016 , 18:51   Re: What exactly am I doing wrong? Sourcemod bug??
Reply With Quote #2

What's your compiler version?
Fyren is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 12-06-2016 , 03:41   Re: What exactly am I doing wrong? Sourcemod bug??
Reply With Quote #3

You need add this
PHP Code:
public Action Timer_GiveWeapons(Handle hTimerint iSerial

    
int iClient GetClientFromSerial(iSerial); 
     
    if (!
iClient && !IsValidClient(iClient)) { 
        return 
Plugin_Stop
    } 
or add this check in function IsValidClient()
Bkz
Quote:
GetClientFromSerial Function

Returns the client index by its serial number.

int GetClientFromSerial(int serial)
Parameters

int serial
Serial number.

Return Value
Client index, or 0 for invalid serial.
__________________
Grey83 is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 12-06-2016 , 03:52   Re: What exactly am I doing wrong? Sourcemod bug??
Reply With Quote #4

Wait
Quote:
L 12/05/2016 - 218:48: [manicure.smx] Client is named SM9(); [1]
L 12/05/2016 - 218:48: [manicure.smx] Client is named Console [2]
A player at this moment gone from the server?

Why not just make something like that?
PHP Code:
int iBufferValues[MAXPLAYERS+1][4];

stock void AddToWeaponRespawnArray(int iClientint iWeapon = -1, const char[] chClassName)
{
    if(!
iClient || !IsValidClient(iClient)) return;

    
iBufferValues[0] = iBufferValues[1] = -1;
    if (
IsValidEntity(iWeapon))
    {
        
iBufferValues[iClient][0] = GetEntProp(iWeaponProp_Send"m_iPrimaryReserveAmmoCount");
        
iBufferValues[iClient][1] = GetEntProp(iWeaponProp_Send"m_iClip1");
        
iBufferValues[iClient][2] = view_as<int>(PTaH_GetEconItemViewFromWeapon(iWeapon));
        
iBufferValues[iClient][3] = StringToInt(chClassName);
    }
}

public 
Action Timer_GiveWeapons(Handle hTimerint iSerial)
{
    
int iClient GetClientFromSerial(iSerial);

    if (!
IsValidClient(iClient)) return Plugin_Stop;

    if (!
IsPlayerAlive(iClient)) return Plugin_Continue;

    
int iReserveAmmo iBufferValues[iClient][0];
    
int iClipAmmo iBufferValues[iClient][1];
    
CEconItemView ceItem view_as<CEconItemView>(iBufferValues[iClient][2]);
    
char chBuffer[64];
    
IntToString(iBufferValues[3], chBuffer64);

    if (
StrEqual(chBuffer"weapon_c4"false))
        
PTaH_GivePlayerItem(iClient"weapon_c4"ceItem);
    else
    {
        if (
iReserveAmmo > -|| iClipAmmo > -1)
            
CSGOItems_GiveWeapon(iClientchBufferiReserveAmmoiClipAmmoCSGOItems_GetActiveWeaponSlot(iClient));
        else 
GivePlayerItem(iClientchBuffer);
    }

    
g_bGivingWeaponsPending[iClient] = false;

    
g_hGiveTimer[iClient] = null;
    return 
Plugin_Stop;

__________________

Last edited by Grey83; 12-06-2016 at 08:52.
Grey83 is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 12-06-2016 , 23:37   Re: What exactly am I doing wrong? Sourcemod bug??
Reply With Quote #5

You creatrle the ArrayList with a blocksize of 128, but only store arrays of size 4 in it.

The docs say, you have to use the |size| parameter when using the GetArrayArray functions with a different sized array. Otherwise it will assume the array has the same size as the block size and paper over random plugin memory, if you pass a smaller buffer.
__________________
Peace-Maker is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 12-07-2016 , 06:10   Re: What exactly am I doing wrong? Sourcemod bug??
Reply With Quote #6

lol wtf every string function requires size parameter, why is it suddenly optional there?
Miu is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 12-08-2016 , 04:54   Re: What exactly am I doing wrong? Sourcemod bug??
Reply With Quote #7

It's not a "string function."
Fyren is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 12-09-2016 , 20:15   Re: What exactly am I doing wrong? Sourcemod bug??
Reply With Quote #8

=__= yes, but they have exactgly the same problem
Miu is offline
Reply



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 19:59.


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