mirror of
https://github.com/s1lentq/ReGameDLL_CS.git
synced 2025-03-03 17:25:24 +03:00
ActiveGrenade: Fixed a potential leak by checking entities smokegrens life if RemoveGrenade call is somehow missing or blocked
This commit is contained in:
parent
8ff1bf1232
commit
cabdc254c7
@ -491,9 +491,15 @@ void ActiveGrenade::OnEntityGone()
|
||||
m_entity = nullptr;
|
||||
}
|
||||
|
||||
void ActiveGrenade::CheckOnEntityGone()
|
||||
{
|
||||
if (m_dieTimestamp == 0 && !m_entity.IsValid())
|
||||
OnEntityGone();
|
||||
}
|
||||
|
||||
bool ActiveGrenade::IsValid() const
|
||||
{
|
||||
if (!m_entity)
|
||||
if (!m_entity.IsValid())
|
||||
{
|
||||
if (gpGlobals->time > m_dieTimestamp)
|
||||
return false;
|
||||
@ -502,7 +508,7 @@ bool ActiveGrenade::IsValid() const
|
||||
return true;
|
||||
}
|
||||
|
||||
const Vector *ActiveGrenade::GetPosition() const
|
||||
const Vector *ActiveGrenade::GetPosition()
|
||||
{
|
||||
return &m_entity->pev->origin;
|
||||
}
|
||||
|
@ -147,6 +147,8 @@ void CBotManager::StartFrame()
|
||||
ActiveGrenade *ag = (*iter);
|
||||
|
||||
// lazy validation
|
||||
ag->CheckOnEntityGone();
|
||||
|
||||
if (!ag->IsValid())
|
||||
{
|
||||
delete ag;
|
||||
@ -203,6 +205,8 @@ void CBotManager::StartFrame()
|
||||
pBot->BotThink();
|
||||
}
|
||||
}
|
||||
|
||||
ValidateActiveGrenades();
|
||||
}
|
||||
|
||||
// Return the filename for this map's "nav map" file
|
||||
@ -278,13 +282,16 @@ void CBotManager::RemoveGrenade(CGrenade *grenade)
|
||||
}
|
||||
|
||||
// Destroy any invalid active grenades
|
||||
NOXREF void CBotManager::ValidateActiveGrenades()
|
||||
void CBotManager::ValidateActiveGrenades()
|
||||
{
|
||||
auto iter = m_activeGrenadeList.begin();
|
||||
while (iter != m_activeGrenadeList.end())
|
||||
{
|
||||
ActiveGrenade *ag = (*iter);
|
||||
|
||||
// lazy validation
|
||||
ag->CheckOnEntityGone();
|
||||
|
||||
if (!ag->IsValid())
|
||||
{
|
||||
delete ag;
|
||||
@ -314,6 +321,8 @@ bool CBotManager::IsInsideSmokeCloud(const Vector *pos)
|
||||
ActiveGrenade *ag = (*iter);
|
||||
|
||||
// lazy validation
|
||||
ag->CheckOnEntityGone();
|
||||
|
||||
if (!ag->IsValid())
|
||||
{
|
||||
delete ag;
|
||||
@ -358,6 +367,8 @@ bool CBotManager::IsLineBlockedBySmoke(const Vector *from, const Vector *to)
|
||||
ActiveGrenade *ag = (*iter);
|
||||
|
||||
// lazy validation
|
||||
ag->CheckOnEntityGone();
|
||||
|
||||
if (!ag->IsValid())
|
||||
{
|
||||
delete ag;
|
||||
|
@ -42,16 +42,17 @@ public:
|
||||
ActiveGrenade(int weaponID, CGrenade *grenadeEntity);
|
||||
|
||||
void OnEntityGone();
|
||||
void CheckOnEntityGone();
|
||||
bool IsValid() const;
|
||||
|
||||
bool IsEntity(CGrenade *grenade) const { return (grenade == m_entity) ? true : false; }
|
||||
bool IsEntity(CGrenade *grenade) const { return grenade == m_entity; }
|
||||
int GetID() const { return m_id; }
|
||||
const Vector *GetDetonationPosition() const { return &m_detonationPosition; }
|
||||
const Vector *GetPosition() const;
|
||||
const Vector *GetPosition();
|
||||
|
||||
private:
|
||||
int m_id;
|
||||
CGrenade *m_entity;
|
||||
EntityHandle<CGrenade> m_entity;
|
||||
Vector m_detonationPosition;
|
||||
float m_dieTimestamp;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user