AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Invalid Timer Handle crash (https://forums.alliedmods.net/showthread.php?t=328491)

Halt 11-12-2020 13:48

Invalid Timer Handle crash
 
This crash's 100% of the time, and I'm not entirely sure why. I believe I've included all the related code below. All I'm attempting to do is kill the timer which would call the Humans win callback, but if all humans die prior to the time expiring then the timer needs to be killed.

PHP Code:

//Global Array
Handle g_hTimer;

//RoundStart callback
float delay 1.0 GetConVarInt(g_cvRoundTime) * 60 2;
g_hTimer CreateTimer(delayTimer_HumansWinEvent_TIMER_FLAG_NO_MAPCHANGE);

//RoundEnd callback (KillTimer is the error line)
if(g_hTimer != INVALID_HANDLE)
{
    
KillTimer(g_hTimer);
    
g_hTimer INVALID_HANDLE;
}

//Error
L 11/11/2020 15:22:01: [SMException reportedInvalid timer handle 686100fc (error 1)
L 11/11/2020 15:22:01: [SMBlamingcZomRevamp3.smx
L 11
/11/2020 15:22:01: [SMCall stack trace:
L 11/11/2020 15:22:01: [SM]   [0KillTimer 


Edit - Shouldn't need to add this here, but the game only crash's on RoundEnd when KillTimer is called. Otherwise no issues (that I've noticed).

Bacardi 11-12-2020 15:55

Re: Invalid Timer Handle crash
 
Quote:

Originally Posted by Halt (Post 2724677)
This crash's 100% of the time, and I'm not entirely sure why. I believe I've included all the related code below. All I'm attempting to do is kill the timer which would call the Humans win callback, but if all humans die prior to the time expiring then the timer needs to be killed.

Code:

//Global Array
Handle g_hTimer;

//RoundStart callback
float delay = 1.0 * GetConVarInt(g_cvRoundTime) * 60 - 2;
g_hTimer = CreateTimer(delay, Timer_HumansWinEvent, _, TIMER_FLAG_NO_MAPCHANGE);

//RoundEnd callback (KillTimer is the error line)
if(g_hTimer != INVALID_HANDLE)
{
        KillTimer(g_hTimer);
        g_hTimer = INVALID_HANDLE;
}

//Error
L 11/11/2020 - 15:22:01: [SM] Exception reported: Invalid timer handle 686100fc (error 1)
L 11/11/2020 - 15:22:01: [SM] Blaming: cZomRevamp3.smx
L 11/11/2020 - 15:22:01: [SM] Call stack trace:
L 11/11/2020 - 15:22:01: [SM]  [0] KillTimer


Edit - Shouldn't need to add this here, but the game only crash's on RoundEnd when KillTimer is called. Otherwise no issues (that I've noticed).

Common mistake, using timer flag TIMER_FLAG_NO_MAPCHANGE
- This stop timer when map change.
- This not clear Handle were you created timer.
- Remove flag or clear Handle at OnMapStart()

GsiX 11-13-2020 02:58

Re: Invalid Timer Handle crash
 
@Bacardi is OnMapEnd() guaranteed to fire every time and safe to CloseHandle() there or should i just do it on OnMapStart()?

MAGNAT2645 11-13-2020 06:40

Re: Invalid Timer Handle crash
 
Quote:

Originally Posted by GsiX (Post 2724732)
@Bacardi is OnMapEnd() guaranteed to fire every time and safe to CloseHandle() there or should i just do it on OnMapStart()?

If your timer is stored into global variable you should use this example
Code:

public void OnMapEnd() {
        KillTimer( g_hTimer );
        g_hTimer = null;
}

or just
Code:

public void OnMapEnd() {
        delete g_hTimer;
}


Bacardi 11-13-2020 17:10

Re: Invalid Timer Handle crash
 
Quote:

Originally Posted by GsiX (Post 2724732)
@Bacardi is OnMapEnd() guaranteed to fire every time and safe to CloseHandle() there or should i just do it on OnMapStart()?

you can test it by yourself

PHP Code:


public void OnMapStart()
{
    
PrintToServer("-- OnMapStart");
}

public 
void OnMapEnd()
{
    
PrintToServer("-- OnMapEnd");



Halt 11-15-2020 14:53

Re: Invalid Timer Handle crash
 
Thanks Bacardi, and Mag. No more crash's :)

Dragokas 11-21-2020 18:18

Re: Invalid Timer Handle crash
 
Here are most cases about the freeing timer's handle covered with explanations.


All times are GMT -4. The time now is 10:18.

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