Raised This Month: $32 Target: $400
 8% 

Timer callback error


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 10-10-2016 , 17:26   Timer callback error
Reply With Quote #1

Here's the error I get:
Code:
L 10/10/2016 - 08:27:02: [SM] Plugin "javit.smx" encountered error 23: Native detected error
L 10/10/2016 - 08:27:02: [SM] Invalid timer handle 9c5863b4 (error 3) during timer end, displayed function is timer callback, not the stack trace
L 10/10/2016 - 08:27:02: [SM] Unable to call function "Timer_DeagleToss" due to above error(s).
And here's all the related code in my plugin to the Timer_DeagleToss callback:
Code:
// global
Handle gLR_DeagleTossTimer = null;

// somewhere in my code, can happen multiple times a round - but only if the handle is null
gLR_DeagleTossTimer = CreateTimer(0.5, Timer_DeagleToss, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);

// whenever the mini-game ends: when a player dies or round ends
void EndMinigame()
{
	if(gLR_DeagleTossTimer != null)
	{
		delete gLR_DeagleTossTimer;
		gLR_DeagleTossTimer = null;
	}
}

public Action Timer_DeagleToss(Handle Timer)
{
	if(some_condition)
	{
		/* code here is creating a timer (which is not bound to any variable) to kill the mini-game loser in 3.0 seconds, unrelated */

		gLR_DeagleTossTimer = null; // notice how i set this to null

		return Plugin_Stop; // and stop the timer, yet i still get errors - even though i safely kill it at round end/EndMinigame()..
	}

	return Plugin_Continue;
}
I'm honestly not sure what's wrong here.. does anyone have an idea?
__________________
retired

Last edited by shavit; 10-10-2016 at 17:26.
shavit is offline
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 10-10-2016 , 19:32   Re: Timer callback error
Reply With Quote #2

Tried switching from delete to killtimer?

PHP Code:
void EndMinigame()
{
    if (
gLR_DeagleTossTimer != null)
    {
        
KillTimer(gLR_DeagleTossTimer);
        
gLR_DeagleTossTimer null;
    }

Wild idea:

else try

PHP Code:
public Action Timer_DeagleToss(Handle Timer
to

PHP Code:
public Action Timer_DeagleToss(Handle timer
__________________
xines is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 10-10-2016 , 20:33   Re: Timer callback error
Reply With Quote #3

Quote:
Originally Posted by xines View Post
Tried switching from delete to killtimer?

PHP Code:
void EndMinigame()
{
    if (
gLR_DeagleTossTimer != null)
    {
        
KillTimer(gLR_DeagleTossTimer);
        
gLR_DeagleTossTimer null;
    }

Wild idea:

else try

PHP Code:
public Action Timer_DeagleToss(Handle Timer
to

PHP Code:
public Action Timer_DeagleToss(Handle timer
But KillTimer is the same as delete (which is a CloseHandle alias) basically for me, because I don't need the autoClose argument that KillTimer has.

I'm a bit confused about the second idea: I didn't try yet - because I can't figure out how to replicate the error myself, I just check my error logs daily and I find this one very often. What would it change? I don't use the timer handle anyways in the code block
__________________
retired
shavit is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 10-10-2016 , 21:00   Re: Timer callback error
Reply With Quote #4

Alternately, you can just have a global integer used for timer validation. Pass the integer as data, and compare it to the current global value in the top of the callback. If different, return Plugin_Stop. Increment the global variable when the timer is supposed to be killed, and it will be killed by your check on next callback. Any new timers would use the new (incremented) value in their validation. This prevents those errors, and you dont have to play with KillTimer, delete, or even handles at all.
__________________
ThatOneGuy is offline
Timocop
AlliedModders Donor
Join Date: Mar 2013
Location: Germany
Old 10-10-2016 , 21:22   Re: Timer callback error
Reply With Quote #5

Code:
CreateTimer(0.5, Timer_DeagleToss, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
Remove TIMER_FLAG_NO_MAPCHANGE and close the timer manualy on OnMapEnd.
When this flag is set, it kills the timer on map change, but doesnt set your gLR_DeagleTossTimer to null.
Never ever use TIMER_FLAG_NO_MAPCHANGE when saving the timer handle into variables for later use.
Timocop is offline
Dr!fter
The Salt Boss
Join Date: Mar 2007
Old 10-10-2016 , 22:13   Re: Timer callback error
Reply With Quote #6

Quote:
Originally Posted by Timocop View Post
Code:
CreateTimer(0.5, Timer_DeagleToss, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
Remove TIMER_FLAG_NO_MAPCHANGE and close the timer manualy on OnMapEnd.
When this flag is set, it kills the timer on map change, but doesnt set your gLR_DeagleTossTimer to null.
Never ever use TIMER_FLAG_NO_MAPCHANGE when saving the timer handle into variables for later use.
The better solution is to just set the variable to null in OnMapStart
Dr!fter is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 10-10-2016 , 23:28   Re: Timer callback error
Reply With Quote #7

This can happen when you do some action in your timer callback that triggers an event in the engine you hooked. Like slaying a player in the timer callback and having player_death hooked, in which you kill the timer. Your event hook would execute after the force suicide call and your timer callback would continue afterwards. When the timer callback exits then, the timer handle was closed in the event hook causing that error.
Same for slaying the last alive player or terminating the round or similar.
__________________
Peace-Maker is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 10-11-2016 , 07:00   Re: Timer callback error
Reply With Quote #8

Quote:
Originally Posted by ThatOneGuy View Post
Alternately, you can just have a global integer used for timer validation. Pass the integer as data, and compare it to the current global value in the top of the callback. If different, return Plugin_Stop. Increment the global variable when the timer is supposed to be killed, and it will be killed by your check on next callback. Any new timers would use the new (incremented) value in their validation. This prevents those errors, and you dont have to play with KillTimer, delete, or even handles at all.
Will try this solution, thanks!

Quote:
Originally Posted by Timocop View Post
Code:
CreateTimer(0.5, Timer_DeagleToss, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
Remove TIMER_FLAG_NO_MAPCHANGE and close the timer manualy on OnMapEnd.
When this flag is set, it kills the timer on map change, but doesnt set your gLR_DeagleTossTimer to null.
Never ever use TIMER_FLAG_NO_MAPCHANGE when saving the timer handle into variables for later use.
Will try to use OnMapStart instead as Dr!fter suggested, thanks!

Quote:
Originally Posted by Peace-Maker View Post
This can happen when you do some action in your timer callback that triggers an event in the engine you hooked. Like slaying a player in the timer callback and having player_death hooked, in which you kill the timer. Your event hook would execute after the force suicide call and your timer callback would continue afterwards. When the timer callback exits then, the timer handle was closed in the event hook causing that error.
Same for slaying the last alive player or terminating the round or similar.
But.. I'm not instantly slaying the player, I'm creating a timer that slays the player in 3 seconds.
__________________
retired

Last edited by shavit; 10-11-2016 at 07:02.
shavit is offline
Timocop
AlliedModders Donor
Join Date: Mar 2013
Location: Germany
Old 10-11-2016 , 15:13   Re: Timer callback error
Reply With Quote #9

You can try
PHP Code:
public Action Timer_DeagleToss(Handle Timer)
{
    if(
some_condition)
    {
        
gLR_DeagleTossTimer null// Set to null, so it wont kill the timer in the player_death event when its fired by your kill code below.
                
        /* Kill Code here e.g KillClient(client); // which fires player_death where your KillTimer code is located for example */

        
return Plugin_Stop;
    }

    return 
Plugin_Continue;


you can also do it like this i guess:
PHP Code:
public Action Timer_DeagleToss(Handle Timer)
{
    if(
some_condition)
    {
        
/* Code */

        
gLR_DeagleTossTimer null;
        
/* Kill Client Code. Fires player_death but ignores KillTimer because its null now */
        
gLR_DeagleTossTimer Timer//player_death already fired now, set the timer handle again

        /* Code */

        
gLR_DeagleTossTimer null;
        return 
Plugin_Stop;
    }

    return 
Plugin_Continue;

Timocop is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 10-12-2016 , 12:01   Re: Timer callback error
Reply With Quote #10

Quote:
Originally Posted by Timocop View Post
You can try
PHP Code:
public Action Timer_DeagleToss(Handle Timer)
{
    if(
some_condition)
    {
        
gLR_DeagleTossTimer null// Set to null, so it wont kill the timer in the player_death event when its fired by your kill code below.
                
        /* Kill Code here e.g KillClient(client); // which fires player_death where your KillTimer code is located for example */

        
return Plugin_Stop;
    }

    return 
Plugin_Continue;


you can also do it like this i guess:
PHP Code:
public Action Timer_DeagleToss(Handle Timer)
{
    if(
some_condition)
    {
        
/* Code */

        
gLR_DeagleTossTimer null;
        
/* Kill Client Code. Fires player_death but ignores KillTimer because its null now */
        
gLR_DeagleTossTimer Timer//player_death already fired now, set the timer handle again

        /* Code */

        
gLR_DeagleTossTimer null;
        return 
Plugin_Stop;
    }

    return 
Plugin_Continue;

The solution won't work simply because I kill the player within a 3.0 seconds timer, not during this timer callback
__________________
retired
shavit 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 00:28.


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