strange problem with commandline arguments

Started by handsource-dyko, October 20, 2010, 05:31:19 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

handsource-dyko

I'm currently fixing some bugs om malvado2010, and I've added a commandline switch that allows the user
to disable the demo movies on systems with low amounts of ram. The demo mode uses about 500mb of ram, whilst the
rest of the game stays below 20mb.

The commandline option works fine when typing malvado -d or malvado.exe -d , but bgdi freaks when I invoke the dcb
by typing bgdi malvado.dcb -d .

It's the seventh commandline argument, and all other switches do not cause bgdi to freak. I've already made sure that
I declared the arg[] count large enough (it was arg[7], now arg[8]).

The output bgdi gives when it freaks is something like: INSTANCE MAIN(65536) ENTRY StackBase=01410068 StackPTR=0141006C
After that, the game works, but the demo is choppy. This doesn't happen in malvado.exe mode. The source modification is straightforeward.

Anyone got some idea what's wrong here?

Code:

// check for fullscreen option on the commandline
   IF (argv[1]=="-f" OR argv[2]=="-f" OR argv[3]=="-f" OR argv[4]=="-f" OR argv[5]=="-f" OR argv[6]=="-f" OR argv[7]=="-f");
      full_screen=TRUE;
      scale_mode=SCALE_NORMAL2X; // in fullscreen, we scale by default, it can be
                                 // overruled by the other  scale options though.
   END
 
 
   // check if a scalemode is specified
   IF (argv[1]=="-scale:normal2x" OR argv[2]=="-scale:normal2x" OR argv[3]=="-scale:normal2x" OR argv[4]=="-scale:normal2x" OR argv[5]=="-scale:normal2x" OR argv[6]=="-scale:normal2x" OR argv[7]=="-scale:normal2x");
      scale_mode=SCALE_NORMAL2X; //default scale mode
   END
   
   IF (argv[1]=="-scale:2x" OR argv[2]=="-scale:2x" OR argv[3]=="-scale:2x" OR argv[4]=="-scale:2x" OR argv[5]=="-scale:2x" OR argv[6]=="-scale:2x" OR argv[7]=="-scale:2x");
      scale_mode=SCALE_SCALE2X;
   END
   
   IF (argv[1]=="-scale:hq2x" OR argv[2]=="-scale:hq2x" OR argv[3]=="-scale:hq2x" OR argv[4]=="-scale:hq2x" OR argv[5]=="-scale:hq2x" OR argv[6]=="-scale:hq2x" OR argv[7]=="-scale:hq2x");
      scale_mode=SCALE_HQ2X;
   END
   
   IF (argv[1]=="-scale:scanline2x" OR argv[2]=="-scale:scanline2x" OR argv[3]=="-scale:scanline2x" OR argv[4]=="-scale:scanline2x" OR argv[5]=="-scale:scanline2x" OR argv[6]=="-scale:scanline2x" OR argv[7]=="-scale:scanline2x");
      scale_mode=SCALE_SCANLINE2X;
   END

   
   // check if sound effects are disabled
   IF (argv[1]=="-nosfx" OR argv[2]=="-nosfx" OR argv[3]=="-nosfx" OR argv[4]=="-nosfx" OR argv[5]=="-nosfx" OR argv[6]=="-nosfx" OR argv[7]=="-nosfx")
      nosfx=TRUE;
   END
       
   // check if background music is disabled
   IF (argv[1]=="-nomusic" OR argv[2]=="-nomusic" OR argv[3]=="-nomusic" OR argv[4]=="-nomusic" OR argv[5]=="-nomusic" OR argv[6]=="-nomusic" OR argv[7]=="-nomusic")
      nomusic=TRUE;
   END   
   
   // check if a custom level is specified (test mode for level editor)
   IF (argv[1]=="-test" OR argv[2]=="-test" OR argv[3]=="-test" OR argv[4]=="-test" OR argv[5]=="-test" OR argv[6]=="-test" OR argv[7]=="-test")
   
      // we now have cheats and can save level map files
      devmode=TRUE;
     
      // get the filename from the "EDITOR.TST" file
      IF (file_exists("editor.tst"))
         testlevelfile=fopen("editor.tst",O_READ);
         testlevelfilename=fgets(testlevelfile);
         fclose(testlevelfile);         
         
         say("");
         say("");
         say("loading testlevel: "+testlevelfilename);
         
         // when the filename in the "EDITOR.TST" file is incorrect, load the default level 1.
         IF (NOT file_exists(testlevelfilename))         
            say("");
            say("");
            say("filename specified in editor.tst does not exist, will use level 1.");
            testlevelfilename="lev\level1.lev"; 
         END
         
      ELSE
         // when the file "EDITOR.TST" does not exitst, load the default level 1.
         say("");
         say("");
         say("editor.tst not found, will start from level 1, DEVMODE disabled.");
         testlevelfilename="lev\level1.lev"; 
         devmode=FALSE;         
      END           
   END
   
   // check if the user wants to select a different joystick device then the default one, and allows to
   // choose a firebutton.
   IF (argv[1]=="-j" OR argv[2]=="-j" OR argv[3]=="-j" OR argv[4]=="-j" OR argv[5]=="-j" OR argv[6]=="-j" OR argv[7]=="-j")
   
      // function for selecting a different joystick and defining the buttons.
      joy_mapping();
   END
   
   // check if the attractmode (demo) is disabled
   IF (argv[1]=="-d" OR argv[2]=="-d" OR argv[3]=="-d" OR argv[4]=="-d" OR argv[5]=="-d" OR argv[6]=="-d" OR argv[7]=="-d")
      attractmode=ENABLED;
   END


Windgate

Can't help you, I have used argc and argv with C but not with Bennu...

I have never seen that error before :o
Iván García Subero. Programador, profesor de informática, monitor de actividades culturales y presidente de TRINIT Asociación de Informáticos de Zaragoza. http://trinit.es

SplinterGU

Download Lastest BennuGD Release: http://www.bennugd.org/node/2

DCelso

#3
yeah, splinterGU responsed It while Im doing it to.
You can not access to argv[2] at least that you have 2 or more arguments in your execution command.
For example if you put "bgdi main.dcb -r -a" you will have 2 argumens and you can access to the argv[2].
But if you put "bgdi main.dcb -r" you cannot acces to argv[2] because it isnot and you program would be crash.
You must check the number or arguments (with argc) before that you access to a position for evade the problems.
For example
if (argc >2)
  say (argv[2])
end

more info:
http://wiki.bennugd.org/index.php?title=Argv
Monstruos Diabólicos

"A PAck of classic GAMEs For BennuGD" en desarrollo
http://code.google.com/p/apagame4be/

handsource-dyko

Strange, it still sort of works.
In my program the position of the arguments don't matter.
It only goes bad in bgdi mode, but before i've added this extra argument
switch I never had this error before. I have really no clue why.

My program doesn't check for the amount of argements, it just checks if there
are any valid argument's and executes them. Incorrect or non-existing arguments
are automatically ignored by my program.

handsource-dyko

I solved it.
I was stupid, I shouldn't have used "-d", because it's a parameter the bgdi already uses.
This is why "-demo" doesn't work either,because of the first two characters.

I now changed it to "-a" and now bgdi doesn't freak anymore. Maybe the first character of
a commandline argument matters more then the whole string.