kajgan / gnuboy

Automatically exported from code.google.com/p/gnuboy
GNU General Public License v2.0
0 stars 0 forks source link

Donkey Kong Land 2 corrupted battery save after first run under Windows #12

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

I discovered a small incompatibility problem with Donkey Kong Land 2.

Reproducing:
1. make sure that no battery save file with the same name as the rom file exists
2. run Donkey Kong Land 2
3. start a game from an arbitrary internal battery save slot

Depending on which gnuboy version is used one of the following will happen:
- you can play a corrupted boss fight that can be neither won nor lost 
(pre-compiled windows binary based on r136 from the downloads tab)
- game will crash immediatly
(self-compiled version from r177)

The bug happens both under Windows XP SP3 32bit and Windows 7 64bit but 
interestingly enough only under Windows. (I'm currently doing a port for 
Symbian OS, which doesn't show this problem)

I did some testing with a test program (compiled with mingw32 without any 
special options) that first allocates some memory, prints the result and then 
loads the beginning of the corrupted save and prints it.

It _looks_ like memory allocated with {{{malloc()}}} under Windows will 
deterministically begin with {{{78 01}}} (hexadecimal) (4 more or less random 
bytes after that, the rest are mostly zeros) as long as the allocated amount is 
above some arbitrary threshold between one and two kilobytes.

Obviously, Donkey Kong Land 2 will interprete this as a valid save state 
instead of discovering that this is indeed the first run and resetting the 
battery backed-up memory.

Either way, a suitable workaround is manually deleting all the internal battery 
save slots after first run or adding {{{set memfill 0}}} to gnuboy.rc, which in 
my opinion should be default behaviour. (at least for windows builds but such 
random problems might happen under other OSs with other games as well).

Original issue reported on code.google.com by matheoe...@web.de on 8 Feb 2013 at 5:41

GoogleCodeExporter commented 9 years ago
I agree:

{{{
set memfill 0
}}}

should be the default setting (and/or using calloc/recalloc when possible). 
Changing the default setting is probably the most expedient option.

I can see the win32 behavior with malloc() in mingw32 having non-zero, but for 
some weird reason the Donkey Kong Land 2 rom I just tried doesn't crash for me 
under Windows XP SP3 32 bit.

Thanks for the report and analysis, small patch to follow shortly.

Original comment by clac...@gmail.com on 10 Feb 2013 at 5:27

GoogleCodeExporter commented 9 years ago
Fixed by r178.

Original comment by clac...@gmail.com on 10 Feb 2013 at 5:32