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

Solved Invalid Timer Handle


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 10-04-2017 , 16:17   Invalid Timer Handle
Reply With Quote #1

I get an "Invalid Timer Handle" error in server console when this stock gets executed:
PHP Code:
stock bool ClearTimer(Handle timer) {
    if(
timer != INVALID_HANDLE) {
        
CloseHandle(timer);
        
timer INVALID_HANDLE;
        
        return 
true;
    }
    
    return 
false;

I'm not sure why.
This is the code where it's executed:
PHP Code:
Handle myTimer INVALID_HANDLE;

public 
void _Smoke_OnRoundStart() {
    
ClearTimer(myTimer);
    
myTimer CreateTimer(1.0SmokeCheckTimer_TIMER_REPEAT);
}

public 
Action SmokeCheckTimer(Handle timer) {
    if(
GetTime() < g_iSmokeTime// Time is not up yet
        
return Plugin_Continue;
    
    
ExecSmoke();
    return 
Plugin_Stop;

Why does it fail? How can I solve this? I read somewhere that I need to initialize the handle with INVALID_HANDLE or else it still would throw errors.
__________________

Last edited by condolent; 10-06-2017 at 10:49.
condolent is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 10-04-2017 , 16:51   Re: Invalid Timer Handle
Reply With Quote #2

New syntax.

Code:
stock bool ClearTimer(Timer timer) {
    if(timer != null) {
        delete timer;
        timer = null;
        return true;
    }
    return false;
}
Your error message doesnt match your code. ClearTimer is just closing a handle. It doesnt care about what type of handle is parsed.

Provide the actual error and its stack trace.
__________________
Neuro Toxin is offline
Papero
Veteran Member
Join Date: Aug 2016
Location: Italy
Old 10-04-2017 , 16:54   Re: Invalid Timer Handle
Reply With Quote #3

Try to set the handle to null/INVALID_HANDLE before you return Plugin_Stop
__________________
My Plugins
SPCode


Steam: hexer504
Telegram: Hexah
Discord: Hexah#6903

If you like my work you can donate here!
Papero is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 10-04-2017 , 18:06   Re: Invalid Timer Handle
Reply With Quote #4

Post your full error and code, it'd help everyone.


Side note: Why are you using a repeating timer in the first place? Just set the time period equal to the g_iSmokeTime (assuming it's in seconds)

Last edited by headline; 10-04-2017 at 18:35.
headline is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-04-2017 , 20:16   Re: Invalid Timer Handle
Reply With Quote #5

Quote:
Originally Posted by Neuro Toxin View Post
New syntax.

Code:
stock bool ClearTimer(Timer timer) {
    if(timer != null) {
        delete timer;
        timer = null;
        return true;
    }
    return false;
}
Your error message doesnt match your code. ClearTimer is just closing a handle. It doesnt care about what type of handle is parsed.

Provide the actual error and its stack trace.
Code:
stock bool ClearTimer(Timer timer) {
You mean this, right?

Code:
stock bool ClearTimer(Timer &timer) {
Edit: For that matter, just scrap the whole stock and use delete instead.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 10-04-2017 at 20:17. Reason: Fixed comma location
Powerlord is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 10-04-2017 , 20:52   Re: Invalid Timer Handle
Reply With Quote #6

I though Handle parameters are byref?

Wait. Lmao. Yes you need to ref the param if setting it to null in the stock. Same goes to the stock in the OP
__________________

Last edited by Neuro Toxin; 10-04-2017 at 20:53.
Neuro Toxin is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 10-04-2017 , 21:05   Re: Invalid Timer Handle
Reply With Quote #7

Quote:
Originally Posted by Neuro Toxin View Post
I though Handle parameters are byref?
Internally in SourceMod, Handles (as seen by SM plugins) are nothing more then an array index to an object stored inside a global array of sourcemod.logic.<binary extension>, said object stores a pointer to the actual object represented by the initial index.
__________________
WildCard65 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-04-2017 , 21:25   Re: Invalid Timer Handle
Reply With Quote #8

Quote:
Originally Posted by WildCard65 View Post
Internally in SourceMod, Handles (as seen by SM plugins) are nothing more then an array index to an object stored inside a global array of sourcemod.logic.<binary extension>, said object stores a pointer to the actual object represented by the initial index.
My point was that if you pass a timer to that stock, it's useless to set it to null in the stock because the original variable will still be set to the now dead handle. Hence why you need the & to pass it as a reference instead.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 10-04-2017 , 21:29   Re: Invalid Timer Handle
Reply With Quote #9

Get rid of ClearTimer entirely, and just use the delete keyword. (EDIT: As Powerlord already suggested a few posts up lmao)

PHP Code:
public void _Smoke_OnRoundStart() {
    
delete myTimer;
    
myTimer CreateTimer(1.0SmokeCheckTimer_TIMER_REPEAT);

__________________

Last edited by ddhoward; 10-04-2017 at 21:30.
ddhoward is offline
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 10-05-2017 , 02:15   Re: Invalid Timer Handle
Reply With Quote #10

Quote:
Originally Posted by Headline View Post
Side note: Why are you using a repeating timer in the first place? Just set the time period equal to the g_iSmokeTime (assuming it's in seconds)
I honestly have no idea how I was thinking. I thought there should've been a timer for each 1 seconds checking if GetTime() == g_iSmokeTime. I just now, when you mention it, realize how stupid that is


As for the error, I will update this topic with the whole stacktrace when I can get home and start it again!
__________________

Last edited by condolent; 10-05-2017 at 03:08.
condolent is offline
Reply


Thread Tools
Display Modes

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 12:52.


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