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

[css] Native "KillTimer" error


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
freanky
Member
Join Date: May 2010
Old 12-15-2013 , 20:07   [css] Native "KillTimer" error
Reply With Quote #1

i have this error in my sourcemod log:
Code:
L 12/15/2013 - 17:48:14: [SM] Displaying call stack trace for plugin "sm_infirmerie.smx":
L 12/15/2013 - 17:48:14: [SM]   [0]  Line 36, C:\Program Files (x86)\Steam\steamapps\marcamy\counter-strike source\cstrike\addons\sourcemod\scripting\sm_infirmerie.sp::Event_round_End()
L 12/15/2013 - 17:49:21: [SM] Native "KillTimer" reported: Invalid timer handle fdf30a08 (error 1)
Line 25 to 52 . ligne 36 is: KillTimer(g_Timer);
Code:
public OnPluginStart()
{
    RegConsoleCmd("sm_infirm", Command_Infirmerie);
	HookEvent("round_start", Event_round_Start);
	HookEvent("round_end", Event_round_End);
}

public Action:Event_round_End(Handle:event, const String:name[], bool:dontBroadcast)
{
	if(g_Timer != INVALID_HANDLE)
	{
		KillTimer(g_Timer);
	}
}

public Action:Event_round_Start(Handle:event, const String:name[], bool:dontBroadcast)
{
	for (new i = 0; i < 26; i++)
	{
		userids[i] = 0;
	}
	position = 1;
	compteur = 30;
	nombreVotes = 0;
	possible = 1;
	infirmeriePermise = 1;
	return Plugin_Continue;
}
freanky is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 12-15-2013 , 20:56   Re: [css] Native "KillTimer" error
Reply With Quote #2

Make sure you set g_Timer to INVALID_HANDLE after you kill him.
A little bird (alongub) told me in the past that you should use CloseHandle for killing timers, try that.
__________________
retired
shavit is offline
freanky
Member
Join Date: May 2010
Old 12-16-2013 , 02:26   Re: [css] Native "KillTimer" error
Reply With Quote #3

not work, or i do not correctly?
freanky is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 12-16-2013 , 02:49   Re: [css] Native "KillTimer" error
Reply With Quote #4

If you create and store timer with timer flag TIMER_FLAG_NO_MAPCHANGE in handle
-Clear that handle OnMapEnd()
-Because this timer flag stop timer without "clearing" that handle to INVALID
-Or don't use this timer flag help's alot.
PHP Code:
public OnMapEnd()
{
    
g_Timer INVALID_HANDLE;

And remember clear handle when timer make action
PHP Code:
public Action:mytimer(Handle:timerany:data)
{
    
// Important! Very first to do this!
    
g_Timer INVALID_HANDLE;

    
// Do your code

And it's good idea clear handle after killing it.
PHP Code:
    if(g_Timer != INVALID_HANDLE)
    {
        
KillTimer(g_Timer);
        
g_Timer INVALID_HANDLE;
        
    } 
TIMER_FLAG_NO_MAPCHANGE or Clearing Handle?
Bacardi is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 12-16-2013 , 04:29   Re: [css] Native "KillTimer" error
Reply With Quote #5

I m not aware of the clearing handle OnMapEnd ().
Thanks for the info.
__________________
If i happen to insulted you unintentionally,
it was me and Google Translate who did it.
GsiX is offline
freanky
Member
Join Date: May 2010
Old 12-16-2013 , 13:15   Re: [css] Native "KillTimer" error
Reply With Quote #6

this line is ok thank you
now:
/home/groups/sourcemod/upload_tmp/phpV2vhC8.sp(169) : warning 219: local variable "g_Timer" shadows a variable at a preceding level

Line 169 to 210
Code:
public Action:CompteurInfirmerie(Handle:g_Timer)
{
	if (compteur == 30)
	{
		PrintCenterTextAll("La sortie vers l'infirmerie commence!");
	}
	else if (compteur == 20)
	{
		for (new i = 1; i <= MaxClients; i++)
		{
			if (IsClientInGame(i) && !IsClientObserver(i))
			{
				if(GetClientTeam(i) == CS_TEAM_T && IsPlayerAlive(i))
				{
					new HPJOUEUR = GetClientHealth(i);
					if (HPJOUEUR != 100)
						{
							SetEntityRenderColor(i, 150, 0, 0);
						}
				}
			}
		}
	}
	else if (compteur > 0 && compteur < 30)
	{
		PrintCenterTextAll("Il reste %d secondes a la sortie vers l'infirmerie", compteur);
	}
	else
	{
		PrintCenterTextAll("La sortie est finie");
		for (new i = 1; i <= MaxClients; i++)
		{
			if (IsClientInGame(i) && !IsClientObserver(i) && IsPlayerAlive(i))
			{
				SetEntityRenderColor(i, 255, 255, 255);
			}
		}
		return Plugin_Stop;
	}
	compteur--;
	return Plugin_Continue;
}
Line 32 to 40
Code:
public Action:Event_round_End(Handle:event, const String:name[], bool:dontBroadcast)
{
    if(g_Timer != INVALID_HANDLE)
    {
        KillTimer(g_Timer);
        g_Timer = INVALID_HANDLE;
        
    }
}

Last edited by freanky; 12-16-2013 at 13:16.
freanky is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 12-16-2013 , 13:32   Re: [css] Native "KillTimer" error
Reply With Quote #7

public Action:CompteurInfirmerie(Handle:g_Timer)

to

public Action:CompteurInfirmerie(Handle:timer)

Also, don't forget to set g_Timer to INVALID_HANDLE when you're done with it, otherwise, KillTimer will throw an error trying to kill a timer that isn't valid.
__________________
View my Plugins | Donate
TnTSCS 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 14:55.


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