Skip to content

Commit

Permalink
Player: Remove hero global
Browse files Browse the repository at this point in the history
Fixes a memory leak when destroying a player with armor equipped.
  • Loading branch information
dscharrer committed Mar 17, 2024
1 parent 5717a8a commit 90a14c6
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 12 deletions.
3 changes: 0 additions & 3 deletions src/core/ArxGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,10 +905,7 @@ bool ArxGame::addPaks() {

static void ReleaseSystemObjects() {

delete hero, hero = nullptr;

if(entities.size() > 0 && entities.player() != nullptr) {
entities.player()->obj = nullptr; // already deleted above (hero)
delete entities.player();
arx_assert(entities.size() > 0 && entities.player() == nullptr);
}
Expand Down
4 changes: 1 addition & 3 deletions src/game/Equipment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ void ARX_EQUIPMENT_RecreatePlayerMesh() {
arx_assert(entities.player());
Entity * io = entities.player();

if(io->obj != hero)
delete io->obj;
delete io->obj;

io->obj = loadObject("graph/obj3d/interactive/npc/human_base/human_base.teo", false).release();

Expand Down Expand Up @@ -250,7 +249,6 @@ void ARX_EQUIPMENT_RecreatePlayerMesh() {
ARX_INTERACTIVE_Show_Hide_1st(entities.player(), !EXTERNALVIEW);
ARX_INTERACTIVE_HideGore(entities.player(), false);

EERIE_Object_Precompute_Fast_Access(hero);
EERIE_Object_Precompute_Fast_Access(entities.player()->obj);

ARX_INTERACTIVE_RemoveGoreOnIO(entities.player());
Expand Down
8 changes: 3 additions & 5 deletions src/game/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ extern long COLLIDED_CLIMB_POLY;
static const float ARX_PLAYER_SKILL_STEALTH_MAX = 100.f;

ARXCHARACTER player;
EERIE_3DOBJ * hero = nullptr;
float currentdistance = 0.f;
float CURRENT_PLAYER_COLOR = 0;
AnimationDuration PLAYER_ROTATION = 0;
Expand Down Expand Up @@ -1083,9 +1082,6 @@ void ARX_PLAYER_Restore_Skin() {
*/
void ARX_PLAYER_LoadHeroAnimsAndMesh() {

hero = loadObject("graph/obj3d/interactive/npc/human_base/human_base.teo", false).release();
PLAYER_SKIN_TC = TextureContainer::Load("graph/obj3d/textures/npc_human_base_hero_head");

herowaitbook = EERIE_ANIMMANAGER_Load("graph/obj3d/anims/npc/human_wait_book.tea");
EERIE_ANIMMANAGER_Load("graph/obj3d/anims/npc/human_normal_wait.tea");
herowait_2h = EERIE_ANIMMANAGER_Load("graph/obj3d/anims/npc/human_wait_book_2handed.tea");
Expand All @@ -1095,7 +1091,9 @@ void ARX_PLAYER_LoadHeroAnimsAndMesh() {
arx_assert(entities.player() == io);
arx_assert(io->idString() == "player");

io->obj = hero;
arx_assert(!io->obj);
io->obj = loadObject("graph/obj3d/interactive/npc/human_base/human_base.teo", false).release();
PLAYER_SKIN_TC = TextureContainer::Load("graph/obj3d/textures/npc_human_base_hero_head");

player.skin = 0;
ARX_PLAYER_Restore_Skin();
Expand Down
1 change: 0 additions & 1 deletion src/game/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@ struct ARXCHARACTER {
extern float CURRENT_PLAYER_COLOR;

extern ARXCHARACTER player;
extern EERIE_3DOBJ * hero;
extern ANIM_HANDLE * herowaitbook;
extern ANIM_HANDLE * herowait_2h;
extern std::vector<std::string> g_playerQuestLogEntries;
Expand Down

0 comments on commit 90a14c6

Please sign in to comment.