While testing the game I’m working on, I came across a strange error. Sometimes, every 10-20 minutes, the game freezes for a moment. First, I noticed that the engine shows many debug lines:
Time: Detected gettimeofday() going backwards on Unix, workarounding. This is known to happen on some Android devices
So I limited the debug to one line, that significantly reduced downtime, but it still occurred. Like Michalis, I assumed it was a defect in my phone. But I was wondering why other games run smoothly.
Clocks on Android
After a short investigation, it turned out that time on Android can be obtained in several ways. The default clock, called the “wall” clock, synchronizes with the network quite often what can cause forward and backward jumps. This clock is used by the function
fpgettimeofday(), which was used by CGE and the Kraft physics engine.
A monotonic clock on Android
To use a clock that guarantees monotonic continuity, use the
clock_gettime(CLOCK_MONOTONIC) function from the
Linux module. After making these changes, the game began to work perfectly without any temporary freezing.
Castle Game Engine and Kraft fixes
If you’re planning to create a game for Android, remember that in Castle Game Engine the problem was resolved on August 18, 2019.
The Kraft was repaired on August 21, 2019, in official repository.