← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1627767-SIGFPE into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1627767-SIGFPE into lp:widelands.

Commit message:
Fixed division by 0 in the AI.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1627767 in widelands: "SIGFPE: wrong player target not seen or not hostile"
  https://bugs.launchpad.net/widelands/+bug/1627767

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1627767-SIGFPE/+merge/306785

Scout's huts/houses have an empty list of output ware types. So, when a savegame is started and the AI gets assigned a formerly human player, the game can crash.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1627767-SIGFPE into lp:widelands.
=== modified file 'src/ai/defaultai.cc'
--- src/ai/defaultai.cc	2016-09-07 09:30:49 +0000
+++ src/ai/defaultai.cc	2016-09-26 17:50:07 +0000
@@ -4176,7 +4176,7 @@
 				return needed_type;
 			} else if (bo.total_count() == 0) {
 				return needed_type;
-			} else if (bo.current_stats > 10 + 70 / bo.outputs.size()) {
+			} else if (!bo.outputs.empty() && bo.current_stats > 10 + 70 / bo.outputs.size()) {
 				assert(bo.last_building_built != kNever);
 				if (gametime < bo.last_building_built + 10 * 60 * 1000) {
 					// Previous building built less then 10 minutes ago
@@ -4204,7 +4204,7 @@
 			return BuildingNecessity::kNeeded;
 		} else if (bo.max_preciousness >= 10 && bo.total_count() == 2) {
 			return BuildingNecessity::kNeeded;
-		} else if (bo.current_stats > (10 + 70 / bo.outputs.size()) / 2) {
+		} else if (!bo.outputs.empty() && bo.current_stats > (10 + 70 / bo.outputs.size()) / 2) {
 			return BuildingNecessity::kNeeded;
 		} else {
 			return BuildingNecessity::kNotNeeded;


Follow ups