Fixes the load game dialog crashing,

...that triggered an assert because of saves with another era than the
currently loaded (might need some more fixing, though, since the unit
images are not loaded yet).
This commit is contained in:
Jörg Hinrichs 2008-03-30 15:59:25 +00:00
parent 23b3e6dda3
commit ede8e6e41d
2 changed files with 10 additions and 4 deletions

View File

@ -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_);

View File

@ -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<const std::string,unit_type>("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()){