-
• #2
(I call
require("FontVGA8").add(Graphics);
inside of the{...}
block of my code in the clock face btw) -
• #3
I think you hit a case nobody thought about before. At least I did not. "removable" apps are expected to cleanup all changes they did to global state while they are unloaded. In my opinion that includes the loading of fonts.
Widgets are the one notable exception to this general rule, just because it is not easy to completely get rid of widgets. In your case the app removes the font as it should but the widget still exists and expects it to be there. I suspect the loading of the font only takes place once in the widget and one of the following draws then fails.- Clock loaded, widgets loaded, font available globally
- Switch from clock to launcher, widgets still loaded, font removed by clock
- Something calls draw of widget, fails because of missing font.
There are a few possible solutions:
- Checking for the font in the widgets draw and reloading it if needed
- Not unloading fonts at all, probably problematic on Bangle 1 because of memory constraints
- Make the loading of fonts more local to app/widget instead of the global graphics object
- Attach a counter to a font on load and only really unload it if there is no user left
There probably are more ways to get this done but some discussion on this will be needed since will affect global behaviour.
- Clock loaded, widgets loaded, font available globally
-
• #4
Yes, that's a tricky one.
Generally clock faces load big fonts which aren't used by anything else, so deleting them isn't a big deal.
However, when something uses a module, generally we don't try and remove the module from memory - and FontVGA8 is a module (
require("FontVGA8").add(Graphics);
).I think in this case I'd just not delete the font from memory - in the scheme of things it's not going to be using huge amounts of RAM. As mentioned it might be an issue on Bangle.js 1 where memory is tight, but realistically you're probably not developing your app to run on that anyway.
-
• #5
Thanks, I will simply not delete the module :)
Hello,
I developed a clock face that uses the
VGA8
font.At the beginning I call:
require("FontVGA8").add(Graphics);
.I tried implementing fast loading so in the
remove
handler I call:delete Graphics.prototype.setFontVGA8;
The problem is that I also have a widget that uses the
VGA8
font. Now, even though the widget callsrequire("FontVGA8").add(Graphics);
in the beginning of its own code as well, I get the errorUnknown font VGA8.
Was I supposed to call
delete Graphics.prototype.setFontVGA8;
?