summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2015-12-11 08:09:30 +0100
committerBardur Arantsson <bardur@scientician.net>2015-12-11 08:09:30 +0100
commite07367524c4fb4483057a7d7f983015f66071157 (patch)
tree637b5ec5a9cd9b1d0d0200f39ac77542077de8e2
parent33e7dc3baa6b375efb6d8989ffe3c50511291228 (diff)
Allocate p_ptr dynamically
While this technically introduces one-time memory leak, it also lets us avoid the Static Initialization Fiasco problem if we change player_type to a non-POD.
-rw-r--r--src/dungeon.cc3
-rw-r--r--src/variable.cc7
2 files changed, 4 insertions, 6 deletions
diff --git a/src/dungeon.cc b/src/dungeon.cc
index 62eaf211..9aaf77ed 100644
--- a/src/dungeon.cc
+++ b/src/dungeon.cc
@@ -5122,6 +5122,9 @@ void play_game(bool_ new_game)
bool_ cheat_death = FALSE;
+ /* Initialize player */
+ p_ptr = new player_type();
+
/* Hack -- Character is "icky" */
character_icky = TRUE;
diff --git a/src/variable.cc b/src/variable.cc
index c2fe5de5..65775bef 100644
--- a/src/variable.cc
+++ b/src/variable.cc
@@ -461,14 +461,9 @@ char *keymap_act[KEYMAP_MODES][256];
/*** Player information ***/
/*
- * Static player info record
- */
-player_type p_body;
-
-/*
* Pointer to the player info
*/
-player_type *p_ptr = &p_body;
+player_type *p_ptr = nullptr;
/*
* Pointer to the player tables