fix github issue #106 - polymorph panic
Fixes #106 If dipping a worn amulet into a potion of polymorph turns it into an amulet of change, the game panics while trying to use up that amulet when the new one hasn't replaced the old one in inventory yet. Simply reordering the relevant code isn't sufficient to fix things: once it is in inventory and can be successfully used up, later code would end up deferencing a stale pointer because it was unaware of the deletion.
This commit is contained in:
22
src/potion.c
22
src/potion.c
@@ -1920,26 +1920,22 @@ dodip()
|
||||
5, 95)) {
|
||||
pline1(nothing_happens);
|
||||
} else {
|
||||
boolean was_wep, was_swapwep, was_quiver;
|
||||
short save_otyp = obj->otyp;
|
||||
|
||||
/* KMH, conduct */
|
||||
u.uconduct.polypiles++;
|
||||
|
||||
was_wep = (obj == uwep);
|
||||
was_swapwep = (obj == uswapwep);
|
||||
was_quiver = (obj == uquiver);
|
||||
|
||||
obj = poly_obj(obj, STRANGE_OBJECT);
|
||||
|
||||
if (was_wep)
|
||||
setuwep(obj);
|
||||
else if (was_swapwep)
|
||||
setuswapwep(obj);
|
||||
else if (was_quiver)
|
||||
setuqwep(obj);
|
||||
|
||||
if (obj->otyp != save_otyp) {
|
||||
/*
|
||||
* obj might be gone:
|
||||
* poly_obj() -> set_wear() -> Amulet_on() -> useup()
|
||||
* if obj->otyp is worn amulet and becomes AMULET_OF_CHANGE.
|
||||
*/
|
||||
if (!obj) {
|
||||
makeknown(POT_POLYMORPH);
|
||||
return 1;
|
||||
} else if (obj->otyp != save_otyp) {
|
||||
makeknown(POT_POLYMORPH);
|
||||
useup(potion);
|
||||
prinv((char *) 0, obj, 0L);
|
||||
|
||||
Reference in New Issue
Block a user