Question

I have an iPhone game using Unity game engine and self written library to access Apple's Core Motion framework. Performance is excellent on iPhone 5 and used to be pretty good on iPhone 4 in the past.

Running my app today on iPhone 4 (iOS 6.1.3) a continuous drop in frame rate occurs after a while (noticeable after 5-10 minutes). After about 20-30 minutes the game is almost unplayable and appears to run in slow motion.

The strange thing is: The effect occurs especially when the device is lying still on the table. When I move the device, frame rate rises noticeably but decreases again when there is no movement. I found out that the game code written in C# (Unity game engine) is not to blame for it but Obj-C part for handling motion control with Core Motion.

I think the problem began about the time when I updated from iOS 5.1.x to iOS 6.1.3 but I am not sure. It's hard to the exact time in revision history when the problem has started, because I did all longer tests on the fancy iPhone 5 and just quick tests on iPhone 4 (OK, lesson learned ;-).

I use the 'old style' pull approach to fetch CMDeviceMotion instances i.e. startDeviceMotionUpdates without block handler. The pulling code runs in a separate thread, which turned out to be the most perfomant way - Well, in the past.

Unity's built-in iOS profiler (console) doesn't show significant memory consumption, but I think native code plugin is not considered in statistics. Xcode profiler too didn't show any leaks as far as I can see it. Just a bulk of memory allocations and deallocs, which was a bit surprising to me (I think recycling CMDeviceMotion instances internally might be faster when polling, but who cares).


Question: Are there any known issues for this constellation on iOS 6? I mean, pulling, running in a separate thread, 60 Hz, combined with Unity game engine + Open GL ES 2, ...

Was it helpful?

Solution

Finally I found the culprit: deviceMotionUpdateInterval
To be more precise changing the interval pretty often.

According to section Choosing a Motion Event Update Interval in Event Handling Guide for iOS a larger interval improves battery life. So I implemented some logic to slow down the frequency to 2Hz when the game is not active i.e. game over, pausing, main menu, ... When resuming game play the frequency was set to 60 Hz again.

After commenting out the code for changing the frequency, the problem disappeared. So I decided to not longer try to save battery consumption this way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top