Strange Behavior after Suspending and Resuming Game

Hey guys,

I’m having a strange problem with Unity where suspending the application and then resuming it on Android devices causes the game to act strangely (such as missing touches, extremely slow performance). Sometimes the game crashes during the resume process, sometimes it just sits at a black screen for a long period of time. But if the game ever resumes it is very unresponsive.

This is using Unity 3.4 on the Nexus One. Here is the logcat information I’m receiving when this happens:

D/FlurryAgent( 1412): startSession called
D/FlurryAgent( 1412): Initializing Flurry session
D/FlurryAgent( 1412): Starting new session
D/FlurryAgent( 1412): Sending report to: http://data.flurry.com/aap.do
D/dalvikvm( 1412): GC_FOR_MALLOC freed 680K, 48% free 3546K/6727K, external 1629K/2137K, paused 48ms
D/FlurryAgent( 1412): Report successful
D/FlurryAgent( 1412): Processing report response
D/FlurryAgent( 1412): Done sending initial agent report
D/dalvikvm(   96): GC_CONCURRENT freed 1988K, 44% free 5909K/10439K, external 2020K/2137K, paused 23ms+6ms
I/ActivityManager(   96): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher } from pid 96
D/Unity   ( 1412): NativeActivity save instance state: 0x2b4f08
D/Unity   ( 1412): NativeActivity pause: 0x2b4f08
D/FlurryAgent( 1412): Ending session
V/RenderScript_jni(  192): surfaceCreated
V/RenderScript_jni(  192): surfaceChanged
D/Unity   ( 1412): NativeActivity window focus changed: 0x2b4f08 -- 0
D/Unity   ( 1412): NativeActivity stop: 0x2b4f08

(this is where I had suspended the app)

I/ActivityManager(   96): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.HiddenVariable.BagIt/com.unity3d.player.UnityPlayerProxyActivity } from pid 192
D/Unity   ( 1412): NativeActivity start: 0x2b4f08
D/Unity   ( 1412): NativeActivity resume: 0x2b4f08
E/libEGL  ( 1412): call to OpenGL ES API with no current context (logged once per thread)
D/FlurryAgent( 1412): startSession called
D/FlurryAgent( 1412): Initializing Flurry session
D/FlurryAgent( 1412): Continuing previous session
D/Unity   ( 1412): Creating OpenGL ES 1.x context (RGB16 565 16/0)
W/AudioFlinger(   68): write blocked for 166 msecs, 17 delayed writes, thread 0xea00
V/RenderScript_jni(  192): surfaceDestroyed
W/ActivityManager(   96): Launch timeout has expired, giving up wake lock!
W/ActivityManager(   96): Activity idle timeout for HistoryRecord{40745378 com.HiddenVariable.BagIt/com.unity3d.player.UnityPlayerNativeActivity}
I/InputDispatcher(   96): Application is not responding: AppWindowToken{409286f0 token=HistoryRecord{40745378 com.HiddenVariable.BagIt/com.unity3d.player.UnityPlayerNativeActivity}}.  5005.5ms since event, 5005.3ms since wait started
I/WindowManager(   96): Input event dispatching timed out sending to application AppWindowToken{409286f0 token=HistoryRecord{40745378 com.HiddenVariable.BagIt/com.unity3d.player.UnityPlayerNativeActivity}}
I/Process (   96): Sending signal. PID: 1412 SIG: 3
I/dalvikvm( 1412): threadid=4: reacting to signal 3
I/dalvikvm( 1412): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   96): Sending signal. PID: 96 SIG: 3
I/dalvikvm(   96): threadid=4: reacting to signal 3
I/dalvikvm(   96): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   96): Sending signal. PID: 180 SIG: 3
I/dalvikvm(  180): threadid=4: reacting to signal 3
I/dalvikvm(  180): Wrote stack traces to '/data/anr/traces.txt'
I/Process (   96): Sending signal. PID: 155 SIG: 3
I/dalvikvm(  155): threadid=4: reacting to signal 3
I/dalvikvm(  155): Wrote stack traces to '/data/anr/traces.txt'
D/dalvikvm(   96): GC_EXPLICIT freed 594K, 42% free 6093K/10439K, external 1625K/2137K, paused 81ms
D/Unity   ( 1412): NativeActivity window focus changed: 0x2b4f08 -- 1
E/ActivityManager(   96): ANR in com.HiddenVariable.BagIt (com.HiddenVariable.BagIt/com.unity3d.player.UnityPlayerNativeActivity)
E/ActivityManager(   96): Reason: keyDispatchingTimedOut
E/ActivityManager(   96): Load: 3.15 / 4.66 / 5.15
E/ActivityManager(   96): CPU usage from 14895ms to 0ms ago:
E/ActivityManager(   96):   13% 1412/com.HiddenVariable.BagIt: 11% user + 1.5% kernel / faults: 1065 minor
E/ActivityManager(   96):   6.7% 73/akmd: 0% user + 6.7% kernel
E/ActivityManager(   96):   2.6% 68/mediaserver: 1.3% user + 1.2% kernel
E/ActivityManager(   96):   2.2% 96/system_server: 1.1% user + 1.1% kernel / faults: 14 minor
E/ActivityManager(   96):   0.4% 5/events/0: 0% user + 0.4% kernel
E/ActivityManager(   96):   0.1% 155/com.android.systemui: 0% user + 0% kernel
E/ActivityManager(   96):   0% 51/kondemand/0: 0% user + 0% kernel
E/ActivityManager(   96):   0% 62/servicemanager: 0% user + 0% kernel
E/ActivityManager(   96):   0% 180/com.android.phone: 0% user + 0% kernel / faults: 1 minor
E/ActivityManager(   96):   0% 209/dhd_dpc: 0% user + 0% kernel
E/ActivityManager(   96):   0% 234/wpa_supplicant: 0% user + 0% kernel
E/ActivityManager(   96): 16% TOTAL: 10% user + 5.5% kernel + 0% softirq
E/ActivityManager(   96): CPU usage from 412ms to 933ms later:
E/ActivityManager(   96):   41% 96/system_server: 22% user + 18% kernel / faults: 21 minor
E/ActivityManager(   96):     11% 103/SurfaceFlinger: 3.7% user + 7.5% kernel
E/ActivityManager(   96):     9.4% 129/WindowManager: 9.4% user + 0% kernel
E/ActivityManager(   96):     3.7% 131/InputDispatcher: 0% user + 3.7% kernel
E/ActivityManager(   96):     1.8% 96/system_server: 0% user + 1.8% kernel
E/ActivityManager(   96):     1.8% 102/Binder Thread #: 1.8% user + 0% kernel
E/ActivityManager(   96):     1.8% 107/GL updater: 0% user + 1.8% kernel
E/ActivityManager(   96):     1.8% 189/Binder Thread #: 1.8% user + 0% kernel
E/ActivityManager(   96):     1.8% 191/Binder Thread #: 1.8% user + 0% kernel
E/ActivityManager(   96):     1.8% 201/Binder Thread #: 1.8% user + 0% kernel
E/ActivityManager(   96):     1.8% 276/Binder Thread #: 0% user + 1.8% kernel
E/ActivityManager(   96):     1.8% 277/Binder Thread #: 0% user + 1.8% kernel
E/ActivityManager(   96):     1.8% 1041/Binder Thread #: 1.8% user + 0% kernel
E/ActivityManager(   96):     1.8% 1279/Binder Thread #: 1.8% user + 0% kernel
E/ActivityManager(   96):   23% 1412/com.HiddenVariable.BagIt: 12% user + 10% kernel / faults: 396 minor
E/ActivityManager(   96):     14% 1412/nVariable.BagIt: 5.3% user + 8.9% kernel
E/ActivityManager(   96):     5.3% 1433/Thread-20: 5.3% user + 0% kernel
E/ActivityManager(   96):     1.7% 1418/Binder Thread #: 1.7% user + 0% kernel
E/ActivityManager(   96):     1.7% 1423/er$SensorThread: 1.7% user + 0% kernel
E/ActivityManager(   96):     1.7% 1434/AudioTrackThrea: 1.7% user + 0% kernel
E/ActivityManager(   96):   5.6% 73/akmd: 0% user + 5.6% kernel
E/ActivityManager(   96):     7.5% 1325/akmd: 0% user + 7.5% kernel
E/ActivityManager(   96):   1.3% 68/mediaserver: 0% user + 1.3% kernel
E/ActivityManager(   96):     1.3% 94/Playback Thread: 0% user + 1.3% kernel
E/ActivityManager(   96):   1.3% 155/com.android.systemui: 0% user + 1.3% kernel
E/ActivityManager(   96):     1.3% 155/ndroid.systemui: 1.3% user + 0% kernel
E/ActivityManager(   96):     1.3% 163/Binder Thread #: 1.3% user + 0% kernel
E/ActivityManager(   96):   1.3% 209/dhd_dpc: 0% user + 1.3% kernel
E/ActivityManager(   96): 71% TOTAL: 36% user + 34% kernel
D/Unity   ( 1412): NativeActivity window focus changed: 0x2b4f08 -- 0
D/Unity   ( 1412): NativeActivity window focus changed: 0x2b4f08 -- 1
W/InputManagerService(   96): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4063a680
I/wpa_supplicant(  234): CTRL-EVENT-STATE-CHANGE id=0 state=6 BSSID=00:00:00:00:00:00
V/WifiMonitor(   96): Event [CTRL-EVENT-STATE-CHANGE id=0 state=6 BSSID=00:00:00:00:00:00]
V/WifiStateTracker(   96): Changing supplicant state: COMPLETED ==> GROUP_HANDSHAKE
I/wpa_supplicant(  234): WPA: Group rekeying completed with 00:18:39:da:04:b4 [GTK=TKIP]
I/wpa_supplicant(  234): CTRL-EVENT-STATE-CHANGE id=0 state=7 BSSID=00:00:00:00:00:00
V/WifiMonitor(   96): Event [WPA: Group rekeying completed with 00:18:39:da:04:b4 [GTK=TKIP]]
V/WifiMonitor(   96): Event [CTRL-EVENT-STATE-CHANGE id=0 state=7 BSSID=00:00:00:00:00:00]
V/WifiStateTracker(   96): Changing supplicant state: GROUP_HANDSHAKE ==> COMPLETED
D/dalvikvm(  192): GC_EXPLICIT freed 246K, 46% free 3680K/6791K, external 5818K/7214K, paused 51ms
D/dalvikvm( 1412): GC_CONCURRENT freed 560K, 46% free 3687K/6727K, external 1633K/2137K, paused 7ms+3ms

Has anyone else been having issues like this?

I am also having this problem on HTC Incredible and Samsung Nexus S. Not so much the crashes, but some touches start getting missed after the game has been suspended and resumed. This behaviour is ONLY exhibited by Unity version 3.4. Version 3.3 does not do this, and I’ve tested on both phones for hours to confirm this. It seems that the TouchPhase.Began phase goes missing sometimes.

I want to move to version 3.4 for the optimized Android loading, but this glitch could be a real deal breaker. Do any Unity employees have some insight into this problem?

Cheers,
Matt

Has anyone else had issues with this? I also hadn’t seen it occur with Unity 3.3. While 3.4 does fix a lot of Android issues we were having, this sort of seems like swapping one big problem with another.

I’m having a suspend and resume issue as well. Seems to work ok on our menu scene, but on one of our actual game scenes, we get a hang on resume. The log shows a “Launch timeout has expired, giving up wake lock!” message.
It showed up after 3.4. Unfortunately I don’t have a copy of 3.3 available to test with.

Updated.
I found a copy of the Unity 3.3 installer and gave it a try. It looks like 3.4 is definitely causing some issues.

What version of Android are you using? I’m getting the error with a Nexus One running 2.3.4, while and LG Optimus I have running 2.2.1 is fine.

I am facing this issue as well…
It seems to be there in devices running Android 2.3
On Android 2.2 the application works just fine.

Same thing happens on my Nexus One with Android 2.3.4 using Unity 3.4. It uses a very long time to resume, but then gives the “Force quit / Wait” message and sometimes crashes.

This worked fine in Unity 3.3 though. Will perform some more tests to try to nail it down further.

I’ve done some additional testing.

I use EZ GUI in my project, and if I disable certain controls, like UIStateToggleBtn, UIRadioBtn, or don’t do UIPanel transitions, then Suspend Resume works fine.

However if they are enabled, it doesn’t work and ends up showing a black screen, waiting, then gives the “Force quit / Wait” message. I don’t remotely use those controls either, they are just enabled or disabled.

Are you other guys also using EZ GUI or something in your scenes where it happens? If you aren’t using EZ GUI, perhaps something else which does something similar “behind the scenes”…

I actually am also using EZGUI, would be interesting if that is the source of the issues. If that is the problem, I wonder what in that code could possibly be killing the app? I’ll check around and see if anything looks suspicious.

I haven’t been able to find out what exactly in EZ GUI that makes it happen, except in my project at least it has something to do with UIStateToggleBtn, UIRadioBtn or UIPanel transitions. Hopefully we’ll be able to locate the culprit though! :slight_smile:

Having exactly the same issue. Using EZGui on Nexus One and Xoom. Will update if I find a fix with in EZGui.

So I think the problem has to do with Time.realtimeSinceStartup. Sometimes it displays negative numbers and if the animation time step is relying on that, it could break. I’ve replaced a couple of the Time.realtimeSinceStartup delta calculations with DateTime.Now deltas in EZGui and I think I’m getting better results. I’ll post any more success.

Are any of you guys using flurry?

I’m getting the same issues on my nexus one, whenever the game is resumed it starts missing touches and all sorts of weird stuff starts happening!

Hey guys I figured out the the looonnnggg BLACK SCREEN problem after RESUMING the game from home screen.

It wasnt an issue of unity 3.3 or 3.4. It just depends on which texture compressions are u using.

If automatic compression is ON for the individual textures, u will see that the on the Android Platform it automatically sets it too either Compressed ETC 4 bits or RGBA 16 bits depending on if texture has alpha or not. And this is the recommended setting if u r building for android cuz both have less loading times and are optimized for Android.

But in Unity 3.4 they gave an additional option of changing the Global Textures Compression on the Build Settings menu. So as I had made my game first on IOS, and PVRTC was working for me in IOS , so I changed them to PVRTC on the main Build Settings menu which is a very slow texture format for Andriod. Both in normal scene to scene loading times and when resuming from home screen of the android phone.

Anyway, anyone else having this same problem like me can just make the texture compression to Automatic Compression on both invidual texture settings tab and also the Build Setting tab.

This is only the solution for textures compression obviously. I will do more tests on EZGUI to see why it is causing problems.

Yes, I have implemented Flurry in my game BUT with the help of Prime31 plugin. His plugins make things easy as a pie :slight_smile:

Ah, in my project all compressions was set to Automatic already and Global Compression was also set to that, so that didn’t affect my project, but good find!

I haven’t found the exact problem in EZ GUI yet, but instead removed all UIStateToggleBtn UIRadioBtn, and turned them into regular UIButtons, and also disabled/removed all UIPanel UIPanelManager, and instead of using EZ GUI’s panel code for transitions I just used iTween to move the panels. After doing those changes it works great, no more black screen when resuming :slight_smile:

I’m still using UIButtons and UISlider, so those 2 components from EZ GUI work at least.

But hopefully we can figure out why it happens though, as it’s annoying to make these changes :confused:

What version of EZ GUI are each of you running?

Regarding toggles and radios, I can’t think of anything distinct on those two control types which would distinguish them from a regular button, etc. I’m doing tests on Nexus One as well and am not able to reproduce the issue with any of the control types.

I’m intrigued by the idea that it could be Time.realtimeSinceStartup though, and so if you are using transition effects on any of those controls, that might make sense.

If someone could provide more information, or ideally, if someone could e-mail me directly with a simple scene that reproduces the issue, I’d like to test with that. Thanks!

Hey guys,

so finally, SOLUTION. If you un-comment #define USE_DELTA_TIME so that the game uses Time.deltaTime, everything works. Brady, I cant tell you why exactly but we just finished days of debugging and finally zeroed in on that. We have tested the solution quite a bit and all looks good. The problem we were fighting was “ERROR/libEGL(5790): call to OpenGL ES API with no current context (logged once per thread)” that showed up in the logcat when you would try to resume the application. kromenak found out that this fires if Unity tries to do something with the GL while suspended. Note that we were not getting the problem in Unity 3.3.

That’s very strange. I could see resume affecting the realtime tracking. But I’m very curious as to what this could have to do with any kind of OpenGL call, since there is no kind of rendering code, etc, inside EZAnimator. My best guess is that the animation coroutine gets called, which in turn moves an object, scales it, or changes its color value, and one of these actions causes Unity to attempt to perform some kind of render operation indirectly. The fact that this issue is not present in Unity 3.3 means it is, at least in part, a Unity issue which probably needs to be reported to them.

Also, what version of EZ GUI was this? There is some new code in the last couple of versions that, upon suspend, also track the time elapsed during suspension, and deducts that from the time elapsed when the game is resumed. Though that still shouldn’t cause an issue like the one described here though.