Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overflow on platform time-stamp #692

Closed
nsubiron opened this issue Aug 22, 2018 · 1 comment · Fixed by #915
Closed

Overflow on platform time-stamp #692

nsubiron opened this issue Aug 22, 2018 · 1 comment · Fixed by #915
Assignees
Labels
bug c++ Requires changing C++ code
Milestone

Comments

@nsubiron
Copy link
Collaborator

nsubiron commented Aug 22, 2018

The platform time-stamp is cast from double to int32 without any overflow checks.

The OS time seems to fit fine on Linux, that's why we didn't noticed before, but fails on Windows. Nevertheless, the code is wrong in both platforms.

The relevant code is in ACarlaPlayerState::UpdateTimeStamp().


As quick workaround until we fix this, you can apply the following patch to add an offset to prevent the overflow

--- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaPlayerState.cpp
+++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaPlayerState.cpp
@@ -77,8 +77,9 @@ static int32 RoundToMilliseconds(float Seconds)
 
 void ACarlaPlayerState::UpdateTimeStamp(float DeltaSeconds)
 {
+  static const auto offset = FPlatformTime::Seconds();
   FrameNumber = GFrameCounter;
   SimulationStepInSeconds = DeltaSeconds;
-  PlatformTimeStamp = RoundToMilliseconds(FPlatformTime::Seconds());
+  PlatformTimeStamp = RoundToMilliseconds(FPlatformTime::Seconds() - offset);
   GameTimeStamp += RoundToMilliseconds(DeltaSeconds);
 }
@nsubiron nsubiron added bug backlog c++ Requires changing C++ code labels Aug 22, 2018
@nsubiron nsubiron self-assigned this Aug 22, 2018
@nsubiron
Copy link
Collaborator Author

Interesting fact, Unreal on Windows adds a big number to the platform time-stamp precisely to find similar bugs

// add big number to make bugs apparent where return value is being passed to float
return Cycles.QuadPart * GetSecondsPerCycle() + 16777216.0;

@nsubiron nsubiron added this to the 0.9.1 milestone Oct 11, 2018
@ghost ghost removed the in progress label Oct 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug c++ Requires changing C++ code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant