Author Topic: NullReferenceException when Application is backgrounded on Android  (Read 4803 times)

jlloyd

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Stack trace looks like this:
07-13 16:36:53.702 27259 27280 I Unity   : NullReferenceException
07-13 16:36:53.702 27259 27280 I Unity   :   at UnityEngine.Transform.get_position () [0x00000] in <filename unknown>:0
07-13 16:36:53.702 27259 27280 I Unity   :   at UIAnchor.Update () [0x00000] in <filename unknown>:0
07-13 16:36:53.702 27259 27280 I Unity   :   at UIAnchor.ScreenSizeChanged () [0x00000] in <filename unknown>:0
07-13 16:36:53.702 27259 27280 I Unity   :   at (wrapper delegate-invoke) UICamera/OnScreenResize:invoke_void__this__ ()
07-13 16:36:53.702 27259 27280 I Unity   :   at (wrapper delegate-invoke) UICamera/OnScreenResize:invoke_void__this__ ()
07-13 16:36:53.702 27259 27280 I Unity   :   at (wrapper delegate-invoke) UICamera/OnScreenResize:invoke_void__this__ ()
07-13 16:36:53.702 27259 27280 I Unity   :   at (wrapper delegate-invoke) UICamera/OnScreenResize:invoke_void__this__ ()
07-13 16:36:53.702 27259 27280 I Unity   :   at (wrapper delegate-invoke) UICamera/OnScreenResize:invoke_void__this__ ()
07-13 16:36:53.702 27259 27280 I Unity   :   at (wrapper delegate-invoke) UICamera/OnScreenResize:invoke_void__this__ ()
07-13 16:36:53.702 27259 27280 I Unity   :   at (wrapper delegate-invoke) UICamera/OnScreenResize:invoke_void__this__ ()
07-13 16:36:53.702 27259 27280 I Unity   :   at (wrapper delegate-invoke) UICamera/OnScreenResize:invoke_void__this__ ()
07-13 16:36:53.702 27259 27280 I Unity   :   at (wrapper delegate-invoke) UICamera/OnScreenResize:invoke_void__this__ ()
07-13 16:36:53.702 27259 27280 I Unity   :   at (wrapper delegate-invoke) UICamera/OnScreenResize:invoke_void__this__ ()
07-13 16:36:53.702 27259 27280 I Unity   :   at (wrapper

We believe is an issue inside UIAnchor.Update where mTrans is null.  Adding null checks for mTrans seems to resolve the issue.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NullReferenceException when Application is backgrounded on Android
« Reply #1 on: July 15, 2016, 11:40:25 PM »
Both mTrans and the screen resize notification subscription are set in OnEnable which is guaranteed to be called before Update where you're running into the issue. I am not sure how you are getting it to happen at all. "mTrans" is always set first...

jlloyd

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: NullReferenceException when Application is backgrounded on Android
« Reply #2 on: September 07, 2016, 08:03:24 PM »
It only happens on device on Android (IL2CPP).  No idea why, but like I said the null check fixed it up.

Vicky

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: NullReferenceException when Application is backgrounded on Android
« Reply #3 on: September 16, 2016, 05:49:53 PM »
Because ScreenSizeChanged only be called on android. And on ios the screen size won't be changed unless you allow your app running on both portrait and landscape.

You may try to reproduce this issue in editor by change resolution in editor's Game view.