Closed vineyy closed 1 year ago
Thank you for the bug report and investigation! Hmm, errors like this shouldn't happen with such basic operations, and don't reproduce in the Windows version.
The function CMon::Set() explicitly checks that the input coordinates are within the bounds of the bitmap, so can't set memory off the edge. Similarly, CMon::BitmapSet() simply loops over the bitmap's memory addresses, so shouldn't set bad memory either. However, I notice the valgrind errors are "Invalid read of size 8" and "Invalid write of size 8". These should only ever be reads and writes of size 4, because the bitmap is an array of unsigned longs (i.e. 32 bit or 4 byte quantities).
Perhaps there's something going on that's making longs size 8, which is causing read/writes to happen one long beyond the end of the allocation? Indeed, one way to avoid the problem is to ensure the vertical size of the bitmap is even, e.g. do "Size 35 36" instead, which should work. (Every bitmap row is some number of longs, so an even row bitmap is guaranteed to have a even number of longs total, or an integer number of 8 byte chunks.) Similarly, the following quick code change should fix the problem too, by padding the memory allocation with an extra long's worth of space:
In daedalus.cpp line 3010, at the start of the function PAllocate(), insert the following line of code: lcb += 4;
Perhaps there's something going on that's making longs size 8
Mine is a 64-bit Linux so long is 8 byte.
lcb += 4;
With this fix, I did not see any crashes. I ran it with valgrind and there is no invalid read/write now.
Thank you for trying out the fix, and reporting that it works! Since it does work, I will make sure this change is in the next version of Daedalus.
I cloned the code on Ubuntu 20.04, commented out
#define WIN
and#define PC
inutil.h
and compiled using the makefile mentioned in #1. Build was successful and I was able to generate mazes. But for some values of Size parameters, it crashesInterestingly
./daedalus 'Size 34 34 1 0 ab P SaveText "files/QWoGKzqOxF"'
and./daedalus 'Size 36 36 1 0 ab P SaveText "files/QWoGKzqOxF"'
worked without any issue.gdb to see where the crash is:
I suspected memory overwrite so I ran it with valgrind:
Machine config:
Please let me know if you need any more information.