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

Occasional crash with this code..


Post New Thread Reply   
 
Thread Tools Display Modes
XARIUS
SourceMod Donor
Join Date: May 2008
Location: Atlanta, GA
Old 10-05-2008 , 20:09   Re: Occasional crash with this code..
Reply With Quote #11

Quote:
Originally Posted by BAILOPAN View Post
XARIUS: it's hard to tell because your crash is on Windows where reverse engineering is harder. The server assumes that its data won't be touched by anyone else. For example, it might cache an entity somewhere and use it again later without error checking -- because it assumes no one has touched it.

When plugins start poking around internals such assumptions can fall apart. It's often not the fault of the game, plugins just need to work around these problems unfortunately. Your crash could be diagnosed further with a breakpoint in the DLL, and trying to analyze the datastructure that's invalid (looks like a bad virtual call).

Getting a crash on Linux in GDB is a lot easier to diagnose.
Gotchya. Getting a custom DLL with breakpoints for this is just silly. The weapon handler code I wrote was my first attempt, and does indeed deal with entity's. It's never *not* worked to strip all weapons etc, so I always assumed it was something with the teleport. Now that I've learned a bit more, I think I'll go back and re-write it based on checking each weapon slot versus incrementing my way up thru the entities.

Thanks again.

X
XARIUS is offline
XARIUS
SourceMod Donor
Join Date: May 2008
Location: Atlanta, GA
Old 10-06-2008 , 08:52   Re: Occasional crash with this code..
Reply With Quote #12

Okay. Well here's the re-write. It's working well so far (no crashes), short of an occasional invalid edict error with GetEdictClassName. Could someone familiar with walking m_hMyWeapons take a look at this and make sure I'm doing it correctly? I wouldn't think I'd get edict errors if I were.

Code:
g_iMyWeapons = FindSendPropOffs("CBaseCombatCharacter", "m_hMyWeapons");

WeaponHandler(client, teamid)
{
  if (isFighting)
  {
    static count = 0;
    for (new i = 0; i <= 128; i += 4)
    {
      new weaponentity = -1;
      new String:weaponname[32];
      weaponentity = GetEntDataEnt(client, (g_iMyWeapons + i));
      if (!IsValidEdict(weaponentity))
      {
        return;
      }
      GetEdictClassname(weaponentity, weaponname, sizeof(weaponname));
      if (weaponentity != -1 && !StrEqual(weaponname, "worldspawn", false))
      {
    // if teamid = 0, we've picked up a weapon during a fight, strip and leave with knife.
        if (teamid == 0 && !StrEqual(weaponname, "weapon_knife", false))
        {
          RemovePlayerItem(client, weaponentity);
          RemoveEdict(weaponentity);
          if (!countdown)
          {
            EquipKnife(client);
          }
        }
    // Starting a knife fight, remove all weapons and store them for later incase we give them back.
        else if (teamid == 3 || teamid == 2)
        {
          RemovePlayerItem(client, weaponentity);
          RemoveEdict(weaponentity);
          if (teamid == 3)
          {
            ctitems[count] = weaponname;
            count++;
          }

          if (teamid == 2)
          {
            titems[count] = weaponname;
            count++;
          }
        }
      }
    }
    count = 0;
  }
}
Thanks!

Last edited by XARIUS; 10-06-2008 at 08:56.
XARIUS is offline
BAILOPAN
Join Date: Jan 2004
Old 10-06-2008 , 22:52   Re: Occasional crash with this code..
Reply With Quote #13

You shouldn't use GetEntDataEnt. I'm making a mental note to mark this as deprecated for 1.1.

Use GetEntDataEnt2 or GetEntPropEnt (preferred).

Source stores entity references as an 11-bit index and a 20-bit serial number. If the entity gets destroyed and recreated, the serial number changes, invalidating old references.

GetEntDataEnt does not validate the serial number, meaning you could be peeking at an old reference. By using the Ent2 or Prop version, you are guaranteed the entity index is completely valid. This also saves you another check.
__________________
egg
BAILOPAN is offline
XARIUS
SourceMod Donor
Join Date: May 2008
Location: Atlanta, GA
Old 10-07-2008 , 08:20   Re: Occasional crash with this code..
Reply With Quote #14

Ah Ha! Thank you thank you. Thats exactly why I was getting invalid edict errors after validating it once, twice, three times a lady.

Will update that code today. =)
__________________
XARIUS 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 15:23.


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