From ab7d3679dfed7baf4abdf820aa9a419ae50a2c94 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Fri, 25 Oct 2013 21:57:09 +0000 Subject: [PATCH] At end of G_RestoreMapState(), update g_player[].ps->i from STAT_PLAYER sprites. This fixes a potential crash caused by violating the expected invariant sprite[g_player[player_index].ps->i].yvel == player_index otherwise. git-svn-id: https://svn.eduke32.com/eduke32@4114 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/gameexec.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index e22660485..f0222094e 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -5662,6 +5662,19 @@ void G_RestoreMapState(void) Gv_RefreshPointers(); #endif + // Update g_player[].ps->i (sprite indices of players) to be consistent + // with just loaded sprites. + // Otherwise, crashes may ensue: e.g. WGR2 SVN r391, map spiderden: + // - walk forward (to door leading to other level "Shadowpine Forest") + // - in new level, walk backward to get back to the Spider Den + // - walk backward to the door leading to Shadowpine Forest --> crash. + for (SPRITES_OF(STAT_PLAYER, i)) + { + int32_t snum = sprite[i].yvel; + Bassert((unsigned)snum < MAXPLAYERS); + g_player[snum].ps->i = i; + } + for (i=0; ii].extra = phealth[i];