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

RemoveFromArray doesn't remove array index 100%, bug or just me


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
klausenbusk
AlliedModders Donor
Join Date: Jan 2011
Old 05-08-2011 , 14:41   RemoveFromArray doesn't remove array index 100%, bug or just me
Reply With Quote #1

Hallo people

I made ​​this little plugin, to show what the problem is
PHP Code:
#include <sourcemod>
#pragma semicolon 1
new Handle:Array;

public 
Plugin:myinfo =
{
    
name "Array-BUG",
    
author "KK",
    
description "Array-BUG ex",
    
version "1.0",
    
url "http://www.attack2.co.cc/"
};

public 
OnPluginStart()
{
    Array = 
CreateArray(4);
    
RegConsoleCmd("sm_acurrnet"Command_aCurrent);
    
RegConsoleCmd("sm_aset"Command_aSet);
}

public 
Action:Command_aCurrent(clientargs)
{
        new 
index FindValueInArray(Array, GetClientUserId(client));
        new 
any:cell1 GetArrayCell(Array, index1);
        new 
any:cell2 GetArrayCell(Array, index2);
        new 
any:cell3 GetArrayCell(Array, index3);
        
PrintToChat(client"Cell 1 %f | 2 %f | 2 %f"cell1cell2cell3);
}

public 
Action:Command_aSet(clientargs)
{
        new 
index FindValueInArray(Array, GetClientUserId(client));
        
SetArrayCell(Array, index9.01);
        
SetArrayCell(Array, index8.02);
        
SetArrayCell(Array, index7.03);
        
PrintToChat(client"Done");
}

public 
OnClientPostAdminCheck(client)
{
    
PrintToServer("2Before size %i"GetArraySize(Array));
    
PushArrayCell(Array, GetClientUserId(client));
    
PrintToServer("2After size %i"GetArraySize(Array));
}

public 
OnClientDisconnect(client)
{
    new 
index FindValueInArray(Array, GetClientUserId(client));
    
PrintToServer("Before size %i"GetArraySize(Array));
    if (
index != -1)
    {
        
PrintToServer("Removed");
        
RemoveFromArray(Array, index);
    }
    
PrintToServer("After size %i"GetArraySize(Array));
    
PrintToServer("ClientDisconnect");

PHP Code:
public OnClientPostAdminCheck(client)
{
    
PrintToServer("2Before size %i"GetArraySize(Array));
    
PushArrayCell(Array, GetClientUserId(client));
    
PrintToServer("2After size %i"GetArraySize(Array));

When a player join the server, become their userid pushed to my array named array

If this player type sm_acurrnet in console, he get:
Code:
Cell 1 -0.000027 | 2 0.000000 | 2 0.000000
Normal?
after that he type sm_aset in chat, and then sm_acurrent and he get:
Code:
Cell 1 9.000000 | 2 8.000000 | 2 7.000000
Now he rejoin, and type sm_acurrent, and get:
Code:
Cell 1 9.000000 | 2 8.000000 | 2 7.000000
WTF?
Why do i get this?, I've removed the array index, which stores this information when you disconnect

PHP Code:
public OnClientDisconnect(client)
{
    new 
index FindValueInArray(Array, GetClientUserId(client));
    
PrintToServer("Before size %i"GetArraySize(Array));
    if (
index != -1)
    {
        
PrintToServer("Removed");
        
RemoveFromArray(Array, index);
    }
    
PrintToServer("After size %i"GetArraySize(Array));
    
PrintToServer("ClientDisconnect");

When this player disconnect, i get:
Code:
Before size 1
Removed
After size 0
In my server console!

PHP Code:
public OnClientPostAdminCheck(client)
{
    
PrintToServer("2Before size %i"GetArraySize(Array));
    
PushArrayCell(Array, GetClientUserId(client));
    
PrintToServer("2After size %i"GetArraySize(Array));

When i have PostAdminCheck, i get:
Code:
2Before size 0
2After size 1
Do i something wrong?, are it normally? or a bug?
(hope you understand, not the best to English )
Attached Files
File Type: sp Get Plugin or Get Source (array-bug.sp - 202 views - 1.4 KB)
klausenbusk is offline
AtomicStryker
Veteran Member
Join Date: Apr 2009
Location: Teutonia!!
Old 05-08-2011 , 17:17   Re: RemoveFromArray doesn't remove array index 100%, bug or just me
Reply With Quote #2

Quote:
Originally Posted by klausenbusk View Post
}[/php]When a player join the server, become their userid pushed to my array named array

If this player type sm_acurrnet in console, he get:
Code:
Cell 1 -0.000027 | 2 0.000000 | 2 0.000000
Normal?
From scripting API:
Note that data will NOT be auto-intialized.

Hence YES, normal.


If there is not much data movement going on on the server the values may fully well still be there if you re-allocate memory to the same array.


After creating the Array initialize it empty if you insist

Array = CreateArray(4);
ClearArray(Array);

EDIT: actually im not sure that would result in the array being all 0


And if you want the memory scrubbed you have to overwrite it

PrintToServer("Removed");

SetArrayCell(Array, index, 0.0, 1);
SetArrayCell(Array, index, 0.0, 2);
SetArrayCell(Array, index, 0.0, 3);

RemoveFromArray(Array, index);

Last edited by AtomicStryker; 05-08-2011 at 17:22.
AtomicStryker is offline
Kevin_b_er
SourceMod Donor
Join Date: Feb 2009
Old 05-08-2011 , 19:43   Re: RemoveFromArray doesn't remove array index 100%, bug or just me
Reply With Quote #3

Do not refer to indexes which do not exist. You'll get garbage data. (In this case old data, since the exact same memory got used)
__________________
Kevin_b_er is offline
klausenbusk
AlliedModders Donor
Join Date: Jan 2011
Old 05-10-2011 , 08:00   Re: RemoveFromArray doesn't remove array index 100%, bug or just me
Reply With Quote #4

Thanks for answer
klausenbusk 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 11:55.


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