dungeons-of-moria / umoria

Moria: a roguelike Dungeon Crawler game | Umoria Source Code
https://umoria.org
GNU General Public License v3.0
353 stars 76 forks source link

[Info] Does not build with gcc-11.1 #44

Closed Rojikku closed 2 years ago

Rojikku commented 3 years ago

Greetings. I maintain https://aur.archlinux.org/packages/umoria/ currently. The build instructions are in the PKGBUILD on there, if you're particularly curious.

I was troubleshooting a failure to build in Arch, but fortunately before posting this I tested my previous builds and found they no longer worked. Some troubleshooting finally led me to see that when I last built I actually had gcc 10 still, which was the issue. I therefore specified the variables CC and CXX to fix this issue- and it STILL didn't work because CMakeLists.txt has g++ hardcoded, so switching it to use g++-10 to get around this issue required a minor patch.

When running make with gcc-11.1 I consistently get the following error:

[ 42%] Building CXX object CMakeFiles/umoria.dir/src/game_save.cpp.o
/home/rojikku/GITS/AUR/umoria/gittest/umoria-5.7.15/src/game_save.cpp: In function ‘bool loadGame(bool&)’:
/home/rojikku/GITS/AUR/umoria/gittest/umoria-5.7.15/src/game_save.cpp:810:29: error: array subscript 66 is above array bounds of ‘Tile_t [66][198]’ [-Werror=array-bounds]
  810 |                 if (tile >= &dg.floor[MAX_HEIGHT][0]) {
      |                             ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/rojikku/GITS/AUR/umoria/gittest/umoria-5.7.15/src/headers.h:59,
                 from /home/rojikku/GITS/AUR/umoria/gittest/umoria-5.7.15/src/game_save.cpp:8:
/home/rojikku/GITS/AUR/umoria/gittest/umoria-5.7.15/src/dungeon.h:55:12: note: while referencing ‘Dungeon_t::floor’
   55 |     Tile_t floor[MAX_HEIGHT][MAX_WIDTH];
      |            ^~~~~
cc1plus: all warnings being treated as errors
make[2]: *** [CMakeFiles/umoria.dir/build.make:370: CMakeFiles/umoria.dir/src/game_save.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/umoria.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

Hopefully, anyone else who experiences this issue will be able to search the reported error and realize it can be solved by using gcc10 instead of gcc11.

I do not know enough about CMake to say if you should make any improvements there, or nearly enough about C++ to suggest if you should make this compatible with gcc11, so consider this issue purely informative.

mrcook commented 3 years ago

Hi @Rojikku , many thanks for the report.

It's certainly going to be useful to support GCC 11 so I will take a look at that. I'll also see what I can do about removing that hard coded g++ requirement.

Regards, Michael

Rojikku commented 3 years ago

Michael,

One of the users in the AUR, aaronp, reported to me that I should just remove line 36 from the CMakeLists.txt (The one with -Werror), which will result in the error above becoming a warning, and thus letting the package build. The advantage being I don't have to make every user install gcc-10 (Though it can be uninstalled right after).

That appears to work, and I didn't encounter any bugs, so that's what I've released for now. Worst case scenario the previous instructions I provided will work for people.

Hopefully that information is useful to your debugging process!

Rojikku

mrcook commented 3 years ago

Thanks Rojikku. That line just outputs various compiler warnings so it's fine to comment it out just to get the build working. I've not encountered any issues with game saves, but still, I'll need to update the code :)

Thanks again, Michael

dbtick commented 2 years ago

Very simple fix, the code is checking in a rather archaic way for an out-of bounds, itself using an out of bound index.

replace the offending line with:

            if (tile > &dg.floor[MAX_HEIGHT-1][MAX_WIDTH-1]) {

and builds fine in gcc 11.2

:-)

mrcook commented 2 years ago

Hi @Rojikku , this has been kindly fixed by the PR from @dbtick.

Thanks!