AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Invalid Trie Handle (https://forums.alliedmods.net/showthread.php?t=147421)

Elusive138 01-09-2011 06:09

Invalid Trie Handle
 
I'm experimenting with tries and ran across an invalid trie handle provided error when I tried TrieSetArray.


PHP Code:

TrieSetArray(cooldownTriekeybuffersizeof(buffer)) 

PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "Elusive"


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /test2""Debug_Test2")
}

stock Float:CheckCooldown(index=0Float:cooldownTime=0.0id=0bool:readonly=falsebool:remove=false)
{
    static 
Trie:cooldownTrie
    
new key[16], Float:buffer[33
    
    if (!
cooldownTrie)
    {
        
cooldownTrie TrieCreate()
    }
    if (
cooldownTrie == Invalid_Trie)
    {
        
set_fail_state("Invalid Handle")
    }
    
formatex(keycharsmax(key), "ID%i"id)
    
    if (
remove)
    {
        if (
TrieKeyExists(cooldownTriekey))
        {
            
TrieDeleteKey(cooldownTriekey)
            return 
Float:1
        
}
        else
        {
            return 
Float:0
        
}
    }
    
    if (
TrieKeyExists(cooldownTriekey))
    {
        
TrieGetArray(cooldownTriekeybuffersizeof(buffer))
    }
    
    new 
Float:currentTime get_gametime()
    if (
buffer[index] > currentTime)
    {
        return (
buffer[index] - currentTime)
    }
    if (
readonly)
    {
        return 
Float:0
    
}
    
    
buffer[index] = currentTime cooldownTime
    
    TrieSetArray
(cooldownTriekeybuffersizeof(buffer))
    
    return 
Float:0
}

public 
Debug_Test2(id)
{
    
client_print(idprint_chat"ID = 222, cooldown = %f"CheckCooldown(id5.0222__))
    
client_print(idprint_chat"ID = 555, cooldown = %f"CheckCooldown(id10.0555__))
    
client_print(idprint_chat"ID = 222, cooldown = %f"CheckCooldown(id5.0222__))
    
client_print(idprint_chat"ID = 555, cooldown = %f"CheckCooldown(id10.0555__))
    
client_print(idprint_chat"ID = 222, cooldown = %f"CheckCooldown(id5.0222_true))
    
client_print(idprint_chat"ID = 555, cooldown = %f"CheckCooldown(id10.0555_true))
    
client_print(idprint_chat"ID = 222, cooldown = %f"CheckCooldown(id5.0222__))
    
client_print(idprint_chat"ID = 555, cooldown = %f"CheckCooldown(id10.0555__))


Code:

L 01/10/2011 - 15:25:44: Invalid trie handle provided (1)
L 01/10/2011 - 15:25:44: [AMXX] Displaying debug trace (plugin "Debug.amxx")
L 01/10/2011 - 15:25:44: [AMXX] Run time error 10: native error (native "TrieSetArray")
L 01/10/2011 - 15:25:44: [AMXX]    [0] Debug.sma::CheckCooldown (line 62)
L 01/10/2011 - 15:25:44: [AMXX]    [1] Debug.sma::Debug_Test2 (line 69)

Any help/advice would be appreciated.

Also, can anyone explain what this part of trietest.sma does?
PHP Code:

stock check_frees()
{
    if (
TrieMallocCount() != TrieFreeCount())
        
fail("free count == malloc count");

    else
        
pass("free count == malloc count");

    
server_print("malloc count: %d free count: %d"TrieMallocCount(), TrieFreeCount());



Arkshine 01-09-2011 07:16

Re: Invalid Trie Handle
 
Show the whole code.

Elusive138 01-09-2011 07:29

Re: Invalid Trie Handle
 
If you can make any sense out of this mess... :|
called on /test2
I did the same thing with Dynamic Arrays, and that worked.
PHP Code:

stock Float:CheckCooldown(index=0Float:cooldownTime=0.0id=0bool:readonly=falsebool:remove=false)
{
    static 
Trie:cooldownTrie
    
new key[16], Float:buffer[33
    
    if (!
cooldownTrie)
    {
        
cooldownTrie TrieCreate()
    }
    if (
cooldownTrie == Invalid_Trie)
    {
        
set_fail_state("Invalid Handle")
    }
    
formatex(keycharsmax(key), "ID%i"id)
    
    if (
remove)
    {
        if (
TrieKeyExists(cooldownTriekey))
        {
            
TrieDeleteKey(cooldownTriekey)
            return 
Float:1
        
}
        else
        {
            return 
Float:0
        
}
    }
    
    if (
TrieKeyExists(cooldownTriekey))
    {
        
TrieGetArray(cooldownTriekeybuffersizeof(buffer))
    }
        
    new 
Float:currentTime get_gametime()
    if (
buffer[index] > currentTime)
    {
        return (
buffer[index] - currentTime)
    }
    if (
readonly)
    {
        return 
Float:0
    
}
    
    
buffer[index] = currentTime cooldownTime

    TrieSetArray
(cooldownTriekeybuffersizeof(buffer))

    return 
Float:0
}

public 
Debug_Test2(id)
{
    
client_print(idprint_chat"ID = 222, cooldown = %f"CheckCooldown(id5.0222__))
    
client_print(idprint_chat"ID = 555, cooldown = %f"CheckCooldown(id10.0555__))
    
client_print(idprint_chat"ID = 222, cooldown = %f"CheckCooldown(id5.0222__))
    
client_print(idprint_chat"ID = 555, cooldown = %f"CheckCooldown(id10.0555__))
    
client_print(idprint_chat"ID = 222, cooldown = %f"CheckCooldown(id5.0222_true))
    
client_print(idprint_chat"ID = 555, cooldown = %f"CheckCooldown(id10.0555_true))
    
client_print(idprint_chat"ID = 222, cooldown = %f"CheckCooldown(id5.0222__))
    
client_print(idprint_chat"ID = 555, cooldown = %f"CheckCooldown(id10.0555__))



Arkshine 01-09-2011 08:12

Re: Invalid Trie Handle
 
Please provide a simple and ready plugin test where the bug occurs so I can test as it is. Because I see nothing wrong.

Elusive138 01-09-2011 23:28

Re: Invalid Trie Handle
 
Sorry, probably should have done this the first post..

EDIT: Never mind, now works correctly. I didn't even know there was a v1.8.2...
Quote:

joaquimandrade - Fix TrieSetArray reading the wrong parameter
Oh, and thanks fysiks.

If anyone could tell me what TrieMallocCount() and TrieFreeCount() does, exactly, I'd very much appreciate it.

PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "Elusive"


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /test2""Debug_Test2")
}

stock Float:CheckCooldown(index=0Float:cooldownTime=0.0id=0bool:readonly=falsebool:remove=false)
{
    static 
Trie:cooldownTrie
    
new key[16], Float:buffer[33
    
    if (!
cooldownTrie)
    {
        
cooldownTrie TrieCreate()
    }
    if (
cooldownTrie == Invalid_Trie)
    {
        
set_fail_state("Invalid Handle")
    }
    
formatex(keycharsmax(key), "ID%i"id)
    
    if (
remove)
    {
        if (
TrieKeyExists(cooldownTriekey))
        {
            
TrieDeleteKey(cooldownTriekey)
            return 
Float:1
        
}
        else
        {
            return 
Float:0
        
}
    }
    
    if (
TrieKeyExists(cooldownTriekey))
    {
        
TrieGetArray(cooldownTriekeybuffersizeof(buffer))
    }
    
    new 
Float:currentTime get_gametime()
    if (
buffer[index] > currentTime)
    {
        return (
buffer[index] - currentTime)
    }
    if (
readonly)
    {
        return 
Float:0
    
}
    
    
buffer[index] = currentTime cooldownTime
    
    TrieSetArray
(cooldownTriekeybuffersizeof(buffer))
    
    return 
Float:0
}

public 
Debug_Test2(id)
{
    
client_print(idprint_chat"ID = 222, cooldown = %f"CheckCooldown(id5.0222__))
    
client_print(idprint_chat"ID = 555, cooldown = %f"CheckCooldown(id10.0555__))
    
client_print(idprint_chat"ID = 222, cooldown = %f"CheckCooldown(id5.0222__))
    
client_print(idprint_chat"ID = 555, cooldown = %f"CheckCooldown(id10.0555__))
    
client_print(idprint_chat"ID = 222, cooldown = %f"CheckCooldown(id5.0222_true))
    
client_print(idprint_chat"ID = 555, cooldown = %f"CheckCooldown(id10.0555_true))
    
client_print(idprint_chat"ID = 222, cooldown = %f"CheckCooldown(id5.0222__))
    
client_print(idprint_chat"ID = 555, cooldown = %f"CheckCooldown(id10.0555__))


Code:

L 01/10/2011 - 15:25:44: Invalid trie handle provided (1)
L 01/10/2011 - 15:25:44: [AMXX] Displaying debug trace (plugin "Debug.amxx")
L 01/10/2011 - 15:25:44: [AMXX] Run time error 10: native error (native "TrieSetArray")
L 01/10/2011 - 15:25:44: [AMXX]    [0] Debug.sma::CheckCooldown (line 62)
L 01/10/2011 - 15:25:44: [AMXX]    [1] Debug.sma::Debug_Test2 (line 69)


fysiks 01-10-2011 00:11

Re: Invalid Trie Handle
 
Just curious, are you using AMX Mod X 1.8.2?

Elusive138 01-10-2011 00:31

Re: Invalid Trie Handle
 
Quote:

Originally Posted by fysiks (Post 1390309)
Just curious, are you using AMX Mod X 1.8.2?

I am now.. was previously using 1.8.1.

joaquimandrade 01-10-2011 00:59

Re: Invalid Trie Handle
 
Quote:

Originally Posted by Elusive138 (Post 1390301)
If anyone could tell me what TrieMallocCount() and TrieFreeCount()

Where you found those?

Elusive138 01-10-2011 01:04

Re: Invalid Trie Handle
 
Quote:

Originally Posted by joaquimandrade (Post 1390329)
Where you found those?

In trietest.sma, where I somehow missed the comment.. I'm stupid :P
Quote:

// These natives are only available in a debug build of amxmodx

Thanks.


All times are GMT -4. The time now is 02:12.

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