Jump to content

Background Problem with Cordova iOS


G3n3ralTao
 Share

Recommended Posts

Hello,

We are currently developping an iOS application using Cordova and we are facing a strange issue.

If the application return from background mode, the game slow down drasticly. We are talking about 5-10 fps instead of 30. We added a callback function on the document event "resume" to reload the application using the location.reload() function, but this solution work 4 time out of 5. Either it working well at 30 fps or we are back at the 5-10 fps. Preventing the application to enter background mode isn't an option since the issue happen when the device is closed manually. It seem that this action doesn't count has a background mode and the framerate goes into "abysmal mode" yet again.

We looked into Cordova bug tracker to see if a similar issue was experienced by other user, but so far we found nothing. So we were wondering if anyone had similar issues or any explication on why this is happening. 

Thank you in advance

Link to comment
Share on other sites

Most likely a bug in Cordova's underlying framework.

Try to trace exactly what causes the slowdown. Run a profiler to see which functions' running time skyrockets after switching.

I never worked with those, but I have a hunch this has to do with framework pumping huge amount of events trying to catch up for the time it wasn't running.

Link to comment
Share on other sites

Thank you for the input. I will investigate that. 

In the meantime, I did some tests including pausing Phaser while the application is in background mode, but even then the performance doesn't improve unfortunately.

In Xcode, I also get weird thread warnings: 

"THREAD WARNING: ['NetworkStatus'] took '17.43452' ms. Plugin should use a background thread."

But I get that at start-up, but the application doesn't slow down. I dug around on that topic and every one is saying that this warning is harmless. Might be related in a weird and twisted way (Like most things with Cordova) since it's not always the same plugin that is mentioned in the Xcode console. 

I'll keep updating this thread has I find new clues or solution to this problem.

Link to comment
Share on other sites

Ok, small update. Still investigating.

With the Safari developer console's profiler and I found that when our application return from the background mode the update RAF call in the "loop" function take at least 0.020ms more time on each frames. I tried forcing Phaser to use of setTimeout over requestAnimationFrame, but I still get the same delay on each calls. I am experimenting with the Phaser configuration to try and find an option that might cause this delay in the game loop but so far, no luck.

I found no way to look into Cordova inner working to find if the delay would come from it, but then again, it's Phaser that get the delay during it loop call. 

I am still digging, I'll keep you posted on my findings. 

Link to comment
Share on other sites

Got it!

For some reason, the RAF isn't stopped while the application is in background mode. To fix this, you need to add the following event listeners:

document.addEventListener("pause", function()
{
    game.paused = true;
    game.raf.stop();
}, false);

document.addEventListener("resume", function()
{
    game.paused = false;
    game.raf.start();
}, false);

I force the engine to pause just to be sure. I didin't receive any paused/resumed events during my tests and Time would continue to run in background mode.

I just found out that solution and I only test it on 3 devices. I am about to send it to the QA departement, so if we find any other issue with the background mode, I'll update this topic.

Bonne fin de journée!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...