#278 command line parameter crashes client

Latest Subversion
closed-works-for-me
nobody
Client (126)
8
2007-03-26
2007-01-15
Geoff Topping
No

From command prompt window in WinXP, starting FO with the command

freeorion --fullscreen

crashes the client. Part of the stack trace:

msvcr80.dll!strlen(unsigned char * buf=0x0012f7b0) Line 81 Asm
msvcp80.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::assign(const char * _Ptr=0x00000000) Line 1042 + 0xb bytes C++
msvcp80.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::basic_string<char,std::char_traits<char>,std::allocator<char> >(const char * _Ptr=0x00000000) Line 644 C++
> freeorion.exe!OptionsDB::SetFromCommandLine(int argc=2, char * * argv=0x015bb318) Line 310 C++
freeorion.exe!SDL_main(int argc=2, char * * argv=0x015bb318) Line 34 C++

Discussion

  • Logged In: NO

    linux:
    ./freeorion -f
    main() caught exception(std::exception): basic_string::_S_construct NULL not validUsage:
    --GameSetup.galaxy-age
    The shape of the galaxy to be generated. | Default: AGE_MATURE

    --GameSetup.galaxy-shape
    The shape of the galaxy to be generated. | Default: SPIRAL_3
    etc

     
  • guardian24
    guardian24
    2007-02-23

    Logged In: YES
    user_id=1536944
    Originator: NO

    Well, i guess it is this:
    Line 26 from chmain.cpp:
    GetOptionsDB().Add('f', "fullscreen", "OPTIONS_DB_FULLSCREEN", false);
    It COULD be:
    GetOptionsDB().AddFlag('f', "fullscreen", "OPTIONS_DB_FULLSCREEN");

    Of course, this would mean a different behaviour, as the game would
    start in windowed mode, when launched without command-line options?!
    (I have lost my will to compile FO on Windows. :(( )
    On the other hand, it could be a problem with the two Add-s, which are both
    template functions.
    Maybe line 26 in chmain.cpp is missing a template parameter, like:
    GetOptionsDB().Add<bool>('f', "fullscreen", "OPTIONS_DB_FULLSCREEN", false);
    (Or bool does need it? I have no clue. :o )

     
  • Geoff Topping
    Geoff Topping
    2007-02-23

    Logged In: YES
    user_id=913462
    Originator: YES

    Changing the line to AddFlag from Add does prevent the crash, but presumably would change the behaviour as noted, and I'm not really sure how the OptionsDB stuff works, so I'll leave it to tzlaine to actually change it...

    There are other examples of this problem as well, such as

    freeorion --UI.multiple-fleet-windows

    which is defined in ClientUI.cpp in the same manner as the fullscreen flag.

     
  • guardian24
    guardian24
    2007-03-04

    Logged In: YES
    user_id=1536944
    Originator: NO

    Its me again. Take a look at these lines from OptionsDB.cpp:

    303: Option& option = it->second;
    304: if (option.value.empty())
    305: throw std::runtime_error("The value member of option \"--" + option.name 306: + "\" is undefined.");

    If no value member is given, like "--fullscreen", then it->second will be a NULL reference.
    On WinXP, this quits with exactly that. Putting it into a try-catch block would reveal the problem, i guess.

     
  • guardian24
    guardian24
    2007-03-11

    Logged In: YES
    user_id=1536944
    Originator: NO

    I have just checked the SVN, and i saw that the OptionsDB.cpp is still the same.
    Was my suggestion checked, or do you think that this isnt the problem?

     
  • Geoff Topping
    Geoff Topping
    2007-03-11

    Logged In: YES
    user_id=913462
    Originator: YES

    It is not a NULL reference problem...

    Above the code you listed:

    std::map<std::string, Option>::iterator it = m_options.find(option_name);

    If there is an entry for the particular option flag passed in the map, then it->second will be it. There are no null references added to the map (and stepping through the code works fine up to and past this point).

    Also, I added

    std::cout << "CLOption: " << option.description << std::endl;

    after

    Option& option = it->second;

    and then got output:

    CLOption: OPTIONS_DB_UI_MULTIPLE_FLEET_WINDOWS

    The crash actually happens in this code:

    std::string value_str(argv[++i]);
    StripQuotation(value_str);
    option.FromString(value_str);

    because

    if (option.validator) { // non-flag

    is returning nonzero, which it shouldn't be for a flag (or so I gather from the code).

     
  • Geoff Topping
    Geoff Topping
    2007-03-11

    Logged In: YES
    user_id=913462
    Originator: YES

    The problem seems to be that UI.multiple-fleet-windows is not actually a flag. It actually expects a parameter value after: 1 or 0. When once isn't found, argv(++i) for the last flag is past the end of the array of (array of char).

    --fullscreen is a flag, so shouldn't have a parameter, so I'm not sure why it was crashing... However it's now not crashing for me.

     
  • Geoff Topping
    Geoff Topping
    2007-03-11

    • status: open --> pending-works-for-me
     
  • Geoff Topping
    Geoff Topping
    2007-03-11

    Logged In: YES
    user_id=913462
    Originator: YES

    I've comitted some code that hopefully gets rid of the crash and generates useful error messages when option flags are incorrectly specified.

    I'm not sureu why the original error, the fullscreen crash, was happening, but it's gone for me now.

    Let me know if this hasn't worked, or if there are other issues remaining.

     
  • Logged In: YES
    user_id=1312539
    Originator: NO

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 14 days (the time period specified by
    the administrator of this Tracker).

     
    • status: pending-works-for-me --> closed-works-for-me