(I’ll share MRE in a follow-up post, trying to think how best to summarise my code)
I have an art project which runs the createFont() function several times per frame – pulling random TTF/OTF files out of a folder containing thousands of fonts – and for some reason unknown to me (memory?) the sketch throws an Exception saying that a font is missing, when it’s clearly had no trouble finding it countless times before. The Exception can occur at anytime, almost immediately on launch, or after thousands of frames.
I’ve tried running my code using only one font – the same font over & over again – but even then, with createFont() being called several times per frame (as my sketch requires), the crash still occurs.
This is an example of the error I get during try{}
:
Problem with createFont("/Volumes/macOS/Users/abc/Desktop/Font-Collection/xyz.ttf")
java.io.IOException: Problem reading font data.
at java.desktop/java.awt.Font.createFont0(Font.java:1208)
at java.desktop/java.awt.Font.createFont(Font.java:1076)
at processing.core.PGraphics.createFont(PGraphics.java:4280)
at processing.core.PApplet.createFont(PApplet.java:5983)
at processing.core.PApplet.createFont(PApplet.java:5929)
at fontchaos.fontChangerLines(fontchaos.java:204)
at fontchaos.draw(fontchaos.java:176)
at processing.core.PApplet.handleDraw(PApplet.java:2185)
at processing.awt.PSurfaceAWT$9.callDraw(PSurfaceAWT.java:1440)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:356)
…and – despite working under normal circumstances – a slightly different Exception appears related to my catch{}
when the above try{}
has failed:
The font "/Volumes/Evo2/processing/fontchaos/DIN Condensed Bold.ttf" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
java.lang.RuntimeException: A null PFont was passed to textFont()
at processing.core.PGraphics.textFont(PGraphics.java:4419)
at processing.core.PApplet.textFont(PApplet.java:12714)
at fontchaos.fontChangerLines(fontchaos.java:205)
at fontchaos.draw(fontchaos.java:176)
at processing.core.PApplet.handleDraw(PApplet.java:2185)
at processing.awt.PSurfaceAWT$9.callDraw(PSurfaceAWT.java:1440)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:356)
fontchaos.pde:189:0:189:0: RuntimeException: A null PFont was passed to textFont()
Finished.
Looking at Activity Monitor I have a hunch this has something to do with memory. The sketch has thousands of files open at the same time, 40GB+ of virtual memory in use etc. etc… so perhaps each time createFont() gets called the font files are shoved into memory but never released?
If anyone has any bright ideas, I’m all ears, thanks in advance!