CleverRaven/Cataclysm-DDA — pull request #4890 by BevapDin (2013-12-05 19:40:02+00:00)
Title: prevent accessing invalid monster instances

Fix for #4811
That is not (directly) related to the fire, but to the blobs splitting on their death.
`game::kill_mon` calls `monster::death` which calls the monster specific mdeath function (`mdeath::blobsplit` in case of blobs). This function calls `game::add_zombie` which resizes the `_active_monsters` vector. This make the monster reference whose die function is currently called invalid.
After calling the mdeath function the triggers of `this` monster get examined. The access of the members of `this` will cause a segfault, as this was actually part of the now reallocated vector.

This PR creates a temporary copy of the `this` in `monster::death` and accesses it after the death function has been called.

Additionally this spills up in `game::monmove` where critter is initialized as reference into the `_active_monsters` after that vector has been changed (there are actually several point where the `kill_mon`/`die` function might got called) one can not even check `critter.dead` as critter is already invalid! This might also came up elsewhere.

The PR avoids this by using a pointer for the critter in monmove and resetting it after _active_monsters might have changed. The better solution would be to use a vector of monster-pointers but this breaks/changes a lot of other code.

Also changed `mdeath::blobsplit` to not produce blobs with negative speed, even if the dying blob is not seen by the player. This caused infinite new blobs with negative speeds, as a blob would always split when the player does not see it.

Note that the crash was unlikely when there are only few active monsters, because `_active_monsters` might not be reallocated when adding monsters. (The std::vector might allocate more space than needed and can therefor add more items to the vector without it being reallocated each time.) But with the blobs reproducing infinitely (the smoke makes them invisible to the player) it happens. This might also crash the game when there is a blob around that can not be seen for whatever reason.