Acknowledged

OLED: font resources seem to be forgotten while sleeping which leads to a crash onExitSleep

It seems that OLED watches now release fonts when sleeping and onExitSleep is called before initialize, so the app crashes when it uses fonts in the onExitSleep to update the layout. 

I get null exception while a resource is expected on this line that is called from onExitSleep.

"UnexpectedTypeException: Expected Number/Resource, given null…"

I got thousands of failure reports on this line from a variety of OLED devices. 

I do not release fonts anywhere in the code and the same line is called via initialize without problems. 

I hotfixed it by catching the exception and calling the initialize instead, but that is a huge wasting of resources and probably a battery. 

I am not aware of any documentation that the Monkey might release any resources on its own and even if it does, I'd expect it would call initialize before onExitSleep. 

Some of devices where the error occurred: 

  • Venu® 3: 8.25
  • vívoactive® 5: 8.27, 4.14
  • Forerunner® 265s: 17.26

EDIT: added an exception text

EDIT2: added devices 

Parents
  • Devices should not be calling onEnterSleep or onExitSleep before initialize. It should be pretty easy to prove to yourself that this is (or is not) happening using the good old System.println() debugger to output the name of the function in each of the calls.

    What is the text of the exception that you catch? This is a critical piece of information that you've omitted that will help to diagnose the issue.

    Yes, the system can evict resources that you hold references to from the graphics pool. This happens silently. The next time you need the resource (you render the bitmap, or render text using the font), the system will evict resources from the pool to make room (if necessary) and load your resource behind the scenes automatically. There is a chance that you (or other apps) have resources in the pool that are "locked" and cannot be evicted. Problems will definitely occur if the system needs memory for your resources and the pool cannot be cleaned up to make room. I believe you'd get a system error on older build, and with newer builds you should get a specific exception to indicate this.

    You should never see fontSmall get set back to null. It is possible that there is a bug down in the virtual machine somewhere that causes a reference that is internally maintained by the system is getting set to null, but you are using these things correctly.

    I've had to say this twice in the last week... You should not be calling initialize() directly on any object EXCEPT when initializing a base class from a derived class initialize(). It could easily lead to resource leaks. We should insert a compiler guard to prevent you from doing it in the first place.

    If you find that you need to initialize data in self again, write a separate function that does that work, and call it from initialize() if that is what you need.

Comment
  • Devices should not be calling onEnterSleep or onExitSleep before initialize. It should be pretty easy to prove to yourself that this is (or is not) happening using the good old System.println() debugger to output the name of the function in each of the calls.

    What is the text of the exception that you catch? This is a critical piece of information that you've omitted that will help to diagnose the issue.

    Yes, the system can evict resources that you hold references to from the graphics pool. This happens silently. The next time you need the resource (you render the bitmap, or render text using the font), the system will evict resources from the pool to make room (if necessary) and load your resource behind the scenes automatically. There is a chance that you (or other apps) have resources in the pool that are "locked" and cannot be evicted. Problems will definitely occur if the system needs memory for your resources and the pool cannot be cleaned up to make room. I believe you'd get a system error on older build, and with newer builds you should get a specific exception to indicate this.

    You should never see fontSmall get set back to null. It is possible that there is a bug down in the virtual machine somewhere that causes a reference that is internally maintained by the system is getting set to null, but you are using these things correctly.

    I've had to say this twice in the last week... You should not be calling initialize() directly on any object EXCEPT when initializing a base class from a derived class initialize(). It could easily lead to resource leaks. We should insert a compiler guard to prevent you from doing it in the first place.

    If you find that you need to initialize data in self again, write a separate function that does that work, and call it from initialize() if that is what you need.

Children
  • I've written SOMETIMES. Your problem is probably because sometimes system doesn't call onLayout().

  • I don't call the onExitSleep  – the OLED device calls it itself without my intervention.

    Re: "You should never see fontSmall get set back to null."

    That's exactly what happens!

    The exception on that line using the font (previously loaded in initialize) is: "UnexpectedTypeException: Expected Number/Resource, given null…"

    Not sure if that exception continues, because there's no way how to reproduce it without the device. It does not show in a simulator. I don't have an OLED device, so I had to let it print to the device display and let my users to report it to me back.

    Contrary what _psx_ reported, my report is that onEnterSleep and onExitSleep are called correctly, but OLED watches often (not always) remove the font used on that line 
    (without my intervention) and it stays removed when the watch itself calls the onExitSleep. Thousands of reports from a variety of OLED watches. 

  • Problem is that sometime system calls onExitSleep:

    -  without the previous onEnterSleep

    - only after initialise