Raised This Month: $120 Target: $400
 30% 

Crash on Vector's operator+ inside CBeam::Center


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 12-07-2018 , 23:46   Crash on Vector's operator+ inside CBeam::Center
Reply With Quote #1

Hi folks

Today I figured out a crash that happened a few hours ago. I've analyzed coredump's backtrace, and this threw out:

Code:
(gdb) bt full
#0  operator+ (v=..., this=<optimized out>) at ../cstrike/dlls/vector.h:111
No locals.
#1  CBeam::Center (this=0xa0b71fa0) at ../cstrike/dlls/effects.h:148
No locals.
#2  0xb2ee817f in CBasePlayer::UpdateClientData (this=0xfa7a630) at ../cstrike/dlls/player.cpp:8188
        pEntity = 0xb31e42c4
        damageOrigin = {x = <optimized out>, y = -1808, z = -147}
        other = <optimized out>
        visibleDamageBits = <optimized out>
        i = <optimized out>
#3  0xb248b5ce in ?? () from cstrike/addons/amxmodx/modules/hamsandwich_amxx_i386.so
No symbol table info available.
#4  0x0aaed013 in ?? ()
No symbol table info available.
#5  0xb2eeae1d in CBasePlayer::RemoveAllItems (this=0xfa7a630, removeSuit=0) at ../cstrike/dlls/player.cpp:1953
        bKillProgBar = <optimized out>
        i = <optimized out>
        pPendingItem = <optimized out>
#6  0xb2e908e0 in DispatchUse (pentUsed=0xb33473c4, pentOther=0xb330e1d8) at ../cstrike/dlls/cbase.cpp:593
        pEntity = 0x88
        pOther = 0xb31e42c4
#7  0xb26a16b8 in ?? () from cstrike/addons/amxmodx/modules/fun_amxx_i386.so
No symbol table info available.
Summarizing (a wild guess):

strip_user_weapons from Fun
->
DispatchUse, CStripWeapons::Use
->
CBasePlayer::RemoveAllItems
->
CBasePlayer::UpdateClientData (hooked with Ham also)

And inside this last one:

Code:
// player.cpp     if (pev->dmg_take || pev->dmg_save || m_bitsHUDDamage != m_bitsDamageType)     {         Vector damageOrigin = pev->origin;         edict_t *other = pev->dmg_inflictor;         if (other)         {             CBaseEntity *pEntity = CBaseEntity::Instance(other);             if (pEntity)
                damageOrigin = pEntity->Center();
        }         int visibleDamageBits = m_bitsDamageType & DMG_SHOWNHUD;         MESSAGE_BEGIN(MSG_ONE, gmsgDamage, NULL, pev);         WRITE_BYTE((int)pev->dmg_save);         WRITE_BYTE((int)pev->dmg_take);         WRITE_LONG(visibleDamageBits);         WRITE_COORD(damageOrigin.x);         WRITE_COORD(damageOrigin.y);         WRITE_COORD(damageOrigin.z);         MESSAGE_END();         pev->dmg_take = 0;         pev->dmg_save = 0;         m_bitsHUDDamage = m_bitsDamageType;         m_bitsDamageType &= DMG_TIMEBASED;     }

It makes completely sense. I implemented a Module that simplifies Beam creation (for Lasermine addon). But none of these are used as Inflictor in some custom-made damage, so I think this is a buffer issue, because "dmg_inflictor" entvar is NEVER reseted.

So, inside CBeam::Center we have:

PHP Code:
// effects.h

public:
    
Vector Center(void){ return (GetStartPos() + GetEndPos()) * 0.5; } 
PHP Code:

// effects.cpp

const Vector &CBeam::GetStartPos()
{
    if (
GetType() == BEAM_ENTS)
    {
        
edict_t *pent INDEXENT(GetStartEntity());
        return 
pent->v.origin;
    }

    return 
pev->origin;
}

const 
Vector &CBeam::GetEndPos()
{
    
int type GetType();
    if (
type == BEAM_POINTS || type == BEAM_HOSE)
    {
        return 
pev->angles;
    }

    
edict_t *pent INDEXENT(GetEndEntity());
    if (
pent)
    {
        return 
pent->v.origin;
    }

    return 
pev->angles;

And lastly:

PHP Code:

// vector.h

    
inline Vector operator+(const Vectorv) const    { return Vector(x+v.xy+v.yz+v.z);} 
Some years ago I made a module for creating Beams. I always have doubt about dealing with "Vector &" datatype. So, I'll attach those functions here, since this is not a plugin problem, and it is related to an arithmetic; this issue smells like an addressing problem

Code:
// Start position
Vector _GetStartPos(edict_t *pEnt)
{     if( _GetType(pEnt) == BEAM_ENTS )     {         edict_t *pStartEnt = GETEDICT(_GetStartEntity(pEnt));
        return pStartEnt->v.origin;
    }    
    return pEnt->v.origin;
}
void _SetStartPos(edict_t *pEnt, const Vector &pos)
{
    pEnt->v.origin = pos;
} // End position
Vector _GetEndPos(edict_t *pEnt)
{     int type = _GetType(pEnt);     if (type == BEAM_POINTS || type == BEAM_HOSE)         return pEnt->v.angles;     edict_t *pEndEnt = GETEDICT(_GetEndEntity(pEnt));     if (!FNullEnt(pEndEnt))
        return pEndEnt->v.origin;
    return pEnt->v.angles;
}
void _SetEndPos(edict_t *pEnt, const Vector &pos)
{
    pEnt->v.angles = pos;
} static cell AMX_NATIVE_CALL Beam_GetStartPos(AMX *amx, cell *params) {     CHECK_ENTITY_SIMPLE(params[1]);     Vector pReturn = _GetStartPos(GETEDICT(params[1]));     cell *vecRet = MF_GetAmxAddr(amx, params[2]);     vecRet[0] = amx_ftoc(pReturn.x);     vecRet[1] = amx_ftoc(pReturn.y);     vecRet[2] = amx_ftoc(pReturn.z);     return 1; } static cell AMX_NATIVE_CALL Beam_SetStartPos(AMX *amx, cell *params) {     CHECK_ENTITY_SIMPLE(params[1]);     cell *vecPosition = MF_GetAmxAddr(amx, params[2]);
    _SetStartPos(GETEDICT(params[1]), Vector(amx_ctof(vecPosition[0]), amx_ctof(vecPosition[1]), amx_ctof(vecPosition[2])));
    return 1; } static cell AMX_NATIVE_CALL Beam_GetEndPos(AMX *amx, cell *params) {     CHECK_ENTITY_SIMPLE(params[1]);     Vector pReturn = _GetEndPos(GETEDICT(params[1]));     cell *vecRet = MF_GetAmxAddr(amx, params[2]);     vecRet[0] = amx_ftoc(pReturn.x);     vecRet[1] = amx_ftoc(pReturn.y);     vecRet[2] = amx_ftoc(pReturn.z);     return 1; } static cell AMX_NATIVE_CALL Beam_SetEndPos(AMX *amx, cell *params) {     CHECK_ENTITY_SIMPLE(params[1]);     cell *vecPosition = MF_GetAmxAddr(amx, params[2]);
    _SetEndPos(GETEDICT(params[1]), Vector(amx_ctof(vecPosition[0]), amx_ctof(vecPosition[1]), amx_ctof(vecPosition[2])));
    return 1; } static cell AMX_NATIVE_CALL Beam_Create(AMX *amx, cell *params) {     edict_t* pEnt = CREATE_NAMED_ENTITY(ALLOC_STRING("beam"));         if(FNullEnt(pEnt))         return 0;             int iLen;     char *szModel = MF_GetAmxString(amx, params[1], 1, &iLen);         pEnt->v.flags |= FL_CUSTOMENTITY;     _SetColor(pEnt, 255, 255, 255);     _SetBrightness(pEnt, 255.0);     _SetNoise(pEnt, 0);     _SetFrame(pEnt, 0.0);     _SetScrollRate(pEnt, 0.0);     _SetWidth(pEnt, 10.0);     _SetTexture(pEnt, MODEL_INDEX(szModel));         //SET_MODEL(pEnt, (char*)STRING(ALLOC_STRING(szModel)));     pEnt->v.model = ALLOC_STRING(szModel);     pEnt->v.skin = 0;     pEnt->v.sequence = 0;     pEnt->v.rendermode = 0;     return ENTINDEX(pEnt); } static cell AMX_NATIVE_CALL Beam_PointsInit(AMX *amx, cell *params) {     CHECK_ENTITY_SIMPLE(params[1]);     edict_t *pEnt = GETEDICT(params[1]);         cell *vecStart = MF_GetAmxAddr(amx, params[2]);     cell *vecEnd = MF_GetAmxAddr(amx, params[3]);         _SetType(pEnt, BEAM_POINTS);
    _SetStartPos(pEnt, Vector(amx_ctof(vecStart[0]), amx_ctof(vecStart[1]), amx_ctof(vecStart[2])));
    _SetEndPos(pEnt, Vector(amx_ctof(vecEnd[0]), amx_ctof(vecEnd[1]), amx_ctof(vecEnd[2])));
    _SetStartAttachment(pEnt, 0);     _SetEndAttachment(pEnt, 0);     _RelinkBeam(pEnt);     return 1; } static cell AMX_NATIVE_CALL Beam_HoseInit(AMX *amx, cell *params) {     CHECK_ENTITY_SIMPLE(params[1]);     edict_t *pEnt = GETEDICT(params[1]);         cell *vecStart = MF_GetAmxAddr(amx, params[2]);     cell *vecDir = MF_GetAmxAddr(amx, params[3]);         _SetType(pEnt, BEAM_HOSE);
    _SetStartPos(pEnt, Vector(amx_ctof(vecStart[0]), amx_ctof(vecStart[1]), amx_ctof(vecStart[2])));
    _SetEndPos(pEnt, Vector(amx_ctof(vecDir[0]), amx_ctof(vecDir[1]), amx_ctof(vecDir[2])));
    _SetStartAttachment(pEnt, 0);     _SetEndAttachment(pEnt, 0);     _RelinkBeam(pEnt);     return 1; } static cell AMX_NATIVE_CALL Beam_PointEntInit(AMX *amx, cell *params) {     CHECK_ENTITY_SIMPLE(params[1]);     CHECK_ENTITY_SIMPLE(params[3]);     edict_t *pEnt = GETEDICT(params[1]);         cell *vecPoint = MF_GetAmxAddr(amx, params[2]);         _SetType(pEnt, BEAM_ENTPOINT);
    _SetStartPos(pEnt, Vector(amx_ctof(vecPoint[0]), amx_ctof(vecPoint[1]), amx_ctof(vecPoint[2])));
    _SetEndEntity(pEnt, params[3]);     _SetStartAttachment(pEnt, 0);     _SetEndAttachment(pEnt, 0);     _RelinkBeam(pEnt);     return 1; } #define CHECK_ENTITY_SIMPLE(x) \     if (x < 0 || x > gpGlobals->maxEntities) { \         MF_LogError(amx, AMX_ERR_NATIVE, "Entity out of range (%d)", x); \         return 0; \     } else { \         if (x != 0 && FNullEnt(INDEXENT(x))) { \             MF_LogError(amx, AMX_ERR_NATIVE, "Invalid entity %d", x); \             return 0; \         } \     }

Real and final question here is: Is this well developed? I mean, data typing and how variables are set/get thinking it's Vector& and not Vector.. (and beam creation also)

I've tried to explain as best as possible. Any other info you think it's crucial to attach, please let me know. Thanks in advance.
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross

Last edited by meTaLiCroSS; 12-07-2018 at 23:52.
meTaLiCroSS is offline
Reply


Thread Tools
Display Modes

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:10.


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