CleverRaven/Cataclysm-DDA — pull request #6297 by BevapDin (2014-02-25 01:06:30+00:00)
Title: Change the creature_tracker to use a list of pointers to monsters.

Change creature trackers list of monster to be a list of pointers to monster.

This allows inserting/removing of monsters without changing the references that `Creature_tracker::find` / `game::zombie` returns.

For me the game crashes in `mattack::fungus`, after it has spawned a new monster.

The monster list in Creature_tracker is initially reserved to contain 1000 entries. But in that function it will create a 1001. entry. This most likely reallocates the vector and therefor invalidates the monster whose special attack is executed currently. The next iteration of the loop in `mattack::fungus` tries to read `monster::_posx`, but the pointer `z` is now invalid.

Backtrace:
```
#0 0x08068cac in monster::posx (this=0xb7037248) at src/monster.h:274
#1 0x081b9b9c in mattack::fungus (this=0xbf9d2307, z=0xb7037248) at src/monattack.cpp:686
#2 0x0811208b in monster::move (this=0xb7037248) at src/monmove.cpp:294
#3 0x083ccf55 in game::monmove (this=0xb7075008) at src/game.cpp:5793
#4 0x083af9a4 in game::do_turn (this=0xb7075008) at src/game.cpp:1129
#5 0x080c0ccb in main (argc=0, argv=0xbf9d2898) at src/main.cpp:147
(gdb) print g->critter_tracker._old_monsters_list.size()
$1 = 1001
```

I also revert the part in `monster.cpp` introduced by 03b5ba1b. It got added because of the same problem: monster got spawned during their death function, screwing up the list of monster including the currently handled monster.

Both were only a problem when there are many monsters on the map, because the list of monsters was initialized to hold at least 1000 entries without being reallocated.

Fixes #6296, nice car btw.