Skip to content

Commit

Permalink
Fix crash at startup. (#40377)
Browse files Browse the repository at this point in the history
* Don't store the result of `options_manager::get_lang_options`

Instead of storing it in a public variable, just make the code that uses it (**two** places only) call the function directly.

This also gets rid of the initialization order bug (where the language path was set after the options had been loaded).

* Remove unnecessary class reference in type names.
  • Loading branch information
BevapDin authored May 9, 2020
1 parent 8759d05 commit d7abbf9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@ std::string game_info::game_report()

std::string lang = get_option<std::string>( "USE_LANG" );
std::string lang_translated;
for( const options_manager::id_and_option &vItem : options_manager::lang_options ) {
for( const options_manager::id_and_option &vItem : options_manager::get_lang_options() ) {
if( vItem.first == lang ) {
lang_translated = vItem.second.translated();
break;
Expand Down
11 changes: 4 additions & 7 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ bool tile_iso;
std::map<std::string, std::string> TILESETS; // All found tilesets: <name, tileset_dir>
std::map<std::string, std::string> SOUNDPACKS; // All found soundpacks: <name, soundpack_dir>

const std::vector<options_manager::id_and_option> options_manager::lang_options =
options_manager::get_lang_options();

options_manager &get_options()
{
static options_manager single_instance;
Expand Down Expand Up @@ -1035,7 +1032,7 @@ std::unordered_set<std::string> options_manager::get_langs_with_translation_file

std::vector<options_manager::id_and_option> options_manager::get_lang_options()
{
std::vector<options_manager::id_and_option> lang_options = {
std::vector<id_and_option> lang_options = {
{ "", translate_marker( "System language" ) },
// Note: language names are in their own language and are *not* translated at all.
// Note: Somewhere in Github PR was better link to msdn.microsoft.com with language names.
Expand All @@ -1055,9 +1052,9 @@ std::vector<options_manager::id_and_option> options_manager::get_lang_options()
{ "zh_TW", no_translation( R"(中文 (台灣))" ) },
};

std::unordered_set<std::string> lang_list = options_manager::get_langs_with_translation_files();
std::unordered_set<std::string> lang_list = get_langs_with_translation_files();

std::vector<options_manager::id_and_option> options;
std::vector<id_and_option> options;

lang_list.insert( "" ); // for System language option
lang_list.insert( "en" ); // for English option
Expand Down Expand Up @@ -1365,7 +1362,7 @@ void options_manager::add_options_interface()
};

add( "USE_LANG", "interface", translate_marker( "Language" ),
translate_marker( "Switch Language." ), options_manager::lang_options, "" );
translate_marker( "Switch Language." ), options_manager::get_lang_options(), "" );

add_empty_line();

Expand Down
3 changes: 1 addition & 2 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class options_manager
: std::pair<std::string, translation>( first, second ) {
}
};
static const std::vector<id_and_option> lang_options;
static std::vector<id_and_option> get_lang_options();
private:
static std::vector<id_and_option> build_tilesets_list();
static std::vector<id_and_option> build_soundpacks_list();
Expand All @@ -39,7 +39,6 @@ class options_manager
static std::vector<id_and_option> load_soundpack_from(
const std::string &path );
static std::unordered_set<std::string> get_langs_with_translation_files();
static std::vector<id_and_option> get_lang_options();

bool load_legacy();

Expand Down

0 comments on commit d7abbf9

Please sign in to comment.