From f6eba87e47e77c01ecd75981a14c53e11c2c1ddc Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Mon, 15 Dec 2025 16:42:10 +0000 Subject: [PATCH] Fix #14915: Crash due to divide-by-zero of industry probabilities. (#14918) --- src/industry_cmd.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index a6cce42fc2..22bad9aad1 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -2474,7 +2474,7 @@ static IndustryGenerationProbabilities GetScaledProbabilities(bool water) for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) { p.probs[it] = GetScaledIndustryGenerationProbability(it, water, &p.force_one[it]); - p.total += p.probs[it];; + p.total += p.probs[it]; if (p.force_one[it]) p.num_forced++; } @@ -2499,7 +2499,8 @@ void GenerateIndustries() auto &p = water ? wprob : lprob; /* Total number of industries scaled by land/water proportion. */ - uint total_amount = p.total * GetNumberOfIndustries() / (lprob.total + wprob.total); + uint total_amount = 0; + if (lprob.total + wprob.total > 0) total_amount = p.total * GetNumberOfIndustries() / (lprob.total + wprob.total); /* Scale land-based industries to the land proportion, unless the player has set a custom industry count. */ if (!water && _settings_game.difficulty.industry_density != ID_CUSTOM) total_amount = Map::ScaleByLandProportion(total_amount);