Skip to content

Commit

Permalink
Handle empty specialists output cache gracefully
Browse files Browse the repository at this point in the history
Discovered while debugging the following behavior: Disallowing
specialists for a governor that already has assigned specialists
crashed the client.

The cause was that in `add_specialist_output` accessing items in
`pcsoutputs` failed, as it was empty.

Closes #2331.
  • Loading branch information
blabber committed Aug 1, 2024
1 parent f952681 commit 1eecc52
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions common/city.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2245,8 +2245,9 @@ void add_specialist_output(

output_type_iterate(stat_index)
{
int amount = pcsoutputs ? pcsoutputs->at(sp)[stat_index]
: get_specialist_output(pcity, sp, stat_index);
int amount = pcsoutputs && !pcsoutputs->empty()
? pcsoutputs->at(sp)[stat_index]
: get_specialist_output(pcity, sp, stat_index);

output[stat_index] += count * amount;
}
Expand Down

0 comments on commit 1eecc52

Please sign in to comment.