diff --git a/src/game.cpp b/src/game.cpp index 6f3b46dc78d..859e8a1305a 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -464,7 +464,6 @@ bool game_controller::init_video() bool game_controller::init_config() { - unit_type_data::instance().clear(); //Resets old_defines_map_, to force refresh_game_cfg to reload //everything. old_defines_map_.clear(); @@ -1902,7 +1901,6 @@ void game_controller::refresh_game_cfg(bool reset_translations) if(old_defines_map_.empty() || defines_map_ != old_defines_map_ || reset_translations) { cursor::setter cur(cursor::WAIT); - unit_type_data::instance().clear(); if(!reset_translations) { game_config_.clear(); read_game_cfg(use_caching_); diff --git a/src/unit_types.cpp b/src/unit_types.cpp index 9e6277bb50d..afd8e71c76a 100644 --- a/src/unit_types.cpp +++ b/src/unit_types.cpp @@ -896,6 +896,8 @@ unit_type_data::unit_type_data() void unit_type_data::set_config(const config& cfg) { DBG_UT << "unit_type_data::set_config, cfg:\n" << cfg; + + clear(); unit_types.set_unit_config(cfg); unit_types.set_unit_traits(cfg.get_children("trait")); @@ -915,6 +917,9 @@ void unit_type_data::set_config(const config& cfg) increment_set_config_progress(); } + //Add dummy unit + unit_types.insert(std::pair("dummy_unit",unit_type())); + unsigned base_unit_count = 0; for(i = cfg.child_range("unit_type"); i.first != i.second; ++i.first) { @@ -1022,8 +1027,11 @@ unit_type_data::unit_type_map::const_iterator unit_type_data::unit_type_factory: unit_type_map::iterator itor = types_.find(key); lg::info(lg::config) << "trying to find " << key << " in unit_type list (unit_type_data.unit_types)\n"; - //This should not happen since it means the unit_type id has not been loaded - assert (itor != types_.end()); + + //This might happen if units of another era are requested (for example for savegames) + if (itor == types_.end()){ + return types_.find("dummy_unit"); + } //check if the unit_type is constructed and build it if necessary if (itor->second.id().empty()){