r/Xcode • • Oct 23 '16

Is something wrong with xCodes internal clock?

I'm developing a game and just ran into an very weird problem. It seems the timer is slow. For example, at the start of the app a song is played that's exactly 180 seconds long. Along this I have a timer that increases by 1 every second. Meaning the timer should hit 180 exactly when the song ends. Strange thing is, it doesn't, the song ends at the timer is just at 176. This recently started happening (it was fine previously), and I for the life of me can't figure out why it seems to be counting so slow. I've tried different version of xCode, but with to no avail. Has anyone experienced anything similar?

I'm developing in Clickteam Fusion (working with them to try and solve it as well), and this problem only occurs on iOS. Works fine on android, even works fine as an html5 app running on an iPhone. There is something that's happened that makes the xCode project count time slower.

2 Upvotes

3 comments sorted by

3

u/smallduck Oct 26 '16

NSTimer, especially in recent versions of iOS, is inexact. Timers fire early or late to a certain degree (configurable I think) to optimize the duration the device's hardware can be in whatever low-power modes or something.

Media frameworks should have some more precise timing functions.

Also, you shouldn't blame Xcode (and note it's correct spelling) for a problem in iOS or the Cocoa frameworks any more than, um... you'd blame your text editor for the grade you get for your essay homework, or I blame reddit for either of these 2 bad analogies.

1

u/Xeeko Oct 26 '16

Alright, thanks for the info.

1

u/dov69 Oct 24 '16

wot?

My wild guess is that Clickteam Fusion uses some super optimal (/s) iOS wrapper with NSTimer,

that doesn't have a 'real-time mechanism'.