Complete.Org: Mailing Lists: Archives: freeciv-dev: September 1999:
Re: [Freeciv-Dev] et_government: Assertion `game.government_count > 0 &&
Home

Re: [Freeciv-Dev] et_government: Assertion `game.government_count > 0 &&

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: maage+freeciv@xxxxxxxxx
Cc: freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: Re: [Freeciv-Dev] et_government: Assertion `game.government_count > 0 && gov >= 0 && gov < game.government_count' failed. (PR#128)
From: David Pfitzner <dwp@xxxxxxxxxxxxxx>
Date: Sat, 18 Sep 1999 14:20:47 +1000 (EST)

maage+freeciv@xxxxxxxxx wrote:

> Full_Name: Markus Linnala
> Version: latest cvs
> OS: Linux 2.2

> How to reproduce:
> start server and client
> make all players ai, including the one at client
> start
> play one round
> quit server
> start server
> connect client
> say 'ai player'
> 
> Problem is that you set something that is not yet created in the client.

The following patch fixes this specific problem, but I'm
not sure if it is correct in general :-/

This is really part of a bigger problem, that when the client 
disconnects from the server it does not cleanly revert to
its state when just started (although in some ways it appears 
so).  Instead it leaves lots of data lying around without 
freeing or re-initializing is, and probably leaks quite a bit 
of memory when re-connects...

:-(

-- David
diff -u -r --exclude-from exclude freeciv-cvs/client/civclient.c 
freeciv-mod/client/civclient.c
--- freeciv-cvs/client/civclient.c      Sat Sep 18 12:02:20 1999
+++ freeciv-mod/client/civclient.c      Sat Sep 18 13:09:42 1999
@@ -29,6 +29,7 @@
 #include "capstr.h"
 #include "fcintl.h"
 #include "game.h"
+#include "government.h"
 #include "log.h"
 #include "map.h"
 #include "packets.h"
@@ -369,6 +370,7 @@
       update_unit_focus();
     }
     else if(client_state==CLIENT_PRE_GAME_STATE) {
+      free_governments();
       popdown_all_city_dialogs();
       game_remove_all_players();
       set_unit_focus_no_center(0);
diff -u -r --exclude-from exclude freeciv-cvs/client/packhand.c 
freeciv-mod/client/packhand.c
--- freeciv-cvs/client/packhand.c       Sat Sep 18 12:02:22 1999
+++ freeciv-mod/client/packhand.c       Sat Sep 18 13:11:03 1999
@@ -1006,10 +1006,7 @@
 {
   int i;
   
-  for(i=0; i<game.government_count; i++) {
-    free(get_government(i)->ruler_titles);
-  }
-  free(governments);
+  free_governments();
       
   game.aqueduct_size = packet->aqueduct_size;
   game.sewer_size = packet->sewer_size;
diff -u -r --exclude-from exclude freeciv-cvs/common/government.c 
freeciv-mod/common/government.c
--- freeciv-cvs/common/government.c     Wed Sep 15 20:18:33 1999
+++ freeciv-mod/common/government.c     Sat Sep 18 13:03:03 1999
@@ -263,3 +263,19 @@
 }
 
 
+/***************************************************************
+  Free all allocated governments data, and set
+  game.government_count to 0.  (May be called even if
+  game.government_count is already 0; then does nothing.)
+***************************************************************/
+void free_governments(void)
+{
+  int i;
+  
+  for(i=0; i<game.government_count; i++) {
+    free(get_government(i)->ruler_titles);
+  }
+  free(governments);
+  governments = NULL;
+  game.government_count = 0;
+}
diff -u -r --exclude-from exclude freeciv-cvs/common/government.h 
freeciv-mod/common/government.h
--- freeciv-cvs/common/government.h     Wed Sep 15 20:18:33 1999
+++ freeciv-mod/common/government.h     Sat Sep 18 12:57:46 1999
@@ -164,4 +164,6 @@
 
 int can_change_to_government(struct player *pplayer, int government);
 
+void free_governments(void);
+
 #endif  /* FC__GOVERNMENT_H */

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