Skip to content

Commit

Permalink
Fix a crash for governors without specialists
Browse files Browse the repository at this point in the history
Governors that forbid specialists do not bother computing how much
specialists would produce and end up with an empty specialist output
cache. When applying solutions to evaluate them, however, we were trying
to use the cached values. Only do it when there specialists are actually
present in the solution.

See longturn#2332.
  • Loading branch information
lmoureaux committed Aug 30, 2024
1 parent c4e8953 commit f7a57b8
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions common/city.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2244,14 +2244,19 @@ void add_specialist_output(
{
int count = pcity->specialists[sp];

output_type_iterate(stat_index)
{
int amount = pcsoutputs ? pcsoutputs->at(sp)[stat_index]
: get_specialist_output(pcity, sp, stat_index);
// This is more than just an optimization. For governors that forbid
// specialists, the cache may not be filled.
if (count > 0) {
output_type_iterate(stat_index)
{
int amount = pcsoutputs
? pcsoutputs->at(sp)[stat_index]
: get_specialist_output(pcity, sp, stat_index);

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

0 comments on commit f7a57b8

Please sign in to comment.