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

Solved remove_entity crash - amxx 1.9


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LordDeath
Member
Join Date: Feb 2019
Old 05-09-2020 , 21:26   remove_entity crash - amxx 1.9
Reply With Quote #1

Well, I have an entity index which I remove with remove_entity native. everything goes fine till I try to remove it the next round using checks (which shouldn't crash the server), but the if condition path somehow and then the server crashes.
Ex:
Code:
public basic_entity(id)
{
new Entity = create_entity("info_target");
Entity settings code (Model, Owner, Origin,etc...)
myEnt[id] = Entity
}
now, let's say I kill the entity and it goes fine
Code:
if(myEnt[id] && is_valid_ent(myEnt[id]))
remove_entity(myEnt[id])
it gets removed normally and it goes fine, then I kill it again while it's not there using the same code
Code:
if(myEnt[id] && is_valid_ent(myEnt[id]))
remove_entity(myEnt[id])
The server crashes, as if the entity is in the world (if condintion passes while it shouldn't).
even keeping the native alone, the server still crashes and the code gets excuted regardless of the check
Code:
if(is_valid_ent(myEnt[id]))
remove_entity(myEnt[id])
the IF condiontions shouldn't pass since the entity isn't there, but still, it passes and the code native gets executed and crashes the server. any solution?

Last edited by LordDeath; 05-10-2020 at 14:08.
LordDeath is offline
simanovich
AlliedModders Donor
Join Date: Jun 2012
Location: Israel
Old 05-10-2020 , 06:00   Re: remove_entity crash - amxx 1.9
Reply With Quote #2

Because is_vaild_ent returns true if the entity index is valid (aka 0<entindex<maxEntities), and doesn't check if the entity does actually exists in the game.


Use pev_vaild.
__________________
simanovich is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 05-10-2020 , 07:20   Re: remove_entity crash - amxx 1.9
Reply With Quote #3

Quote:
Originally Posted by simanovich View Post
Because is_vaild_ent returns true if the entity index is valid (aka 0<entindex<maxEntities), and doesn't check if the entity does actually exists in the game.


Use pev_vaild.
That's kind correct.

Make sure to reset the variable to 0 once you remove it.

Give the entity the flag FL_KILLME ( set_pev(ent, pev_flags, FL_KILLME) ) TO Safely remove it.

Also it really depends a lot when and how are you removing it but I suggest to give it the flag killme for safety remove.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 05-10-2020 at 07:27.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
LordDeath
Member
Join Date: Feb 2019
Old 05-10-2020 , 14:08   Re: remove_entity crash - amxx 1.9
Reply With Quote #4

Thank you guys,
Solved
LordDeath is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 05-14-2020 , 11:45   Re: remove_entity crash - amxx 1.9
Reply With Quote #5

Quote:
Originally Posted by simanovich View Post
Because is_vaild_ent returns true if the entity index is valid (aka 0<entindex<maxEntities), and doesn't check if the entity does actually exists in the game.


Use pev_vaild.
Take a look next time

PHP Code:
int is_ent_valid(int iEnt)
{
    if (
iEnt || iEnt gpGlobals->maxEntities
        return 
0;

    if (
iEnt <= gpGlobals->maxClients)
    {
        if (!
MF_IsPlayerIngame(iEnt))
        {
            return 
0;
        }
    } else {
        if (
FNullEnt(TypeConversion.id_to_edict(iEnt)))
        {
            return 
0;
        }
    }

    return 
1;

PHP Code:
        edict_tid_to_edict(int index)
        {
            if (
index || index >= gpGlobals->maxEntities)
            {
                return 
nullptr;
            }

            if (!
index)
            {
                return 
m_FirstEdict;
            }

            
auto pEdict static_cast<edict_t*>(m_FirstEdict index);

            if (
pEdict && (pEdict->free || (index gpGlobals->maxClients && !pEdict->pvPrivateData)))
            {
                return 
nullptr;
            }

            return 
pEdict;
        } 
It's more than a dumb check. It is correctly asking if is not freed, also validating its private data pointer. remove_entity calls ED_Free, which immediately frees the memory and sets the corresponding flags.

At this point, the statement (is_valid_ent(entityindex)) == (pev_valid(entityindex) == 2) is always true when entityindex is not a player.
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross

Last edited by meTaLiCroSS; 05-14-2020 at 11:47.
meTaLiCroSS 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 10:49.


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