iOS multitasking freezes Unity app

Upgrading our app to iOS 4. With or without multitasking enabled via the Info.plist we are noticing freezes in our game just from activating the multitasking panel with a double click of the home button.

So:

  1. Open game (even just leave it sitting at menu screen, though the same thing happens during game play)
  2. Double click home button to bring up multitasking panel
  3. Tap back into the game area to return to the game
  4. Unity is frozen and there’s nothing you can do but close the app by clicking the home button

This doesn’t happen EVERY time but it happens most of the time. With some debugging I can see the exact issue. Sometimes the app never receives the applicationDidBecomeActive event and therefore Unity never becomes unpaused. Not sure how to solve it, though.

Has anyone else seen this? Any ideas for workarounds or solutions?

Thanks,

Jeremy

UPDATE: Actually, you don’t have to close and reopen the app. You can simply re-pause (double click home button) and then un-pause again (click in the game area). Repeatedly doing this shows that sometimes it happens and sometimes it doesn’t within one game session.

UPDATE: The only way I can get these messages consistently is to completely remove the UnityPause(true) and UnitySetAudioSessionActive(false) calls during applicationWillResignActive. Probably not ideal. Any other ideas?

I don’t have this problem.

My game works after return in-game.

I try with other project, no problem too.

We have the same (or similar) problem:

When reopening the app, the visual is totally frozen. However, the UI and gameplay are still working, even though we don’t get any visual feedback at all and don’t see anything moving, we can still click on the buttons and play the game.

What’s going on??? OMG! I DID mess with the audio settings because our audio was turning off due to the “Enhancement Pack” and also deleted some random picture taking code that was giving errors (also due to Enhancement Pack).

BTW, not having any problems on this particular setup: 3Gs + iOS 4.0.0

so what, do you have a problem or do you not have a problem?

Yeah, because the nothing on the screen is moving. It’s like the game is playing in the background, I know it is because of the sound FX are playing as expected, but problem is that the screen never changes.

So on which setup then? you mention above on which all is running fine and thats aside of the iphone4 the only possible setup at all

So far we have witnessed it being broken on 3G + OS 4.0.0, and have customer comments of it not working on iTouch 2G + OS 4.0.1, and some others that just said they are using OS 4. So it’s always OS 4, except on my 3GS where it seems to work fine…

on 3G there is no multitasking or background alive keeping at all.
On 3G, pressing home = termination

What you though will realize, independent on if you like it or not, is that on 3G you have less RAM available and it takes longer to load than before. So chances that you get crashes due to this raises massively (out of my experience, stuff that previously worked but was over 25mb ram now stands little chances to load at all anymore … perhaps 1 out of 5 times where it does not crash on startup already, if it gets through there, it crashes on the switch to the level)

Also, don’t know if this helps - but I was getting crashes and device lockups with after manually closing a Unity app from the multitasking tray (on a 3GS). Figured out it was only when the phone was plugged into XCode. After unplugging from XCode the crashing stopped.

I’m not doing anything special and I haven’t had the problems your are explaining. On my 3GS, fast app switching is working fine.

Have you tried creating a new very basic Unity app to see if this happens with it too?

Wanted to get a feel for whether this was a common problem or not. Looks like it’s hit or miss. I’ll have to try that.

Also, should have included this, but my testing is on a 3GS running iOS 4.0.

I was just curious if anyone ever found a solution to this issue. I’ve been having the same problem on an iPad 1 and iPad2 on iOS 4.3. The only thing that I’ve noticed that when this occurs applicationDidBecomeActive isn’t actually called. I wasn’t sure if this is just an issue with iOS or if its something I can fix.

If you’re using NativeToolkit, notice that NativeToolkit.mm pauses Unity during applicationDidBecomeActive if there is a iOS view being shown.

I’ve had the same problem. Sorry if the post is a little bit late, but i hope it could save somebody a headache :slight_smile:
It comes from NativeToolkit.
in the NativeToolkit.mm I added this line:

- (void)applicationDidBecomeActive:(NSNotification*)note
{
	if( _displayingViewController ){
             /* add this line: */      [self showViewControllerWithName:@"MenuViewController"];
	   
             [self pauseUnity:YES];
    }
    
}

“applicationDidBecomeActive:” is called every time the app starts
MenuViewController is a controller that I’ve created.
In the MenuViewController.m I’ve added:

- (void) onContinueGame{
    [[NativeToolkit sharedManager] pauseUnity:NO];
    [[NativeToolkit sharedManager] hideViewController:self];
    
}

Note that MenuViewController will be shown even on the first run of the app. But I also wanted that to happen :slight_smile:

EDIT: in order for this to work I;ve changed the boolean _displayingViewController to YES. If it’s a NO - code is not being called and app is not freezing. I guess the problem stays when I show a view controller from unity script that boolean gets set to YES, and then when multitasking is done the freezing problem appears… (it’s difficult to explain it better)

Any Resolutions???
I also have a problem where some times after multitasking or screen being locked reopening the app the visual is frozen but UI still seems to work sounds play on button click etc. but visual will frozen till app is shut down in memory and restarted. Only tested and noticed on Ipad2 so far. No “Enhancement Pack” or “Native Tool kit” … I am using several Prime 31 plugins… “Etcetra”, “Flurry”, “Social Networking”

1 Like