CaravelGames / drod

The official public repository of Deadly Rooms of Death and DROD RPG
http://caravelgames.com
56 stars 17 forks source link

Fix import crash when deleting character #522

Closed Hypexion closed 1 year ago

Hypexion commented 1 year ago

Due to 5.2 changes, importing a hold that contains a character crashes the game.

This happens in CDbRoom::ClearMonsters. Due to the addition of character behaviors allow characters to be monster targets, characters with these behaviors need to be removed from the monster enemy list when deleted. This requires the CMonster pointer to the character to be cast to CCharacter to check for these behaviors. Due to the particulars of how monsters are imported, this cast fails during importing, and the game crashes when trying to access an invalid pointer.

This can be avoided by checking if the room is attached to a game. Characters cannot gain behaviors until their game is set, and this does not happen during importing. Therefore, the check for monster target behaviors can be safely skipped.

Thread: https://forum.caravelgames.com/viewtopic.php?TopicID=45937