Attnam / ivan

Iter Vehemens ad Necem - a continuation of the graphical roguelike by members of http://attnam.com
GNU General Public License v2.0
297 stars 42 forks source link

"Player can't be found anywhere" bug #591

Open andrewtweber opened 4 years ago

andrewtweber commented 4 years ago

In the Aslona update, after descending to the tower or the goblin area, it generates the new map and autosaves, then crashes. The tower has worked about 50% of the time, I've only discovered the goblin area once and it failed. The fungal caves have not had this issue. Haven't done any regular GC games since this update.

Then when I try loading the game again, it crashes; the save file is sadly unusable now.

The error it gives is Player can't be found anywhere! Try to restore a backup if available which can be tracked down to bugworkaround.cpp line 426

red-kangaroo commented 4 years ago

Which tower you mean, please?

Aslona update added the Castle of Aslona, the Rebel Camp, the Pyramid, the Goblin Fort and the Fungal Caves. The Goblin Fort has a tower-like icon on worldmap, or maybe the Black Market also resembles tower?

AquariusPower commented 4 years ago

As I remember, this problem (player vanishes after crash) is probably not Aslona specific, this may happen because the way the game works, this is at feio.cpp (now the crash/abort itself is usually related to some item config not found, I still dont get how that can happen)

/**
 * Backups are a fallback mainly when a crash happens like this:
 *
 * - USER action: you try to enter a new dungeon (so it will be created now)
 *
 * - game action: saves a backup of the current dungeon last save at ".bkp"
 * - game action: saves the current dungeon w/o the player on it at ".tmp" (so if this saving crashes, the corrupted .tmp will just be ignored)
 * - game action: copies the sane ".tmp" to the final filename (and deletes the ".tmp" just after)
 *
 * - game bug: the new dungeon creation fails and crashes.
 *
 * This means: the only file remaining with player data (a player char at dungeon pos) is the .bkp one!!!
 */
AquariusPower commented 4 years ago

First thing, backup all savegames now before making any more tests...

so, do you have .bkp saved files for that player? if you have, it will ask to try the backup, just press 'y'

if not, paste here the file list (with file sizes) of your saved game. better if you can upload at least the about 3 newest ones, one of them may contain the player. If you remember the player name, it is easy to check using an hexeditor (like bless, on linux) or may be strings FileName |grep "player name" -i

AquariusPower commented 4 years ago

I just thought... the bug (and abort, that is not a crash) randomly happens only when a NEW dungeon level is generated... so... why not check for the bug, discard the generated dungeon and just generate it again until it is generated w/o any bug? I think it may not be complicated to implement :>

also, may be, to track the bug, a command line could be implemented like --generatedungeonloop <dungeonID> so we would have a lot of use cases to track why it happens!

ryfactor commented 4 years ago

I just got a There was some problem but the Player character was found and moved to requested position bug, upon entering the Goblin Fort. Game crashed and I zipped the savefile, and restored the game by following the prompts, subsequently entered Goblin Fort and the dungeon loaded fine.

when a NEW dungeon level is generated... so... why not check for the bug, discard the generated dungeon and just generate it again until it is generated w/o any bug?

Funny you should say, the world map generator already does this if it can't put (at minimum) the UT exit, Attnam, and GC on one continent. A dungeon generation loop could be a good workaround. Maybe it should try to generate 10 times, and if it fails then generate a "safe" level??

I think one way crashes can happen during dungeon generation is when there are too many rooms specified, such that they can't all be placed inside the level. Either increase level size, or decrease max number of rooms. OTOH, it seems that sometimes the player can't even be placed, so that might mean no rooms/tunnels/stairs are generated??

AquariusPower commented 4 years ago

Funny you should say, the world map generator already does this if it can't put (at minimum) the UT exit, Attnam, and GC on one continent.

nice, that may be a good start (to look at code)!

a safe level could be a static one, I dont know how it is generated but I guess it is from a random seed, so we could store for each dungeon a safe seed before each release, but... I think 10 retries is more than enough, but will take some time making the user wait it end, my guess is it will work in at most 3 times.

sometimes the player can't even be placed, so that might mean no rooms/tunnels/stairs are generated??

that's strange, the only reason for that to happen would be a dungeon filled with non walkable squares (walls, NPCs, forges etc)

til now I only had problems when creating a dungeon and failing with "undefined config sought" error, but that is not a crash and will help as hint :>

there are other crashes but the dungeon was ready already, these (when I catch) I try to fix using the debugger, btw I always run ivan thru nemiver so I can get the context stack and evaluate some variables to understand how to fix :)

AquariusPower commented 4 years ago

this is the retry code: https://github.com/AquariusPower/ivan/blob/SomeFixes1234/Main/Source/dungeon.cpp#L92 after it is generated, it still generates rain and other things but the "undefined config sought" may happen inside that code.

I tested but all levels generated fine, it would require a loop continuously generating many levels to let the problem happen and know if this "retry" really works (mainly concerning the cleanup of a failed attempt, but also any other thing that could leave an invalid state (like invalid variables' values) on the previous attempt). It throws a (non aborting) exception as a way to determine when the next retry must happen.

AquariusPower commented 4 years ago

There is a new code that lets you test dungeon generation. The results will be on dbgmsg log file grep UndefinedConfigurationSought. I tested the Crystal Cave for about 500 times without a problem (took 10 minutes). To test it (linux command line, see ./ivan --help):

export IVAN_DebugGenDungeonLevelLoopID=43; # crystal cave
export IVAN_DebugGenDungeonLevelLoopMax=250; # default is 250. As there is some memory leak I couldn't determine the origin, avoid increasing it (basically ignore this line).
./ivan

so, do you know the dungeon level ID for the tower or the goblin area of Aslona (the one appended on savegame files)? but... with the retry code, this problem may expectedly not happen anymore. If it does, just increase retries from 10 to 20 (or it could even be an environment variable).