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

Jason Dorje Short wrote:
> There is a whole sequence of tickets devoted to this bug.  It is a
> well-known bug but no progress toward fixing it has been made in quite
> some time.  The problem is the sequence of random calls in the reload is
> different than it was before the continuation after the game was saved.
> 
I searched subjects for "random" and "seed" -- didn't find other reports,
or at least didn't seem on topic.  Could we make this the master ticket?
Like was done for gotos?


> Making a log of all random calls and comparing them could help point
> toward fixes.
> 
Locally, I added a LOG_VERBOSE call with line numbers; found one problem,
so far.  Could be LOG_DEBUG instead, should this be added to the source?

====

--- rand.h      Sun Feb 18 23:01:44 2007
+++ freeciv-2.1.0-beta4/utility/rand.h  Thu May 10 10:43:42 2007
@@ -26,7 +26,11 @@
    bool is_init;                        /* initially 0 for static storage */
  } RANDOM_STATE;

-RANDOM_TYPE myrand(RANDOM_TYPE size);
+#define myrand(vsize)      myrand_debug((vsize), "myrand", \
+                                        __LINE__, __FILE__)
+
+RANDOM_TYPE myrand_debug(RANDOM_TYPE size,
+                   const char *called_as, int line, const char *file);
  void mysrand(RANDOM_TYPE seed);

  bool myrand_is_init(void);
--- rand.c      Sun Feb 18 23:01:44 2007
+++ freeciv-2.1.0-beta4/utility/rand.c  Thu May 10 12:15:01 2007
@@ -77,13 +77,16 @@
    directly representable in type RANDOM_TYPE, so we do instead:
           divisor = MAX_UINT32/size
  *************************************************************************/
-RANDOM_TYPE myrand(RANDOM_TYPE size)
+RANDOM_TYPE myrand_debug(RANDOM_TYPE size,
+                    const char *called_as, int line, const char *file)
  {
    RANDOM_TYPE new_rand, divisor, max;
    int bailout = 0;

    assert(rand_state.is_init);
-
+  freelog(LOG_VERBOSE, "%s(%lu) at line %d of %s",
+           called_as, (unsigned long)size, line, file);
+
    if (size > 1) {
      divisor = MAX_UINT32 / size;
      max = size * divisor - 1;
@@ -108,7 +111,7 @@
      rand_state.v[rand_state.x] = new_rand;

      if (++bailout > 10000) {
-      freelog(LOG_ERROR, "Bailout in myrand(%u)", size);
+      freelog(LOG_ERROR, "Bailout in myrand(%lu)", (unsigned long)size);
        new_rand = 0;
        break;
      }
@@ -180,6 +183,7 @@
  void set_myrand_state(RANDOM_STATE state)
  {
    rand_state = state;
+  freelog(LOG_VERBOSE, "set_myrand_state");
  }

  /*************************************************************************



_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to