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

Native "GetEntDataEnt2" reported


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
headline
SourceMod Moderator
Join Date: Mar 2015
Old 08-05-2015 , 01:00   Native "GetEntDataEnt2" reported
Reply With Quote #1

Cant figure this one out...

Code:
L 08/04/2015 - 23:38:28: [SM] Native "GetEntDataEnt2" reported: Entity 32 (32) is invalid
L 08/04/2015 - 23:38:28: [SM] Displaying call stack trace for plugin "hg.smx":
L 08/04/2015 - 23:38:28: [SM]   [0]  Line 1375, C:\Users\Studio\Desktop\Scripting\include\smlib/clients.inc::Client_GetWeapon()
L 08/04/2015 - 23:38:28: [SM]   [1]  Line 1356, C:\Users\Studio\Desktop\Scripting\include\smlib/clients.inc::Client_HasWeapon()
L 08/04/2015 - 23:38:28: [SM]   [2]  Line 422, C:\Users\Studio\Desktop\Scripting\Hunger Games Scripting\ZIPCORE\hg.sp::Timer_Remove_Weapons()
PHP Code:
public Action:Event_Spawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    
CreateTimer(0.2Timer_Remove_Weaponsclient);
    
// Other stuff below here that doesn't matter

Some time later...
PHP Code:
public Action:Timer_Remove_Weapons(Handle:timerany:client)
{
    if (
Client_HasWeapon(client"weapon_knife") && IsValidClient(client))
    {
        
Client_RemoveAllWeapons(client);
    }

headline is offline
shortguy
Member
Join Date: Jul 2009
Old 08-05-2015 , 01:20   Re: Native "GetEntDataEnt2" reported
Reply With Quote #2

Is it possible that the client becomes invalid in those 0.2 seconds?

Maybe change:
Code:
if (Client_HasWeapon(client, "weapon_knife") && IsValidClient(client))


To
Code:
if (IsValidClient(client) && Client_HasWeapon(client, "weapon_knife"))


Last edited by shortguy; 08-05-2015 at 01:20.
shortguy is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 08-05-2015 , 01:41   Re: Native "GetEntDataEnt2" reported
Reply With Quote #3

If the client disconnects between spawn and the timer callback the client index will be invalid.

Check validity of the client first above all else. Furthermore, in the worse case where someone leaves and another guy joins before the first timer gets called you might target the wrong player. A userid check might also be needed (you decide on that).
Potato Uno is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 08-05-2015 , 01:47   Re: Native "GetEntDataEnt2" reported
Reply With Quote #4

Quote:
Originally Posted by Potato Uno View Post
A userid check might also be needed (you decide on that).
like if (client == 0) ???

now I have

PHP Code:
public Action:Event_Spawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    if (
IsValidClient(client) && client != 0)
    {
        
CreateTimer(0.2Timer_Remove_Weaponsclient);
    }

&

PHP Code:
public Action:Timer_Remove_Weapons(Handle:timerany:client)
{
    if (
IsValidClient(client) && Client_HasWeapon(client"weapon_knife") && client != 0)
    {
        
Client_RemoveAllWeapons(client);
    }


Last edited by headline; 08-05-2015 at 01:50.
headline is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 08-05-2015 , 02:05   Re: Native "GetEntDataEnt2" reported
Reply With Quote #5

you just need to swap the order of if (Client_HasWeapon(client, "weapon_knife") && IsValidClient(client)) since client_hasweapon which uses getentdataent2 can happen before isvalidclient

or use userids

edit: if it's not clear, userids are distinct from client indices

Last edited by Miu; 08-05-2015 at 02:21.
Miu is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 08-05-2015 , 02:29   Re: Native "GetEntDataEnt2" reported
Reply With Quote #6

Arent I using user ids???
headline is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 08-05-2015 , 02:50   Re: Native "GetEntDataEnt2" reported
Reply With Quote #7

youre sending the timer a client index after converting the userid in the event to one

Last edited by Miu; 08-05-2015 at 02:54.
Miu is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 08-05-2015 , 03:41   Re: Native "GetEntDataEnt2" reported
Reply With Quote #8

Quote:
Originally Posted by Miu View Post
youre sending the timer a client index after converting the userid in the event to one
Hmmm okay. Thanks to you I now have a better understanding of what I was doing! haha

EDIT: Here is what I am doing now!

PHP Code:
public Action:Event_Spawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    if (
IsValidClient(client))
    {
        new 
UserId GetClientUserId(client)
        
CreateTimer(0.2Timer_Remove_WeaponsUserId);
    }

PHP Code:
public Action:Timer_Remove_Weapons(Handle:timerany:UserId)
{
    new 
client GetClientOfUserId(UserId)
    if (
IsValidClient(client) && Client_HasWeapon(client"weapon_knife"))
    {
        
Client_RemoveAllWeapons(client);
    }


Last edited by headline; 08-05-2015 at 04:12.
headline is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 08-05-2015 , 04:39   Re: Native "GetEntDataEnt2" reported
Reply With Quote #9

That's sort of roundabout since you can just do this directly (the player should be valid in the tick the event fires so there's no need to check)

PHP Code:
public Action:Event_Spawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
UserId GetEventInt(event"userid");
    
CreateTimer(0.2Timer_Remove_WeaponsUserId);

but yeah, that's the general idea.

You don't really need to use userids in your case since the worst case scenario is that another client who just joined gets their weapons removed which would've happened anyway when they spawned, but in other cases it can potentially lead to very weird bugs, so it's good general practice.

Also, while logical AND intuitively seems like a symmetric relation (A && B is the same as B && A), lazy evaluation means that it's not, at least in terms of side effects: If you have A && B and A is false, there's no need to evaluate B, so it doesn't. This is important when A checks the validity of something B relies on, e.g. in the case of IsValidClient(client) && Client_HasWeapon(client, "weapon_knife"). If you swap the order, it no longer works.

In a language with eager evaluation, like PHP, you'd have to do

PHP Code:
if (IsValidClient(client))
{
    if (
Client_HasWeapon(client"weapon_knife"))
    {
        ...
    }

Miu is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 08-05-2015 , 04:57   Re: Native "GetEntDataEnt2" reported
Reply With Quote #10

Quote:
Originally Posted by Miu View Post
That's sort of roundabout since you can just do this directly (the player should be valid in the tick the event fires so there's no need to check)

PHP Code:
public Action:Event_Spawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
UserId GetEventInt(event"userid");
    
CreateTimer(0.2Timer_Remove_WeaponsUserId);

but yeah, that's the general idea.

You don't really need to use userids in your case since the worst case scenario is that another client who just joined gets their weapons removed which would've happened anyway when they spawned, but in other cases it can potentially lead to very weird bugs, so it's good general practice.

Also, while logical AND intuitively seems like a symmetric relation (A && B is the same as B && A), lazy evaluation means that it's not, at least in terms of side effects: If you have A && B and A is false, there's no need to evaluate B, so it doesn't. This is important when A checks the validity of something B relies on, e.g. in the case of IsValidClient(client) && Client_HasWeapon(client, "weapon_knife"). If you swap the order, it no longer works.

In a language with eager evaluation, like PHP, you'd have to do

PHP Code:
if (IsValidClient(client))
{
    if (
Client_HasWeapon(client"weapon_knife"))
    {
        ...
    }

Ah okay okay. So it what was happening was between that 0.2 second gap, people were leaving. And when trying to check if they have a knife, they are already gone so it spits out the error and THEN checks if the client is valid. I figured when I wrote it since the commands fire so quickly it wouldn't matter, but I guess I now know.

No more error logs for me ;) Such a great feeling. I get to the point where error logs pile up and when I get annoyed I clean through them. They are all not very serious errors. Just little ones that I dont fix because I am lazy.

Last edited by headline; 08-05-2015 at 05:00.
headline 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 13:06.


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