Skip to content

Commit

Permalink
Crash Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
caxanga334 committed Dec 8, 2024
1 parent a90b599 commit 57a0024
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 4 additions & 4 deletions extension/bot/interfaces/inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void IInventory::Reset()

edict_t* weapon = GetBot()->GetActiveWeapon();

if (weapon != nullptr)
if (UtilHelpers::IsValidEdict(weapon))
{
m_cachedActiveWeapon = std::make_shared<CBotWeapon>(weapon);
}
Expand All @@ -48,7 +48,7 @@ void IInventory::Update()

edict_t* weapon = GetBot()->GetActiveWeapon();

if (weapon != nullptr && m_cachedActiveWeapon->GetEdict() != weapon)
if (UtilHelpers::IsValidEdict(weapon) && m_cachedActiveWeapon->GetEdict() != weapon)
{
m_cachedActiveWeapon = std::make_shared<CBotWeapon>(weapon);
}
Expand Down Expand Up @@ -95,7 +95,7 @@ void IInventory::BuildInventory()

edict_t* weapon = gamehelpers->EdictOfIndex(index);

if (!weapon || weapon->IsFree() || weapon->GetIServerEntity() == nullptr)
if (!UtilHelpers::IsValidEdict(weapon))
continue;

m_weapons.emplace_back(new CBotWeapon(weapon));
Expand Down Expand Up @@ -168,7 +168,7 @@ std::shared_ptr<CBotWeapon> IInventory::GetActiveBotWeapon()
{
edict_t* weapon = GetBot()->GetActiveWeapon();

if (weapon == nullptr)
if (!UtilHelpers::IsValidEdict(weapon))
{
return nullptr;
}
Expand Down
10 changes: 10 additions & 0 deletions extension/util/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ namespace UtilHelpers
return edict != nullptr;
}

inline bool IsValidEdict(edict_t* edict)
{
if (edict == nullptr || edict->IsFree() || edict->GetIServerEntity() == nullptr)
{
return false;
}

return true;
}

// Returns whether or not an entity has a valid networkable edict.
bool IsEntNetworkable(int index);
// Returns whether or not an entity has a valid networkable edict.
Expand Down

0 comments on commit 57a0024

Please sign in to comment.