segmentation fault on start NIKO BOHM'S TUTORIAL levels

Found a bug in R'n'D? Report it here!

Moderators: Flumminator, Zomis

Post Reply
BryanFRitt
Posts: 219
Joined: Mon Nov 13, 2017 4:16 pm

segmentation fault on start NIKO BOHM'S TUTORIAL levels

Post by BryanFRitt »

In Rocks'n'Diamonds 4.3.1.0 When I try to start NIKO BOHM'S TUTORIAL LEVEL 001 etc... it freezes and segfaults with:
Thread 1 "rocksndiamonds" received signal SIGSEGV, Segmentation fault.
0x00005555556664d9 in el2img (element=1515714624) at tools.c:8358
8358 element = GFX_ELEMENT(element);
(gdb) bt
#0 0x00005555556664d9 in el2img (element=1515714624) at tools.c:8358
#1 0x000055555565a3fb in DrawScreenElementExt (x=22, y=2, dx=0, dy=0, element=1515714624, cut_mode=0, mask_mode=0) at tools.c:2021
#2 0x000055555565c907 in DrawScreenElement (x=22, y=2, element=0) at tools.c:2536
#3 0x000055555565ca84 in DrawScreenField (x=22, y=2) at tools.c:2558
#4 0x000055555565f20c in DrawLevel (draw_background_mask=2) at tools.c:3377
#5 0x0000555555695965 in InitGame () at game.c:4403
#6 0x00005555556b7e44 in StartGameActions (init_network_game=0, record_tape=1, random_seed=0) at game.c:11761
#7 0x0000555555670a1a in HandleMainMenu (mx=0, my=0, dx=0, dy=0, button=0) at screens.c:2235
#8 0x0000555555654f44 in HandleKey (key=13, key_status=1) at events.c:2349
#9 0x0000555555653513 in HandleKeyEvent (event=0x7fffffffd8d0) at events.c:1502
#10 0x00005555556512bc in HandleEvents () at events.c:263
#11 0x00005555556514c1 in EventLoop () at events.c:369
#12 0x000055555564425a in main (argc=1, argv=0x7fffffffda28) at main.c:7876
UPDATE: This seems to affect more than this levelset, but not all levelsets.
Life is partially trying to strike a balance between generating new things/ideas, and making sure they are good/organized. These extremes can be said to between gibberish mess and nothing said/done.
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: segmentation fault on start NIKO BOHM'S TUTORIAL levels

Post by Holger »

Are you able to reproduce this crash on a different computer?

I remember that you encountered lots of R'n'D crashes in the past on your computer that I could never reproduce.

I'm especially baffled that the problem occurs with level 001 of level set "Niko Böhm's Tutorial Levels", which is the first level of the first level set that everybody plays first (in fact, it's the most played level and level set according to the high score server), and it is THE LEVEL I constantly use for whatever tests I do in R'n'D.

But this really does not look good:

Code: Select all

#1 0x000055555565a3fb in DrawScreenElementExt (x=22, y=2, dx=0, dy=0, element=1515714624, cut_mode=0, mask_mode=0) at tools.c:2021
#2 0x000055555565c907 in DrawScreenElement (x=22, y=2, element=0) at tools.c:2536
That is, "DrawScreenElement()" gets parameter "element" with value "0", but in "DrawScreenElementExt()" that same parameter now has the value "1515714624". Here's the code for "DrawScreenElement()":

Code: Select all

void DrawScreenElement(int x, int y, int element)
{
  int mask_mode = NO_MASKING;

  if (game.use_masked_elements)
  {
    int lx = LEVELX(x), ly = LEVELY(y);

    if (IN_LEV_FIELD(lx, ly) && element != EL_EMPTY)
    {
      DrawScreenElementExt(x, y, 0, 0, EL_EMPTY, NO_CUTTING, NO_MASKING);

      mask_mode = USE_MASKING;
    }
  }

  DrawScreenElementExt(x, y, 0, 0, element, NO_CUTTING, mask_mode);
  DrawLevelFieldCrumbled(LEVELX(x), LEVELY(y));
}
As we can see, parameter "element" is taken as it is and used in calling "DrawScreenElementExt()" directly. (Or set to EL_EMPTY, which is "0", but line 2536 is the second case here.)

I have no idea what else could cause such a symptom/stacktrace other than memory problems (as there are no other threads running when starting a level that could change the game's memory area).

Does anybody else have the slightest idea what else could cause such a problem?
BryanFRitt
Posts: 219
Joined: Mon Nov 13, 2017 4:16 pm

Re: segmentation fault on start NIKO BOHM'S TUTORIAL levels

Post by BryanFRitt »

Trying with 4.3.0.3, and this bug did not show up.
Going back to 4.3.1.0 and this bug reappears.
This happens when trying to start a level. Never got beyond that point. Unless my memory is messed up, The older bug would happen when playing, and disappeared with a later version of R'n'D.
Older bug link: viewtopic.php?p=3086
I tried re-downloading the newer R'n'D to see if that helps, and the same issue still happens.
Linux version, extracted and ran `make --debug` then ran the `rocksndiamonds`

Switched the theme from the 'WIDESCREEN MODE [1920x1080]' one to 'CLASSIC GRAPHICS', and the problem went away.
When switched back to 'WIDESCREEN MODE [1920x1080]', and the problem came back.
So maybe R'n'D version 4.3.1.0 and this 'CUSTOM GRAPHICS' aren't compatible, while R'n'D version 4.3.0.3 and this 'CUSTOM GRAPHICS' are.
MAIN MENU > SETUP > CUSTOM ARTWORK > CUSTOM GRAPHICS > ...
'WIDESCREEN MODE' 'CUSTOM GRAPHICS' link: viewtopic.php?p=17277
Last edited by BryanFRitt on Sun Feb 06, 2022 4:26 am, edited 2 times in total.
Life is partially trying to strike a balance between generating new things/ideas, and making sure they are good/organized. These extremes can be said to between gibberish mess and nothing said/done.
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: segmentation fault on start NIKO BOHM'S TUTORIAL levels

Post by Holger »

That's a very interesting observation, and may help to find the problem!

Are you able to use "git bisect" to find the commit between 4.3.0.3 and 4.3.1.0 that starts crashing the game on your system?

In any case, I will try to reproduce the problem with this new information. I hope I will find something this time!

A general note: When reporting bugs, please use a setup that is as close as possible to a "vanilla" R'n'D installation. That is, ideally, a "from scratch" installation of the last release version of R'n'D, with an empty/default personal data directory ("Documents/Rocks'n'Diamonds" on Windows and Mac and "~/.rocksndiamonds" on Linux), which can easily be simulated by just temporarily renaming this directory to, say, "Documents/Rocks'n'Diamonds.temp", do the tests, and rename it back (after removing the newly created "Documents/Rocks'n'Diamonds"). This eliminates unexpected side effects like the "widescreen" custom graphics set in this case.
BryanFRitt
Posts: 219
Joined: Mon Nov 13, 2017 4:16 pm

Re: segmentation fault on start NIKO BOHM'S TUTORIAL levels

Post by BryanFRitt »

A general note: When reporting bugs, please use a setup that is as close as possible to a "vanilla" R'n'D installation.
Tried 4.3.1.0 with a fresh ~/.rocksndiamonds. Without 'WIDESCREEN MODE [1920x1080]' enabled things work fine, but with it, there's a segmentation fault when starting some levels.
Are you able to use "git bisect" to find the commit between 4.3.0.3 and 4.3.1.0 that starts crashing the game on your system?
git clone https://git.artsoft.org/rocksndiamonds.git
set up r'n'd to use 'WIDESCREEN MODE [1920x1080]'
download then move extracted folder to ~/.rocksndiamonds/graphics
MAIN MENU > SETUP > CUSTOM ARTWORK > CUSTOM GRAPHICS > ...
git bisect
git bisect bad
git bisect good 4.3.0.3
make clean
make --debug
test ./rockndiamonds
if ran without the issue
git bisect good
else
git bisect bad
If not done, go back to make clean
else select / copy results
(optional, if you'd like to start over, or whatever) git bisect reset, make clean, make --debug

results:
1e23125074b86c5eb1254037a81a3e9062152b7f is the first bad commit

commit 1e23125074b86c5eb1254037a81a3e9062152b7f
Author: Holger Schemel <info@artsoft.org>
Date: Sat Nov 27 00:03:17 2021 +0100

added basic support for additional empty space elements in game engine

:040000 040000 d7bf218bcc148225c6f4af26921b2933a14ec9f9 976aeb654d6ade19a018e4c2aaaeaf93009a4d10 M src
Life is partially trying to strike a balance between generating new things/ideas, and making sure they are good/organized. These extremes can be said to between gibberish mess and nothing said/done.
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: segmentation fault on start NIKO BOHM'S TUTORIAL levels

Post by Holger »

Thanks a lot for the bisecting! This additional information may be useful for tracking down this problem (although I really cannot see what problem this small commit could cause, but some bugs are not that obvious).

I also did some additional tests using the widescreen graphics set (with Niko Böhm's Tutorial level set), but did not encounter any crash so far.

Which version of the widescreen graphics set from the mentioned forum thread did you use? I can see at least four different variants (and tested with the first one):

- 1920x1080_by_rjkole.zip
- 1920x1080_by_rjkole_fix.zip
- 1920x1080_by_rjkole_fix_num_2.zip
- 1920x1080_by_rjkole_fix_num_3_with_level_preview.zip

You could also just zip and attach the variant you are using and which causes the crash for you (as some of the above variants are only delta changes to the previous variants).
BryanFRitt
Posts: 219
Joined: Mon Nov 13, 2017 4:16 pm

Re: segmentation fault on start NIKO BOHM'S TUTORIAL levels

Post by BryanFRitt »

Which version of the widescreen graphics set from the mentioned forum thread did you use?
It was this version:
1920x1080_by_rjkole_fix_num_3_with_level_preview.zip
download/file.php?id=853
tested with a fresh ~/.rocksndiamonds
Last edited by BryanFRitt on Mon Feb 07, 2022 2:56 am, edited 1 time in total.
Life is partially trying to strike a balance between generating new things/ideas, and making sure they are good/organized. These extremes can be said to between gibberish mess and nothing said/done.
BryanFRitt
Posts: 219
Joined: Mon Nov 13, 2017 4:16 pm

Re: segmentation fault on start NIKO BOHM'S TUTORIAL levels

Post by BryanFRitt »

I just tried other 'CUSTOM GRAPHICS', and the all the ones I tried seemed to work good except for ones based off of these 'WIDESCREEN MODE [1920x1080]' 'CUSTOM GRAPHICS'.
Life is partially trying to strike a balance between generating new things/ideas, and making sure they are good/organized. These extremes can be said to between gibberish mess and nothing said/done.
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: segmentation fault on start NIKO BOHM'S TUTORIAL levels

Post by Holger »

although I really cannot see what problem this small commit could cause, but some bugs are not that obvious
Wow, this is embarrassing. :oops: This problem (program crash) is not due to bad memory, but due to bad programmer -- here's the part of the small commit (thank's again for bisecting it, that helped a lot) that causes the crash:

Code: Select all

+  if (element == EL_EMPTY)
+    element = GfxElementEmpty[lx][ly];
+
   if (IN_LEV_FIELD(lx, ly))
   {
Once I've seen it, I could bang my head against a wall: The additional lines (marked with "+") of course have to go inside the following "if" block (to make sure that "lx" and "ly" are inside the level playfield). That's all. :shock:

The reason why it only happens to you when using that widescreen graphics set is just that it dramatically increases the number of invalid memory accesses on level start in comparison to using the default graphics (with smaller visible screen area). So it could also happen with the default graphics, but it is just a lot less likely.

A new patch release that fixes this painful bug (and a few others) is already on its way...!

Sorry for bothering you with this bug, and thanks a lot for reporting it! :)
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: segmentation fault on start NIKO BOHM'S TUTORIAL levels

Post by Holger »

BTW: It's interesting, that gdb displayed "DrawScreenElementExt (x=22, y=2, dx=0, dy=0, element=1515714624 ..." -- that means that the values of the function parameters are not those from the time of invocation of the function, but from the time of the crash! (I know, good programmers do not change function parameter variables, but ... see above! :cry:) Didn't know that! :o
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: segmentation fault on start NIKO BOHM'S TUTORIAL levels

Post by Holger »

New version 4.3.1.1 which should fix this crash bug just released! Please have a look if it works for you! :)
BryanFRitt
Posts: 219
Joined: Mon Nov 13, 2017 4:16 pm

Re: segmentation fault on start NIKO BOHM'S TUTORIAL levels

Post by BryanFRitt »

New version 4.3.1.1 which should fix this crash bug just released! Please have a look if it works for you!
It works! Thanks
Life is partially trying to strike a balance between generating new things/ideas, and making sure they are good/organized. These extremes can be said to between gibberish mess and nothing said/done.
filbo
Posts: 647
Joined: Fri Jun 20, 2014 10:06 am

Re: segmentation fault on start NIKO BOHM'S TUTORIAL levels

Post by filbo »

> not due to bad memory, but due to bad programmer

eh. Writing this sort of stuff in raw C is like juggling running chainsaws. You appear to still have all your limbs, you're doing great...
Post Reply