#14493 closed defect (fixed)

XEEN: Coin of Daily &use magic items crashes game

Reported by: IvoryTower33 Owned by: dreammaster
Priority: normal Component: Engine: MM: Xeen
Version: Keywords:
Cc: Game: Might and Magic: World of Xeen

Description (last modified by dreammaster)

edited: actually, the game crashes frequently when trying to use either of those items, both wand of daily protection and coin of daily sorcery. Not sure why this happens.

Attachments (1)

xeen bug savefile.rar (1.1 MB ) - added by IvoryTower33 18 months ago.

Download all attachments as: .zip

Change History (8)

comment:1 by tag2015, 18 months ago

Component: --Unset--Engine: Xeen
Priority: highnormal
Summary: Coin of Daily sorcery cassts wrong spellXEEN: Coin of Daily sorcery casts wrong spell

by IvoryTower33, 18 months ago

Attachment: xeen bug savefile.rar added

comment:2 by dreammaster, 18 months ago

Owner: set to dreammaster
Resolution: fixed
Status: newclosed

Fixed, thanks for noticing the problem.

Just a heads-up, if you decide to test out the fix.. daily builds right now don't have compiled data needed for Xeen. In order to run it, you need a downloaded copy of the ScummVM source, and from the Launcher, select the game's Game Options, go to the Paths tab, and point the Extra Path to /devtools/create_mm folder of the ScummVM source.

comment:3 by IvoryTower33, 18 months ago

I've set it up correctly, meaning the extra path and such, but now when I try to use the item it crashes my game I'm afraid.

I've experienced this issue before with the "day of protection" wand, which I fixed by reloading another game. Not entirely sure what might be happening.

EDIT: casting recharge item on the "coin of daily sorcery" seems to have fixed the issue : O

comment:4 by IvoryTower33, 18 months ago

actually, the game crashes frequently when trying to use either of those items, both wand of daily protection and coin of daily sorcery. Not sure why this happens.

comment:5 by IvoryTower33, 18 months ago

Description: modified (diff)
Resolution: fixed
Status: closednew
Summary: XEEN: Coin of Daily sorcery casts wrong spellXEEN: Coin of Daily &use magic items crashes game

comment:6 by PushmePullyu, 18 months ago

Tested with master c77e9f8cae261673478fbf071401c767995a3b24.

This seems to be caused by a stale pointer dereference when a item spell uses combat._oldCharacter.

dialogs/dialogs_items.cpp:

int ItemsDialog::doItemOptions(...) {
...
    _oldCharacter = &c;
    // FIXME: Some spells use combat._oldCharacter, and it may not be set
    // if an item is used directly after the game is started
    if (!combat._oldCharacter)
        combat._oldCharacter = &c;
...
}

If combat._oldCharacter was set before and a new game is loaded the check will fail and it will not be reset. A possible fix would be to reset combat._oldCharacter to nullptr when loading a game (e.g. in Combat::setupCombatParty()).

To reproduce:

  1. Load slot 23: "dasd" (from the provided save)
  2. Use the "Coin of daily sorcerery" (sic)
  3. Load slot 23 again
  4. Use the coin again

This should either trigger a crash or an invalid memory access when using an address sanitizer like Valgrind.

Last edited 18 months ago by PushmePullyu (previous) (diff)

comment:7 by dreammaster, 18 months ago

Description: modified (diff)
Resolution: fixed
Status: newclosed

You're right. I dug a bit deeper, and Combat._oldCharacter is set all the time when a character casts a spell (so it would really be more appropriate if it were a general global). So it was proper to always properly set the field to the character whose item is being used, no matter what mode the game is in. I've now committed an appropriate fix.

Note: See TracTickets for help on using tickets.