Sign in to follow this  

Reproducible behavior and float precision

This topic is 4098 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I'm trying to make a determinist scene based on user inputs, I'm using a fixed time game loop and I will implement a lockstep network model too. The problem is with float calculations. When I launch the game twice using the same stream user input I obtain different results at the end of timeline, dinamic objects positions are slightly different. How can I fix it? I try to use _controlfp_s win32 function but doesn't work. Thanks.

Share this post


Link to post
Share on other sites
Is it the same hardware (or an exact duplicate)? If there's some sort of timing issue or rounding issue it may cause this.

My suggestion would be to try an isolate the problem a bit more. Try outputting position and orientation data for both simulations into a log and then compare the outputs. See if there is one particular type of input that creates the difference and then consider how those calculations are made.

Without knowing more about how things are computed and their inputs it would be difficult to guess..


Hope that helps.

Share this post


Link to post
Share on other sites
Thanks for help me.
The hardware is the same, is my local machine. The time is fixed (15Ms).
I did put the results on a log and I saw the differences.
The calculations are adds, subs and dot products vectors. Inside the main loop, between readInput and doLogic calls are not other external calls made (OpenGL, Filesystem, etc.).

Share this post


Link to post
Share on other sites
I was working on this issue lately - with full success.
My goal was to be able to roll back a few frames to look on the in-game situation from different angles, for debugging purposes. And also exact prediction of future states for AI/physics interaction.

About your problem:
1. Is the simulation using always the same code path? I guess that it isn't, since if it were, there would be no reason for the end results to be different each time.
2. If you're using Visual Studio, there's a cool new option available for controlling floating numbers behaviour. I really recommend this article explaining in detail usage of /fp switch (Specify Floating-Point Behavior).

So you either use option 1. or - make the codepaths alike, ensuring that different code chunks are compiled similarly and are producing exact same results for same inputs (using /fp:precise switch).

Other than that, for debugging, I was simply checking my variables for equality with the ones from the previous run in a few strategic places, and fired a breakpoint whenever they differed - thus narrowing any problems quite quickly.

Share this post


Link to post
Share on other sites
I use /fp:precise switch in VS config.
I think that the execution path is the same, fails here or not initialized var. perhaps.
I will check these questions.
Thanks to all!

Share this post


Link to post
Share on other sites

This topic is 4098 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this