don't crash when attempting to configure a level with no sides

A similar assertion failure also exists in mp_create I believe.
It's a bit ugly to have to put this in src/game_initialization/
multiplayer.cpp, but probably the best thing if these classes
aren't going to be robust against corner cases like this.
This commit is contained in:
Chris Beck 2014-11-04 19:54:51 -05:00
parent e0c7bc5175
commit 75b61e6401
2 changed files with 23 additions and 6 deletions

View file

@ -6,15 +6,27 @@
#include <boost/foreach.hpp>
#include <cassert>
#include <sstream>
namespace ng {
static const config dummy;
configure_engine::configure_engine(saved_game& state) :
state_(state),
parameters_(state_.mp_settings()),
sides_(state_.get_starting_pos().child_range("side")),
cfg_((assert(sides_.first != sides_.second), *sides_.first))
cfg_(sides_.first != sides_.second ? *sides_.first : dummy) //second part is just any old config, it will be ignored
{
if (sides_.first == sides_.second) {
std::stringstream msg;
msg << "Configure Engine: No sides found in scenario, aborting.";
std::cerr << msg;
std::cerr << "Full scenario config:\n";
std::cerr << state_.to_config().debug();
throw game::error(msg.str());
}
set_use_map_settings(use_map_settings_default());
BOOST_FOREACH(const config& scenario,

View file

@ -594,11 +594,16 @@ static bool enter_configure_mode(game_display& disp, const config& game_config,
mp::ui::result res;
{
mp::configure ui(disp, game_config, gamechat, gamelist, state,
local_players_only);
run_lobby_loop(disp, ui);
res = ui.get_result();
ui.get_parameters();
if (!state.get_starting_pos().child("side")) {
gui2::show_error_message(disp.video(), "No sides found", "This map doesn't have any sides, you can't configure it, skipping...");
res = mp::ui::CREATE;
} else {
mp::configure ui(disp, game_config, gamechat, gamelist, state,
local_players_only);
run_lobby_loop(disp, ui);
res = ui.get_result();
ui.get_parameters();
}
}
switch (res) {