|
Senior Member
|

01-09-2011
, 06:09
Invalid Trie Handle
|
#1
|
I'm experimenting with tries and ran across an invalid trie handle provided error when I tried TrieSetArray.
PHP Code:
TrieSetArray(cooldownTrie, key, buffer, sizeof(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(PLUGIN, VERSION, AUTHOR) register_clcmd("say /test2", "Debug_Test2") }
stock Float:CheckCooldown(index=0, Float:cooldownTime=0.0, id=0, bool:readonly=false, bool: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(key, charsmax(key), "ID%i", id) if (remove) { if (TrieKeyExists(cooldownTrie, key)) { TrieDeleteKey(cooldownTrie, key) return Float:1 } else { return Float:0 } } if (TrieKeyExists(cooldownTrie, key)) { TrieGetArray(cooldownTrie, key, buffer, sizeof(buffer)) } new Float:currentTime = get_gametime() if (buffer[index] > currentTime) { return (buffer[index] - currentTime) } if (readonly) { return Float:0 } buffer[index] = currentTime + cooldownTime TrieSetArray(cooldownTrie, key, buffer, sizeof(buffer)) return Float:0 }
public Debug_Test2(id) { client_print(id, print_chat, "ID = 222, cooldown = %f", CheckCooldown(id, 5.0, 222, _, _)) client_print(id, print_chat, "ID = 555, cooldown = %f", CheckCooldown(id, 10.0, 555, _, _)) client_print(id, print_chat, "ID = 222, cooldown = %f", CheckCooldown(id, 5.0, 222, _, _)) client_print(id, print_chat, "ID = 555, cooldown = %f", CheckCooldown(id, 10.0, 555, _, _)) client_print(id, print_chat, "ID = 222, cooldown = %f", CheckCooldown(id, 5.0, 222, _, true)) client_print(id, print_chat, "ID = 555, cooldown = %f", CheckCooldown(id, 10.0, 555, _, true)) client_print(id, print_chat, "ID = 222, cooldown = %f", CheckCooldown(id, 5.0, 222, _, _)) client_print(id, print_chat, "ID = 555, cooldown = %f", CheckCooldown(id, 10.0, 555, _, _)) }
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()); }
Last edited by Elusive138; 01-09-2011 at 23:29.
|
|