HaG@HaG

Discussion about Rocks'n'Diamonds, Boulder Dash, Supaplex, Emerald Mine and any other BD hybrid.

Moderators: Flumminator, Zomis

User avatar
Holger
Site Admin
Posts: 4071
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: HaG@HaG

Post by Holger »

The Boulder Dash level format stuff (loading native BD style files in BD, BDCFF and GAMEBD format) looks promising. I have compiled the modified game and was successfully able to load some of the included native BD levels!

However, I also got a crash (Segmentation fault) on level set "BDCFF":

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
strtok () at ../sysdeps/x86_64/strtok.S:190
190     ../sysdeps/x86_64/strtok.S: No such file or directory.
#0  strtok () at ../sysdeps/x86_64/strtok.S:190
#1  0x00000000004c3217 in rtryDbl (s=0x5ca285 "1", del=0x5c9de4 " \t", nochk=0, err=0) at filesBDCFF.c:211
#2  0x00000000004c706a in Load_BDCFFlevel (level=0x47f80c0, level_file_info=0x47f80c0) at filesBDCFF.c:1206
#3  0x00000000004c3031 in LoadLevelFromFileInfo_BD (level=0x47f80c0, level_file_info=0x47f80c0) at filesBD.c:1200
#4  0x00000000004b05ab in LoadLevelFromFileInfo (level=0x47f80c0, level_file_info=0x47f80c0, level_info_only=0) at files.c:6507
#5  0x00000000004b164e in LoadLevel_LoadAndInit (network_level=0x0) at files.c:7019
#6  0x00000000004b16e7 in LoadLevel (nr=1) at files.c:7043
#7  0x000000000042ffb3 in DrawMainMenu () at screens.c:1831
#8  0x00000000004116af in OpenAll () at init.c:6645
#9  0x0000000000404e0f in main (argc=1, argv=0x7fffffffd348) at main.c:7934
The function that crashes looks unsuspicious on first view; however, I have no clue what it is supposed to do (or what might be wrong with it; but propably the string pointer is invalid or something like that):

Code: Select all

static double rtryDbl(char *s, char *del, int nochk, int err)
{  
   char *tok = strtok(s, del);
   if ((tok!=NULL) && (nochk || !strEmpty(tok))) {
     return atof(tok);
   } else {
     if (err) {
       error = err;
     }
     return 0.0;
   }
}
Do you have an idea what might be the problem here?
HerzAusGold
Posts: 362
Joined: Sun Sep 25, 2005 4:41 pm
Location: Germany

Re: HaG@HaG

Post by HerzAusGold »

Hi,
this don't happen to me. (Windows11 - 64Bit)
Check if "bdcff.conf" exists and is in right format (Unix/Windows).
When does it happen? Starting RND and play BDCFF first? or after starting some other Levels?

Try my "rndTest-mingw.exe"

btw. BDCFF -> this levelset is original BD01 with 20*5 levels.
And the answer is ... 42 !
HerzAusGold
Posts: 362
Joined: Sun Sep 25, 2005 4:41 pm
Location: Germany

Re: HaG@HaG

Post by HerzAusGold »

Hm
rtrydbl only use here:
-> Load_BDCFFlevel

Code: Select all

    
    {   // test
        double d = rtry_dbl("1");
        error = d * 0;
    }
maybe for your compiler "1" is a "const char *" -> if it is I understand the seg.fault.

comment this four lines out.
rtrydbl -> never used .. maybe I already have trouble with it, so I write the test.
And the answer is ... 42 !
User avatar
Holger
Site Admin
Posts: 4071
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: HaG@HaG

Post by Holger »

Check if "bdcff.conf" exists and is in right format (Unix/Windows).
If a program crashes or not should not depend on the existence or correct format of a config file. :-D
When does it happen? Starting RND and play BDCFF first? or after starting some other Levels?
In both cases.
Try my "rndTest-mingw.exe"
No Windows system available here, unfortunately.
comment this four lines out.
rtrydbl -> never used .. maybe I already have trouble with it, so I write the test.
It works now! :-)
maybe for your compiler "1" is a "const char *" -> if it is I understand the seg.fault.
String literals are of type "const char *" only in C++ -- in C, they are "char *".

But the real cause of the problem is that writing to a string literal in C is undefined behaviour as defined in the C standard.

That is, both "works just fine" (as on your system) and "crashes the program" (as on mine) is a perfectly valid interpretation of "undefined behaviour" (and an instant crash is probably preferred in case of undefined behaviour than some harder to find error at some later stage, after the program was happily writing to a string literal for whatever reason).

Some more details can be found here:

"STR30-C. Do not attempt to modify string literals":
https://wiki.sei.cmu.edu/confluence/dis ... g+literals

So better don't do this, if you want your code to work on other systems than your own. ;-)
HerzAusGold
Posts: 362
Joined: Sun Sep 25, 2005 4:41 pm
Location: Germany

Re: HaG@HaG

Post by HerzAusGold »

Hi,
upload version 4.3.8.1 with source code again.
New Loaders for .WLC (original C64 file format (e.g. BD01) with Commands to draw the levels)
New Loaders for .WL2 (original C64 file format (e.g. BD02) with more Commands to draw the levels)
Loader for .OTO file (OneToOne file format, with many new elements)
OTO can be configured with the .BDCFF Config file (example included).

you can find it on http://www.arthurdent.de
-> rndTest-4.3.8.1-rc16 (release candidate, immediately playable) -> with the converted BoulderDashTosec levels.

and BD-reader with all the readers (with source code).
-> BD-reader (one solution) for all readers.
And the answer is ... 42 !
Post Reply