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

I have the same issue: After switching between apps, the game gets really slow when reactivated. It drops from 60fps to 6fps and remains slow until the game is stopped and restarted.

The game is packaged with phonegap/cordova and uses canvas-mode for rendering. This behaviour only occurs on iOS (here iOS 9).

 

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

16 hours ago, G3n3ralTao said:

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

Confirmed, this also fixed my phonegap resume issue. Thanks so much @G3n3ralTao!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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