Raised This Month: $32 Target: $400
 8% 

Linux server crashes when I kill entity by knife and remove it after


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Hedgehog Fog
Senior Member
Join Date: Jun 2010
Location: Ukraine
Old 10-29-2016 , 23:18   Linux server crashes when I kill entity by knife and remove it after
Reply With Quote #1

Hello,
I need help with fix some bug on linux.
I create entity with pev_takedamage DMG_AIM, and I hook Ham_Killed event for this entity. When I try to remove this entity on Kill:
PHP Code:
engfunc(EngFunc_RemoveEntityent
Linux server just crash, no errors in amx log.

This bug appears only if I kill this entity by knife.

No problem if I do something like that:
PHP Code:
set_pev(entpev_flagspev(entpev_flags) | FL_KILLME); 
Anyway I would like to know the reason of crashes.
__________________

❄️ CS Snow Wars - Mod based on snowballs fights
🧟 CS Zombie Panic - A port of HL Zombie Panic!
🎃 CS Halloween Mod - Completely new gamemode for Halloween Holidays
📦 AMXXPack - CLI and build system for amxx projects
🔧 Custom Entities API - API to register custom entities

Last edited by Hedgehog Fog; 10-30-2016 at 00:16.
Hedgehog Fog is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 10-30-2016 , 00:22   Re: Linux server crashes when I kill entity by knife and remove it after
Reply With Quote #2

Something can use this entity after your removing, that's why. In your case knife code calls Classify function for damaged entity to choose the damage sound, that's why server crashes. https://github.com/s1lentq/ReGameDLL....cpp#L361-L367. In other case another plugin can get invalid entity when expected to get only valid after your removing (for example next plugin that also hooks Killed for this entity class).
So mostly you should use delayed entity removing.
__________________

Last edited by PRoSToTeM@; 10-30-2016 at 08:30. Reason: misinformation
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
Hedgehog Fog
Senior Member
Join Date: Jun 2010
Location: Ukraine
Old 10-30-2016 , 00:41   Re: Linux server crashes when I kill entity by knife and remove it after
Reply With Quote #3

PRoSToTeM@
Thanks.
Anyway, looks like it's no reason for crash. When engine try to make something with invalid entity we got error messages in console, not a server crash. And this problem appears only on Linux server, no problem on Windows server.
__________________

❄️ CS Snow Wars - Mod based on snowballs fights
🧟 CS Zombie Panic - A port of HL Zombie Panic!
🎃 CS Halloween Mod - Completely new gamemode for Halloween Holidays
📦 AMXXPack - CLI and build system for amxx projects
🔧 Custom Entities API - API to register custom entities
Hedgehog Fog is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 10-30-2016 , 00:46   Re: Linux server crashes when I kill entity by knife and remove it after
Reply With Quote #4

Quote:
Originally Posted by Hedgehog95 View Post
Anyway, looks like it's no reason for crash.
Gamedll try to access already freed memory (privateData is freed), that is a reason for crash.
Quote:
Originally Posted by Hedgehog95 View Post
When engine try to make something with invalid entity we got error messages in console, not a server crash.
First of all that is gamedll, not engine. Secondly gamedll/plugins don't check entity after calling something.
Quote:
Originally Posted by Hedgehog95 View Post
And this problem appears only on Linux server, no problem on Windows server.
That is strange.
__________________

Last edited by PRoSToTeM@; 10-30-2016 at 08:28. Reason: misinformation
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
Solokiller
Senior Member
Join Date: Sep 2015
Old 10-30-2016 , 07:16   Re: Linux server crashes when I kill entity by knife and remove it after
Reply With Quote #5

Calling the EngFunc_RemoveEntity function should be avoided if it's at all possible. It's more of a bookkeeping function for special cases, like failed entity creation.
Normally, SDK code uses UTIL_Remove, which first calls UpdateOnRemove and then flags it for removal with FL_KILLME.

What you're doing bypasses that and makes it possible to break entity cleanup. By removing it right away you also risk the invalid access that PRoSToTeM@ mentioned.
Note that the engine never touches privatedata, it only uses edict and entvars, which are never freed. The engine shouldn't crash when accessing that data.

I've noticed crashes that only occur on one platform, but i don't know what could be causing that. It could be related to how dynamic memory allocation is handled, different algorithms could cause memory to be reused at different points in time.

Last edited by Solokiller; 10-30-2016 at 07:17.
Solokiller is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 10-30-2016 , 07:22   Re: Linux server crashes when I kill entity by knife and remove it after
Reply With Quote #6

Ahm, when the entity is killed, it is automatically removed, you don't have to remove it manually.. probably that's why it is crashing

I remember i had a similar issue some time ago, the server was crashing when i was killing a certain entity with the knife, unfortenately i don't remember how it was happening and what was triggering it
__________________

Last edited by Depresie; 10-30-2016 at 07:25.
Depresie is offline
Solokiller
Senior Member
Join Date: Sep 2015
Old 10-30-2016 , 07:40   Re: Linux server crashes when I kill entity by knife and remove it after
Reply With Quote #7

Quote:
Originally Posted by Depresie View Post
Ahm, when the entity is killed, it is automatically removed, you don't have to remove it manually.. probably that's why it is crashing
That depends on the entity. Killed is called when the entity is killed by taking damage. The entity isn't removed unless the logic in Killed flags it for removal. Killed isn't called at all if you killtarget the entity: https://github.com/ValveSoftware/hal.../subs.cpp#L262

Entities will sometimes delay their own removal after being killed. Monsters will first fade out, or get gibbed before being removed. Weapons call UTIL_Remove in Killed, so it'll be removed by the engine after the frame is done.

Setting FL_KILLME twice won't cause any problems, but calling EngFunc_RemoveEntity does invalidate the private data, which means that if Killed is allowed to run after your code is done, it'll be accessing freed memory. The 'this' pointer may no longer point to a valid pev member at that point, at which point anything could happen.

Last edited by Solokiller; 10-30-2016 at 07:41.
Solokiller is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 10-30-2016 , 08:27   Re: Linux server crashes when I kill entity by knife and remove it after
Reply With Quote #8

Quote:
Originally Posted by Solokiller View Post
Note that the engine never touches privatedata, it only uses edict and entvars, which are never freed. The engine shouldn't crash when accessing that data.
Oh, thanks, forgot it.
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
Hedgehog Fog
Senior Member
Join Date: Jun 2010
Location: Ukraine
Old 10-30-2016 , 10:05   Re: Linux server crashes when I kill entity by knife and remove it after
Reply With Quote #9

Thanks you guys.
__________________

❄️ CS Snow Wars - Mod based on snowballs fights
🧟 CS Zombie Panic - A port of HL Zombie Panic!
🎃 CS Halloween Mod - Completely new gamemode for Halloween Holidays
📦 AMXXPack - CLI and build system for amxx projects
🔧 Custom Entities API - API to register custom entities
Hedgehog Fog 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 00:28.


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