Complete.Org: Mailing Lists: Archives: freeciv-ai: May 2005:
[freeciv-ai] Re: (PR#13156) auto_settler_findwork infinite recursion
Home

[freeciv-ai] Re: (PR#13156) auto_settler_findwork infinite recursion

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: bh@xxxxxxxxxxxxxxxxxxx
Subject: [freeciv-ai] Re: (PR#13156) auto_settler_findwork infinite recursion
From: "Marko Lindqvist" <marko.lindqvist@xxxxxxxxxxx>
Date: Sun, 22 May 2005 01:30:11 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13156 >

Benoit Hudson wrote:
> 
> I just had a segv caused by seemingly infinite recursion in 
> auto_settler_findwork (it overflowed the stack in a related 
> function, with a_s_f several thousand invocations deep).
> Sadly, I can't repro it from a savegame; it happens 
> consistently in a particular server-only game I'm running, 
> but it only hits around 1985 so it's kinda slow to test.

  Can you send that autogame? This is old bug I have been unable to 
reproduce. I have been using attached patch in my test environment in 
hope that I sometime catch it.


  - ML

diff -Nurd -X.diff_ignore freeciv/server/settlers.c freeciv/server/settlers.c
--- freeciv/server/settlers.c   2004-09-21 18:52:45.234375000 +0300
+++ freeciv/server/settlers.c   2004-09-21 21:46:02.265625000 +0300
@@ -46,6 +46,8 @@
 
 #include "settlers.h"
 
+#include "fcassert.h"
+
 BV_DEFINE(nearness, MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS);
 static nearness *territory;
 #define TERRITORY(map_x, map_y) territory[map_pos_to_index(map_x, map_y)]
@@ -1075,7 +1077,7 @@
   Find some work for our settlers and/or workers.
 **************************************************************************/
 #define LOG_SETTLER LOG_DEBUG
-static void auto_settler_findwork(struct player *pplayer, struct unit *punit)
+static void auto_settler_findwork(struct player *pplayer, struct unit *punit, 
int recursion)
 {
   struct cityresult result;
   int best_impr = 0;            /* best terrain improvement we can do */
@@ -1191,7 +1193,11 @@
   /*** Recurse if we want to found a city ***/
 
   if (punit->ai.ai_role == AIUNIT_BUILD_CITY) {
-    auto_settler_findwork(pplayer, punit);
+    if (recursion == 1) {
+      freelog(LOG_ERROR, "Recursive autosettler.");
+    }
+    fc_assert(recursion < 15);
+    auto_settler_findwork(pplayer, punit, recursion+1);
   }
 }
 #undef LOG_SETTLER
@@ -1313,7 +1319,7 @@
         handle_unit_activity_request(punit, ACTIVITY_IDLE);
       }
       if (punit->activity == ACTIVITY_IDLE) {
-        auto_settler_findwork(pplayer, punit);
+        auto_settler_findwork(pplayer, punit, 0);
       }
     }
   }

[Prev in Thread] Current Thread [Next in Thread]