stransky / berusky2

Berusky 2 (Bugs Escape 3D) is a game that challenges your visual/spatial thinking and ability to find a way to resolve a logic task. Using five bugs, you'll go through an adventure full of various puzzles spread across nine episodes. Individual episodes differ in appearance and difficulty, which increases throughout the game.
http://anakreon.cz/en/Berusky2.htm
GNU General Public License v3.0
14 stars 3 forks source link

Saved games don't appear in the load/save menu #20

Closed apoleon closed 11 years ago

apoleon commented 11 years ago

I can successfully save games and they show up in ~/.berusky2/Save but they don't appear in the load/save menu. So it is impossible to load a game again from the in-game menu.

I'm not sure if this is a well-known bug or if I made a mistake when I had to adjust the game paths to Debian specific values. Feedback welcome.

stransky commented 11 years ago

The game can be saved and loaded under the same profile. The profile name is stored in the saved game and it's compared with active profile name. For instance if you play a level from command line ($berusky2 - u level_name.lv6) and game is saved, it's not shown when you try to load it from game menu under some profile.

stransky commented 11 years ago

There's a simple testcase:

1) start the game under some profile 2) run some level (tutorial, journey...) 3) save game 4) quit and run game again with the same profile 5) load the game in menu

apoleon commented 11 years ago

Hi,

On 17.09.2013 23:21, Martin Stransky wrote:

There's a simple testcase:

1) start the game under some profile 2) run some level (tutorial, journey...) 3) save game 4) quit and run game again with the same profile 5) load the game in menu

That's what I would expect to see, too.

I created only one profile, ran the first tutorial level, I saved the game and quit it. I can see the saved game in ~/.berusky2/Save but when I restart the game and try to load the savegame there is no visible entry.

I can only imagine that the Debian-specific data patch changed this behaviour unintentionally.

http://patch-tracker.debian.org/patch/series/view/berusky2/0.9.1-1/data.patch

although I only changed all occurrences of /usr/share to /usr/share/games.

apoleon commented 11 years ago

I think I have identified the root cause of this issue.

This only happens when I compile the game with -D_FORTIFY_SOURCE=2 and other hardening compiler flags, which is the default in Debian.

It turned out that a bug in load_level.cpp caused undefined behavior because the variable 'p_Level_Name' is used as parameter and destination in sprintf. This leads to the weird and buggy behavior that it is possible to save levels but not to load them anymore and that the game aborts when you try to record a game. I haven't found a complete solution yet but I'm attaching a preliminary patch for load_level.cpp that fixes the load level bug.

https://gist.github.com/apoleon/6731208

apoleon commented 11 years ago

Btw, I have found this error with cppcheck. There are two more possible errors in load_level.cpp at line 833 and 919.

kofola/load_level.cpp:833]: (error) Resource leak: file [kofola/load_level.cpp:919]: (error) Resource leak: file

stransky commented 11 years ago

The file lead doesn't seem to be significant here (and look like a false alarm to me).

stransky commented 11 years ago

The loading should be fixed now, but save format is different. If you try to load old savegame, the game crashes (because of old savegame format with different MAX_PATH size, which is depend on the system settings).

The new save uses a fixed sizes intependent on the MAX_PATH. Unfortunately I can't detect the old saves but I'll try to fix the game crash.

stransky commented 11 years ago

The savegame crash is fixed by commit 922d467231d63086ba5d55c3bbbb5d43557c1e2c

stransky commented 11 years ago

The savegames are saved in ~/.berusky2/Save ... do you have those files? Each directory contains one save. But test with latest git snapshot.

apoleon commented 11 years ago

Yes, I can see the savegames in ~/.berusky2/Save but they are not shown in-game when I try to load them again.

The problem lies in load_level.cpp. It seems you missed my patch above. I have rebased it against the latest git commit.

https://gist.github.com/apoleon/7305139

So basically the problem here is, that you use the same name for the parameter and your target. This is undefined behaviour for the gcc compiler. In this specific case the game is saved to ~/.berusky2/Save but never appears in the load menu.

I can confirm that the patch fixes the issue, here on Debian with FORTIFY_SOURCE turned on.

stransky commented 11 years ago

Ahh, thanks for the patch, I overlooked it. commit f4d62b7465bc46c8b0c4bad67ab2731b3b45af43

stransky commented 11 years ago

I guess it's okay now...