News:

The Forum Rules and Guidelines
Our forum has Rules and Guidelines. Please, be kind and read them ;).

[Latest code as at 20 May] Possible network desync with forest tool

Started by jamespetts, May 19, 2014, 11:38:16 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jamespetts

During the efforts to track down the cause of the frequent network desyncs in Experimental, an issue  has been identified which also affects Standard, albeit that this is not the major cause of problems in current Experimental and is quite narrowly confined.

Line 196 of baum.cc contains (double precision) floating point code. This code is part of the create_forest function, which, depending on the pakset, can be used by players to create a wooded area without having to place individual trees manually, and could be used in network mode. As is well-known, the rounding of floating point values is not defined by the C++ standard, and may (and does) vary between platforms, so that a different result is obtained on an MSVS compiled binary compared to a GCC compiled binary (and probably a MinGW compiled binary comapred to a Linux GCC binary). This results in turn in different calls to the random number generator and a desync. This can only occur when a player uses the forest tool during an online game. This has been confirmed to cause desyncs in Experimental, and the result is likely to be the same in Standard, although this has not been tested.

One possible solution would be disabling the forest tool during online games, although, if this depends on the pakset authors, this might be a sub-optimal solution. I did look into trying to remove the floating point code myself, but the forest code is not entirely straightforward and I thought it best to leave that to those who understand the intention of the relevant line of code better than I do.

I hope that this is helpful.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

prissi

Yes, the solution is simple. Just use the integer sqrt function for uint. Changed in r7220. (I hope this works, since my linker is on the fizz after reinstalling windows. The stupid cvrest bug again.)

captain crunch

Quote from: prissi on May 21, 2014, 10:40:00 PM
Yes, the solution is simple. Just use the integer sqrt function for uint. Changed in r7220. (I hope this works, since my linker is on the fizz after reinstalling windows. The stupid cvrest bug again.)

===> CXX obj/baum.cc
obj/baum.cc: In static member function 'static void
baum_t::distribute_trees(int)':
obj/baum.cc:58:79: error: 'pow' was not declared in this scope
  unsigned   const t_forest_size  = (unsigned)pow(((double)x * (double)y), 0.25) * s.get_forest_base_size() / 11 + (x + y) / (2 * s.get_forest_map_size_divisor());


prissi

That is only called on map creation and should not be a problem. I just accidently deleted it. MSVC gets it pow() from stdlib, it seems. Tron put it already back.