I’m having the strangest problem, and I’m hoping someone can shed some light on the issue.
I’ve got a puzzle app, and the puzzles are timed. I’ve got a gameLoop function that increments the timer and does a few other background tasks. This function is called every second with timer.performWithDelay
:
local gameLoopTimer
-- Some time later
gameLoopTimer = timer.performWithDelay( 1000, gameLoop, 0 )
This has been bullet-proof. Works great, millions of play sessions, no problems. I’ve got a new app that uses the same code base, same timer. Also works great. Except…
On iOS the timer doesn’t always start correctly. It will fire the gameLoop function the first time, but then it hangs. Doesn’t increment the timer display, doesn’t perform the background tasks. If you pause and unpause the game, it will then “catch up”, rapidly running up the counter until it is where it should have been if it hadn’t been stuck and then work normally for the rest of the time, and report the correct time when the puzzle is finished. If you finish the puzzle without pausing and unpausing the game, it will report your final time as one second.
This only happens on iOS and only after a pre-roll ad. The ad provider doesn’t matter. This does not happen under the same circumstances on my other app. It is maddening.
If anyone has any insight into why this might be happening, I’d love to hear it. (Just to reiterate, the timer is not simply failing to start- it “knows” how far behind it is. If the timer is paused then unpaused, it will rush to catch up to where it should be.)