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

Invalid Handle Error (With Timers)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Papero
Veteran Member
Join Date: Aug 2016
Location: Italy
Old 09-09-2017 , 06:34   Invalid Handle Error (With Timers)
Reply With Quote #1

I cannot understand why I'm getting this error
PHP Code:
L 09/09/2017 12:17:50: [SMException reportedHandle 3df4107c is invalid (error 1)
L 09/09/2017 12:17:50: [SMBlamingzMisc/VipBonus.smx
L 09
/09/2017 12:17:50: [SMCall stack trace:
L 09/09/2017 12:17:50: [SM]   [0CloseHandle
L 09
/09/2017 12:17:50: [SM]   [1Line 578VipMenu.sp::Menu_PlayerSpawn 
The block:
PHP Code:
    if (hRegenTimer[client] != INVALID_HANDLE)
    {
        
hRegenTimer[client].Close();
        
hRegenTimer[client] = INVALID_HANDLE;
    } 
FullCode: https://github.com/Hexer10/VipMenu-B...emod/scripting
__________________
My Plugins
SPCode


Steam: hexer504
Telegram: Hexah
Discord: Hexah#6903

If you like my work you can donate here!
Papero is offline
AI_
Member
Join Date: Oct 2014
Location: Canada
Old 09-09-2017 , 06:57   Re: Invalid Handle Error (With Timers)
Reply With Quote #2

Have you tried replacing that block with delete?:

Code:
delete hRegenTimer[client];
__________________
AI_ is offline
Papero
Veteran Member
Join Date: Aug 2016
Location: Italy
Old 09-09-2017 , 06:59   Re: Invalid Handle Error (With Timers)
Reply With Quote #3

Quote:
Originally Posted by AI_ View Post
Have you tried replacing that block with delete?:

Code:
delete hRegenTimer[client];
Yes...
__________________
My Plugins
SPCode


Steam: hexer504
Telegram: Hexah
Discord: Hexah#6903

If you like my work you can donate here!
Papero is offline
AI_
Member
Join Date: Oct 2014
Location: Canada
Old 09-09-2017 , 07:12   Re: Invalid Handle Error (With Timers)
Reply With Quote #4

A slight nitpick, but your array initializations only set the first element.

Code:
int iArr[4] = 1; // iArr is now {1, 0, 0, 0}
To set them all, use this syntax:

Code:
int iArr[4] = {1, ...}; // iArr is now {1, 1, 1, 1}
__________________

Last edited by AI_; 09-09-2017 at 07:17.
AI_ is offline
Papero
Veteran Member
Join Date: Aug 2016
Location: Italy
Old 09-09-2017 , 07:16   Re: Invalid Handle Error (With Timers)
Reply With Quote #5

Quote:
Originally Posted by AI_ View Post
A slight nitpick, but your array initializations only set the first element. To set them all, use this syntax:

Code:
int iArr[4] = {1, ...};
You are right, but I dont think that is causing the problem.
__________________
My Plugins
SPCode


Steam: hexer504
Telegram: Hexah
Discord: Hexah#6903

If you like my work you can donate here!
Papero is offline
AI_
Member
Join Date: Oct 2014
Location: Canada
Old 09-09-2017 , 07:21   Re: Invalid Handle Error (With Timers)
Reply With Quote #6

Looks like there's a chance your timer may be terminated here due to Plugin_Stop:

Code:
public Action Timer_Regen(Handle timer, any userid)
{
	int client = GetClientOfUserId(userid);
	if (!IsValidClient(client, false, false))
		return Plugin_Continue;
	int iHealth = GetClientHealth(client);
	if (IsValidClient(client))
	{
		if (!bRegen[client])
			return Plugin_Stop;
		
		if (cv_iRegenMaxHP.IntValue > iHealth)
		{
			if (bRegen[client])
			{
				SetEntityHealth(client, iHealth + cv_iRegenHP.IntValue);
				return Plugin_Continue;
			}
		}
		
		if (!cv_bStopTimer.BoolValue)
			return Plugin_Stop;
		else
			return Plugin_Continue;
	}
	else
	{
		return Plugin_Stop;
	}
}
This will not automatically set hRegenTimer[client] to null but the handle it refers to is no longer valid.
__________________

Last edited by AI_; 09-09-2017 at 07:23.
AI_ is offline
Zeisen
Member
Join Date: Nov 2016
Location: Republic of Korea
Old 09-09-2017 , 07:31   Re: Invalid Handle Error (With Timers)
Reply With Quote #7

Try This: might be solve.

Code:
public Action Timer_Regen(Handle timer, any userid)
{
	int client = GetClientOfUserId(userid);
	if (!IsValidClient(client, false, false))
		return Plugin_Continue;
        hRegenTimer[client] = INVALID_HANDLE;
	int iHealth = GetClientHealth(client);
	if (IsValidClient(client))
	{
		if (!bRegen[client])
			return Plugin_Stop;
		
		if (cv_iRegenMaxHP.IntValue > iHealth)
		{
			if (bRegen[client])
			{
				SetEntityHealth(client, iHealth + cv_iRegenHP.IntValue);
				return Plugin_Continue;
			}
		}
		
		if (!cv_bStopTimer.BoolValue)
			return Plugin_Stop;
		else
			return Plugin_Continue;
	}
	else
	{
		return Plugin_Stop;
	}
}
but actually your code has problem..
Zeisen is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-09-2017 , 07:51   Re: Invalid Handle Error (With Timers)
Reply With Quote #8

Repeated timer?

...your timers are passing player userid.
But if player disconnect, you not get client index anymore with given userid.
That is one problem.

You could try datatimer to store both clientindex and userid in timer dstapack

Secondly, you need set global Handle to null everytime when timer Plugin_Stop.
__________________
Do not Private Message @me

Last edited by Bacardi; 09-09-2017 at 07:53.
Bacardi is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 09-09-2017 , 08:58   Re: Invalid Handle Error (With Timers)
Reply With Quote #9

Timers automatically destroy themselves upon completion (as in no longer going to be calling your plugin's callback function).
__________________
WildCard65 is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 09-09-2017 , 11:43   Re: Invalid Handle Error (With Timers)
Reply With Quote #10

The problem is what AI_ and Bacardi said, when the code takes a path that returns Plugin_Stop in the callback, then your variable will not be set to null/INVALID_HANDLE yet the timer will be invalid. Zeisen's suggested code isn't right because it sets the timer to INVALID_HANDLE even in the path where Plugin_Continue is returned.

Also:

Quote:
Originally Posted by Bacardi View Post
...your timers are passing player userid.
But if player disconnect, you not get client index anymore with given userid.
That is one problem.
This is not a problem if you check that the return value of GetClientOfUserId is not zero.
Fyren 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:04.


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