Author Topic: NGUI Frozen on iPhone after sleeping for a while  (Read 4061 times)

TeddyDief

  • Guest
NGUI Frozen on iPhone after sleeping for a while
« on: October 09, 2012, 06:42:41 PM »
Hi!
I've found that sometimes, if my iPhone app has been asleep for several hours and I open it back up, Unity picks up where it left off, but NGUI isn't receiving input. This is difficult to test specifically because it requires waiting for hours at a time between tests.

Has anyone seen this NGUI freezing on iPhone or iPad, and can advise some way to wake up NGUI's input?

Thank you!

rain

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 79
    • View Profile
Re: NGUI Frozen on iPhone after sleeping for a while
« Reply #1 on: October 10, 2012, 01:59:46 AM »
No exceptions in the XCode log?

Darkmax

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 92
    • View Profile
Re: NGUI Frozen on iPhone after sleeping for a while
« Reply #2 on: October 14, 2012, 11:27:28 PM »
i'm having this issue with my iphone when i, stop using the phone for a while and i start using again the app this happens, but in some cases the gui responds but all mess up so i need to close the application and start it all again.

I hope some know why is this happening.

Radazen

  • Guest
Re: NGUI Frozen on iPhone after sleeping for a while
« Reply #3 on: October 20, 2012, 10:44:53 PM »
I'm experiencing the same issue mentioned in the original post, and it's pretty consistent and easy to reproduce. On my iPhone 4S and on my iPhone 5 (and probably on all of my iOS devices, but these are the two I've tested on), if I run my app, press the home button, and then resume it again some 10-12 hours later, NGUI freezes for a little while (anywhere from 5 to 30 seconds, in my experience) before reacting to my input again. The freeze duration seems to be proportional to the amount of time since I last used the application. So if I do it late at night, go to sleep, do other stuff in the morning, and then resume the app later that day, it freezes for a very very noticeable 20-30 seconds, but if I only wait a few hours, the freeze only lasts something like 5 seconds and isn't as apparent.

Given that the freeze duration seems proportional to the amount of time that's passed since I actually used the app, I'm guessing that it's something related to Time.realtimeSinceStartup, but I searched through the NGUI code and couldn't find any obvious place where realtimeSinceStartup would be causing the issue.

Radazen

  • Guest
Re: NGUI Frozen on iPhone after sleeping for a while
« Reply #4 on: October 20, 2012, 10:49:33 PM »
Also, for context's sake: the scenes that I see this happening in include a UIDraggable panel, buttons, and input fields. None of these things react to input when the freeze is happening.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 327
  • -Receive: 1153
  • Posts: 22,063
  • Toronto, Canada
    • View Profile
Re: NGUI Frozen on iPhone after sleeping for a while
« Reply #5 on: October 21, 2012, 12:34:23 AM »
Hmm... interesting. I may have an idea.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 327
  • -Receive: 1153
  • Posts: 22,063
  • Toronto, Canada
    • View Profile
Re: NGUI Frozen on iPhone after sleeping for a while
« Reply #6 on: October 21, 2012, 12:38:46 AM »
Open up IgnoreTimeScale's UpdateRealTimeDelta() function, and add this after line 49:
  1. if (mTimeDelta > 1f) mTimeDelta = 1f;
You may also need to do a search for "int ms" (4 references in NGUIMath.cs), and make sure that:
  1. if (deltaTime > 1f) deltaTime = 1f;

Radazen

  • Guest
Re: NGUI Frozen on iPhone after sleeping for a while
« Reply #7 on: October 21, 2012, 10:05:31 AM »
Changes made. I'll report back in a couple of days when my phones have had enough idle time to test the issue. Thanks.

Radazen

  • Guest
Re: NGUI Frozen on iPhone after sleeping for a while
« Reply #8 on: October 22, 2012, 11:54:50 AM »
Well, there's good news and bad news.

The good news is that the change in IgnoreTimeScale.cs does fix the problem. There's no freezing whatsoever when I resume the app after keeping it suspended for 12-16 hours.

The bad news is that the springy momentum movement of my UIDraggablePanel is broken by the change. For a while after I resume (actually, it's pretty similar to the way the freeze worked: the longer the app was suspended, the longer this issue lasts), there's no momentum when I drag. I can drag the panel, but it stops immediately when I stop dragging it. After a little while, it'll go back to having momentum. It's a much more exaggerated effect than the freeze was, though; 5 minutes of suspending the app is enough to make this issue very apparent on resume.

My inclination is to remove the changes in NGUIMath.cs, since they're in code related to spring lerping and dampening, but those changes don't end up being necessary anyway. deltaTime is always clipped to 1.0f before the clipping code I added to those methods, so removing the clipping code in NGUIMath.cs doesn't do anything.

Do the spring panels use some sort of accumulator? What I see with debug prints is this:

==================
No changes
==================
SpringDampen: deltaTime = 0.017
SpringDampen: deltaTime = 0.018
SpringDampen: deltaTime = 0.016
SpringDampen: deltaTime = 0.017

SUSPEND, WAIT A WHILE, RESUME

SpringDampen: deltaTime = 1752.508
SpringDampen: deltaTime = 0.017
SpringDampen: deltaTime = 0.018


==================
IgnoreTimeScale.cs changes
==================
SpringDampen: deltaTime = 0.017
SpringDampen: deltaTime = 0.018
SpringDampen: deltaTime = 0.016

SUSPEND, WAIT A WHILE, RESUME

SpringDampen: deltaTime = 1
SpringDampen: deltaTime = 1
SpringDampen: deltaTime = 1
SpringDampen: deltaTime = 1
SpringDampen: deltaTime = 1
SpringDampen: deltaTime = 1
SpringDampen: deltaTime = 1

<this goes on for quite some time, and my drags have no momentum while deltaTime = 1>

SpringDampen: deltaTime = 1
SpringDampen: deltaTime = 1
SpringDampen: deltaTime = 1
SpringDampen: deltaTime = 1

<eventually, we go back to normal deltaTime values, and my drags have momentum again>

SpringDampen: deltaTime = 0.018
SpringDampen: deltaTime = 0.016

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 327
  • -Receive: 1153
  • Posts: 22,063
  • Toronto, Canada
    • View Profile
Re: NGUI Frozen on iPhone after sleeping for a while
« Reply #9 on: October 22, 2012, 05:07:27 PM »
I have a feeling you put this before line 49, not after as I suggested. This is how it should be:
  1. mActual -= mTimeDelta;
  2. if (mTimeDelta > 1f) mTimeDelta = 1f;

Radazen

  • Guest
Re: NGUI Frozen on iPhone after sleeping for a while
« Reply #10 on: October 22, 2012, 11:04:47 PM »
Ah, oops. My line numbers were off by 1 because of a debug print I put in when I was trying to diagnose the issue a few days ago. Trying the suggested change now. Thanks!

Radazen

  • Guest
Re: NGUI Frozen on iPhone after sleeping for a while
« Reply #11 on: October 23, 2012, 03:06:45 PM »
Yup, that does it. No freeze on resume, no weirdness with spring dampening. I kept the changes in NGUIMath.cs, though I don't know if they're necessary or not. I'll remove those changes and see if everything still works properly.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 327
  • -Receive: 1153
  • Posts: 22,063
  • Toronto, Canada
    • View Profile
Re: NGUI Frozen on iPhone after sleeping for a while
« Reply #12 on: October 23, 2012, 03:07:26 PM »
You can keep them. You will see this change in the next update as well.

Radazen

  • Guest
Re: NGUI Frozen on iPhone after sleeping for a while
« Reply #13 on: October 23, 2012, 03:08:01 PM »
Works for me. Thanks for the assistance!

Darkmax

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 92
    • View Profile
Re: NGUI Frozen on iPhone after sleeping for a while
« Reply #14 on: October 31, 2012, 04:14:28 PM »
thanks works great