(PR#10567) Re: pubserver crash: ai-controlled unit has no goto destination

"Per I. Mathisen" <per-0/[email protected]>
Newsgroups gmane.games.freeciv.ai
Message-ID <[email protected]>
<URL: http://rt.freeciv.org/Ticket/Display.html?id=10567 >

Here is a patch to turn the assert into a freelog (hopefully).

  - Per
dipl2.diff (text/x-patch, 1.3 KB)
Index: ai/aidiplomat.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aidiplomat.c,v
retrieving revision 1.40
diff -u -r1.40 aidiplomat.c
--- ai/aidiplomat.c	29 Sep 2004 02:24:18 -0000	1.40
+++ ai/aidiplomat.c	18 Oct 2004 13:10:07 -0000
@@ -624,7 +624,7 @@
     } else if ((ctarget = ai_diplomat_defend(pplayer, punit,
                                              punit->type, map)) != NULL) {
       task = AIUNIT_DEFEND_HOME;
-      UNIT_LOG(LOG_DIPLOMAT, punit, "going defensive");
+      UNIT_LOG(LOG_DIPLOMAT, punit, "going to defend %s", ctarget->name);
     } else if ((ctarget = find_closest_owned_city(pplayer, punit->tile, 
 						  TRUE, NULL)) != NULL) {
       /* This should only happen if the entire continent was suddenly
@@ -639,10 +639,16 @@
     }
 
     ai_unit_new_role(punit, task, ctarget->tile);
+    assert(punit->moves_left > 0 && ctarget 
+           && punit->ai.ai_role != AIUNIT_NONE);
   }
 
   CHECK_UNIT(punit);
-  assert(punit->moves_left > 0 && ctarget && punit->ai.ai_role != AIUNIT_NONE);
+  if (ctarget == NULL) {
+    UNIT_LOG(LOG_ERROR, punit, "ctarget not set (role==%d)", punit->ai.ai_role);
+    pf_destroy_map(map);
+    return;
+  }
 
   /* GOTO unless we want to stay */
   if (!same_pos(punit->tile, ctarget->tile)) {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.