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

Timer handles are the craziest things in sp tbh


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
supertimor
AlliedModders Donor
Join Date: Sep 2017
Old 04-16-2020 , 10:15   Timer handles are the craziest things in sp tbh
Reply With Quote #1

Hi!
I am just curious.. why if I am checking, if THIS HANDLE IS INVALID, there's an error with invalid handle?

Code:

if(g_timerHealing[client] != INVALID_HANDLE && g_timerHealing[client] != null) {
KillTimer(g_timerHealing[client]);
}


L 04/16/2020 - 15:40:04: [SM] Exception reported: Invalid timer handle d33f570b (error 3)
L 04/16/2020 - 15:40:04: [SM] Call stack trace:
L 04/16/2020 - 15:40:04: [SM] [0] KillTimer
L 04/16/2020 - 15:40:04: [SM] [1] Line 42, plugin.sp:layerSpawn


So according to code, this handle ISN'T invalid, and ISN't nulled, so passed... anyway, just shoot with invalid timer handle error lmao

supertimor is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 04-16-2020 , 11:04   Re: Timer handles are the craziest things in sp tbh
Reply With Quote #2

https://wiki.alliedmods.net/Timers_(...Mod_Scripting)

Happens when you not clear array handle when timer works last time. Stop.

Another is Timer flag TIMER_FLAG_NO_MAPCHANGE. If you use it, you need clear Handle OnMapStart.

PHP Code:

Handle PlayerTimers
[MAXPLAYERS+1];

// You need clear handles when you create Timer with TIMER_FLAG_NO_MAPCHANGE
public void OnMapStart()
{
    for(
int x 0sizeof(PlayerTimers); x++) PlayerTimers[x] = null;
}



//    player appear on server
public void OnClientPutInServer(int client)
{

    
// There is already timer ? Delete old, make new one.
    
if(PlayerTimers[client] != null)
    {
        
delete PlayerTimers[client];
    }


    
// create timer.
    
DataPack pack;
    
PlayerTimers[client] = CreateDataTimer(5.0delaypackTIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
    
pack.WriteCell(client);    // This is slot index, for find our timer from array PlayerTimers[]
    
pack.WriteCell(GetClientUserId(client)); // UserId is player unique number for later use. We can check is player same person.
    
pack.Reset(); // Go back to top of pack.
}


// When timer callback is working
public Action delay(Handle timerDataPack pack)
{
    
int index pack.ReadCell(); // This is array PlayerTimers[] index. "client"
    
int userid pack.ReadCell();
    
int client GetClientOfUserId(userid); // Using UserId to get client index.
    
pack.Reset(); // Reset pack for later use.

    // Can't find player with that UserId
    
if(client == 0)
    {
        
// Remember clear array handle when timer need stop.
        
PlayerTimers[index] = null;
        return 
Plugin_Stop;
    }


    
// Player not fully in game, not in team 2 or 3, is dead
    
if(!IsClientInGame(client) || GetClientTeam(client) <= || !IsPlayerAlive(client))
    {
        
// Let timer repeat but skip rest of code.
        
return Plugin_Continue;
    }
    
    
    
PrintToChat(client"My timer is working, client %i, PlayerTimers[index %i], userid %i"clientindexuserid);

    
// Timer continue repeat
    
return Plugin_Continue;

__________________
Do not Private Message @me

Last edited by Bacardi; 04-16-2020 at 11:09.
Bacardi is offline
dangerlord63
Senior Member
Join Date: Aug 2011
Old 04-16-2020 , 11:04   Re: Timer handles are the craziest things in sp tbh
Reply With Quote #3

after killing the timer you need to set variable to INVALID_HANDLE so it doesn't cause any error.
take a look : https://wiki.alliedmods.net/Timers_(SourceMod_Scripting)
dangerlord63 is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 04-16-2020 , 11:31   Re: Timer handles are the craziest things in sp tbh
Reply With Quote #4

https://forums.alliedmods.net/showpo...3&postcount=33
__________________
Silvers is offline
supertimor
AlliedModders Donor
Join Date: Sep 2017
Old 04-16-2020 , 12:31   Re: Timer handles are the craziest things in sp tbh
Reply With Quote #5

Problem is different. Function player_spawn was triggered for bots also, so check passed (i still don't know why?), and handle was just invalid, so its reported. Bug fixed, but don't you guys think, that this is just bugged by sourcepawn side? OK, we have handle, we're checking if this is just invalid, then if it isn't let it go, and then report because of invalid handle.. (? )


Variables are nulled onmapstart also.

Last edited by supertimor; 04-16-2020 at 12:32.
supertimor is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 04-16-2020 , 14:15   Re: Timer handles are the craziest things in sp tbh
Reply With Quote #6

INVALID_HANDLE is just an old name for null, your handle value was not null / 0 (it was "valid"), but what it was a handle to was invalid - because you had a dangling reference.

It is logically a lot clearer if you stop using old, outdated things like INVALID_HANDLE (and KillTimer.)
__________________

Last edited by asherkin; 04-16-2020 at 14:16.
asherkin is offline
supertimor
AlliedModders Donor
Join Date: Sep 2017
Old 04-18-2020 , 06:08   Re: Timer handles are the craziest things in sp tbh
Reply With Quote #7

Thanks for it asherkin.
Basically, there's another thing, i think its similiar :

1 plugin_forward = GetFunctionByName(plugins[plugin], "forward_name");
2 if(plugin_forward != INVALID_FUNCTION) {
3 <some code>
4 }

Throws invalid plugin handle exception at line 1. How to check it safely?

oh yeah, maybe.. if(plugins[plugin] != null) ? lmao, got it probably thanks

Last edited by supertimor; 04-18-2020 at 06:28.
supertimor 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 13:04.


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