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

[freeciv-ai] (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] (PR#13156) auto_settler_findwork infinite recursion
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 11 Jun 2005 17:28:21 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This looks like a bug in the new "displacement" code causing a recursive
displacement (which is supposed to be impossible of course).

This is with CVS from "Sun Jun 12 00:26:39 UTC 2005", the attached log
patch, plus a fix for loading-games bug, and with the savegame
previously attached to this ticket.

(gdb) bt
#0  0x400b583b in raise () from /lib/tls/libc.so.6
#1  0x400b6fa2 in abort () from /lib/tls/libc.so.6
#2  0x400af2df in __assert_fail () from /lib/tls/libc.so.6
#3  0x080a1a99 in auto_settler_findwork (pplayer=0x81fe1c0, punit=0x854bf88,
    state=0xbfff7844, recursion=15) at settlers.c:1043
#4  0x080a1ddb in auto_settler_findwork (pplayer=0x81fe1c0, punit=0x8548838,
    state=0xbfff7844, recursion=14) at settlers.c:1108
#5  0x080a1ddb in auto_settler_findwork (pplayer=0x81fe1c0, punit=0x854bf88,
    state=0xbfff7844, recursion=13) at settlers.c:1108
#6  0x080a1ddb in auto_settler_findwork (pplayer=0x81fe1c0, punit=0x8548838,
    state=0xbfff7844, recursion=12) at settlers.c:1108
#7  0x080a1ddb in auto_settler_findwork (pplayer=0x81fe1c0, punit=0x854bf88,
    state=0xbfff7844, recursion=11) at settlers.c:1108
#8  0x080a1ddb in auto_settler_findwork (pplayer=0x81fe1c0, punit=0x8548838,
    state=0xbfff7844, recursion=10) at settlers.c:1108
#9  0x080a1ddb in auto_settler_findwork (pplayer=0x81fe1c0, punit=0x854bf88,
    state=0xbfff7844, recursion=9) at settlers.c:1108
#10 0x080a1ddb in auto_settler_findwork (pplayer=0x81fe1c0, punit=0x8548838,
    state=0xbfff7844, recursion=8) at settlers.c:1108
#11 0x080a1ddb in auto_settler_findwork (pplayer=0x81fe1c0, punit=0x854bf88,
    state=0xbfff7844, recursion=7) at settlers.c:1108
#12 0x080a1ddb in auto_settler_findwork (pplayer=0x81fe1c0, punit=0x8548838,
    state=0xbfff7844, recursion=6) at settlers.c:1108
#13 0x080a1ddb in auto_settler_findwork (pplayer=0x81fe1c0, punit=0x854bf88,
    state=0xbfff7844, recursion=5) at settlers.c:1108
#14 0x080a1ddb in auto_settler_findwork (pplayer=0x81fe1c0, punit=0x8548838,
    state=0xbfff7844, recursion=4) at settlers.c:1108
#15 0x080a1ddb in auto_settler_findwork (pplayer=0x81fe1c0, punit=0x854bf88,
    state=0xbfff7844, recursion=3) at settlers.c:1108
#16 0x080a1ddb in auto_settler_findwork (pplayer=0x81fe1c0, punit=0x8548838,
    state=0xbfff7844, recursion=2) at settlers.c:1108
#17 0x080a1ddb in auto_settler_findwork (pplayer=0x81fe1c0, punit=0x854bf88,
    state=0xbfff7844, recursion=1) at settlers.c:1108
#18 0x080a1ddb in auto_settler_findwork (pplayer=0x81fe1c0, punit=0x854c650,
    state=0xbfff7844, recursion=0) at settlers.c:1108
#19 0x080a25e0 in auto_settlers_player (pplayer=0x81fe1c0) at
settlers.c:1267
#20 0x0805080d in end_phase () at srv_main.c:625
#21 0x080526d9 in main_loop () at srv_main.c:1695
#22 0x08052e35 in srv_loop () at srv_main.c:1956
#23 0x080528f1 in srv_main () at srv_main.c:1773
#24 0x0804ae45 in main (argc=8, argv=0xbffff874) at civserver.c:242

Index: server/settlers.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v
retrieving revision 1.239
diff -u -r1.239 settlers.c
--- server/settlers.c   7 Jun 2005 16:55:00 -0000       1.239
+++ server/settlers.c   12 Jun 2005 00:26:21 -0000
@@ -977,7 +977,8 @@
 #define LOG_SETTLER LOG_DEBUG
 static void auto_settler_findwork(struct player *pplayer, 
                                  struct unit *punit,
-                                 struct settlermap *state)
+                                 struct settlermap *state,
+                                 int recursion)
 {
   struct cityresult result;
   int best_impr = 0;            /* best terrain improvement we can do */
@@ -988,6 +989,12 @@
   /* time it will take worker to complete its given task */
   int completion_time = 0;
 
+
+  if (recursion == 1) {
+    freelog(LOG_ERROR, "Recursive autosettler.");
+  }
+  assert(recursion < 15);
+
   CHECK_UNIT(punit);
 
   result.total = 0;
@@ -1098,7 +1105,7 @@
       
       if (displaced) {
        displaced->goto_tile = NULL;
-       auto_settler_findwork(pplayer, displaced, state);
+       auto_settler_findwork(pplayer, displaced, state, recursion + 1);
       }
     } else {
       UNIT_LOG(LOG_DEBUG, punit, "giving up trying to improve terrain");
@@ -1120,7 +1127,7 @@
 
   if (punit->ai.ai_role == AIUNIT_BUILD_CITY
       && punit->moves_left > 0) {
-    auto_settler_findwork(pplayer, punit, state);
+    auto_settler_findwork(pplayer, punit, state, recursion + 1);
   }
 }
 #undef LOG_SETTLER
@@ -1257,7 +1264,7 @@
         handle_unit_activity_request(punit, ACTIVITY_IDLE);
       }
       if (punit->activity == ACTIVITY_IDLE) {
-        auto_settler_findwork(pplayer, punit, state);
+        auto_settler_findwork(pplayer, punit, state, 0);
       }
     }
   } unit_list_iterate_end;

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