Resume from background restarting

Hey guys, anyone run into a situation where returning from background causes the app to restart for no apparent reason? I’m trying to figure out why this is happening (crashing). My game isn’t doing anything specific during:
applicationDidEnterBackground
or
applicationWillEnterForeground

I’m clueless as to whether its something nasty happening internally in cocos2d-x or I’m not properly understanding the application lifecycle and how it relates to the lack of “game save” feature.

Any help would be greatly appreciated.
Thanks.

1 Like

What platform? I’m fighting with Android now (haven’t got to testing on iOS hardware yet).

I think it’s something to do with the Android garbage collection. If I jump out of the game for a few seconds - answer text or something quick or power off phone then turn back on it keeps everything. Longer and I loose some of the TTF labels (and textures created in code) Just put out post on it today. But I just checked one of my test phones that has been off for a few hours and it came back on to the intro screen like it was just launched (I’ve been intentionally leaving it in level 2 of my game to make sure it’s keeping the game play). This has happened on a Galaxy S3 (4.4.4) and S5 (4.4.2). But a Zoom running 4.4.4 has so far not lost any graphics / text or the level I left it on yesterday!

So I don’t think it’s the OS version. I’m at a loss.

I notice the same font loss and restarting crap happening on my galaxy s4 as well. Also, a couple of my iPhone 5 and 5s testers complaining about this as well, also happening on my own 5s (iOS8).

Not sure if it’s related but I went through and was trying to clean up all of the depreciated code I had and haven’t seen the issue since.

The main thing that I think might have helped was on how the calbacks for menu’s were handled.

//Old call
auto closeItem = MenuItemLabel::create(lblQuitLabel, this, menu_selector(IntroScene::menuCloseCallback));
//New Call
auto closeItem = MenuItemLabel::create(lblQuitLabel, CC_CALLBACK_1(IntroScene::menuCloseCallback, this));

Not sure if this is it but for now at least my game seems to be working better.

Thanks for this dalek1, though all of my code is using non-deprecated API. I rolled back to 3.2 last night from 3.3 rc0, my game hasn’t restarted, but one of my testers sent me message saying his didn’t either, but then he opened his FB app, checked some emails, then went back to the game and THEN it had restarted. I’m confused!

Did you get anywhere with this? Seeing the same behaviour - app restarting, font loss, crashing - with moto g, v4.4.4, cocos2d-x-3.2

I’ve changed all of my labels from TTF to BM labels. I’ll send out a build soon for a new round of testing which will tell me if the app restarts. I noticed there was some weirdness going on with the TTF fonts on Android, so I’m wondering if that could be the issue.

Ok, yes it seems to be. The issue I was having was to do with updating ui::Text or any other object that uses TTF fonts, either while the app was in the background or during applicationWillEnterForeground.

When the app resumed, there would often be letters or whole labels missing - this would sometimes lead to crashes. So I assume this is something to do with reconstructing the font atlas, when the app resumes. I added an artificial delay - using DelayTime + CallFunc in a Sequence - and it seems to have resolved the issue.

That was my exact assumption regarding the problem. Thanks for reconfirming that the issues may be related! Please reply back with any details as you resolve the issue.

Thanks!

Hello Scoridd,

Can you please give me an indication on how you called a delaytime and callfunc in a sequence inside the AppDelegate?
It doesn’t allow me to call this->runAction(…)

Thanks!