Player face grins after restoring savefile

The status bar face momentarily displays a malicious grin whenever the player obtains a new weapon. After a saved game is loaded, however, the grin also appears the first time any item is picked up, weapon or otherwise.

Technical
The malicious grin is triggered during the function ST_updateFaceWidget in st_stuff.c:

if (plyr->bonuscount) { // picking up bonus doevilgrin = false; for (i=0;iweaponowned[i]) { doevilgrin = true; oldweaponsowned[i] = plyr->weaponowned[i]; } } if (doevilgrin) { // evil grin if just picked up weapon priority = 8; st_facecount = ST_EVILGRINCOUNT; st_faceindex = ST_calcPainOffset + ST_EVILGRINOFFSET; } }

The bonuscount field is initially set to zero upon creation of the player thing (P_SpawnPlayer in p_mobj.c), but can be assigned a nonzero value by picking up almost any beneficial object (see the function P_TouchSpecialThing in p_inter.c). Because the variable oldweaponsowned</tt> is local to st_stuff.c</tt>, its value cannot be recorded in the savefile, so it contains uninitialized "junk" values the first time the above conditional statement is executed. Therefore, the bolded test is virtually guaranteed to return TRUE</tt> and produce a grinning face in that instance.

This bug can also manifest itself when the IDKFA or IDFA cheat code is invoked, because the cheats give weapons to the player by directly updating plyr->weaponowned</tt>, bypassing the status bar face completely (see the function ST_Responder</tt> in st_stuff.c</tt>). The next time the player collects any item, the status bar will then "notice" the change in weapons owned and the grinning face will be displayed at that time, even if the new item being collected is a weapon already possessed or an unrelated thing like a health bonus.