Skip to content

Commit

Permalink
Don't exit to desktop if using debug unit command with invalid type n…
Browse files Browse the repository at this point in the history
…ame (FR #25619)
  • Loading branch information
Vultraz committed Apr 14, 2017
1 parent 1310dc6 commit 8a1263c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/synced_commands.cpp
Expand Up @@ -435,10 +435,20 @@ SYNCED_COMMAND_HANDLER_FUNCTION(debug_unit, child, use_undo, /*show*/, /*error_
} else {
config cfg;
i->write(cfg);
resources::gameboard->units().erase(loc);
cfg[name] = value;
unit new_u(cfg, true);
resources::gameboard->units().add(loc, new_u);

// Attempt to create a new unit. If there are error (such an invalid type key), exit.
try{
unit new_u(cfg, true);

// Don't remove the unit until after we've verified there are no errors in creating the new one,
// or else the unit would simply be removed from the map with no replacement.
resources::gameboard->units().erase(loc);
resources::gameboard->units().add(loc, new_u);
} catch(unit_type::error& e) {
ERR_REPLAY << e.what() << std::endl; // TODO: more appropriate error message log
return false;
}
}
if (name == "fail") { //testcase for bug #18488
assert(i.valid());
Expand Down Expand Up @@ -508,7 +518,7 @@ SYNCED_COMMAND_HANDLER_FUNCTION(debug_kill, child, use_undo, /*show*/, /*error_h
resources::undo_stack->clear();
}
debug_notification("kill debug command was used during turn of $player");

const map_location loc(child["x"].to_int(), child["y"].to_int(), wml_loc());
const unit_map::iterator i = resources::gameboard->units().find(loc);
if (i != resources::gameboard->units().end()) {
Expand Down

1 comment on commit 8a1263c

@Vultraz
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit message is supposed to say titlescreen not desktop...sorry :(

Please sign in to comment.