We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › loadFont trouble
Page Index Toggle Pages: 1
loadFont trouble (Read 465 times)
loadFont trouble
Dec 9th, 2008, 10:14am
 
Hi everybody.

I m programing a software. I wanted to load all fonts once, and used it as static in my PApplet. I don't know why I can load 3 different fonts but no more. That's weird. All fonts file are correct I tested it one by one.

public abstract class Form extends PApplet{

public static Hashtable<String,PFont> Fonts = new Hashtable<String,PFont>();

public void setupApplet()
{
if(Form.Fonts.isEmpty())
{
Form.Fonts.put("Normal-48", loadFont("DejaVuSans-48.vlw"));
Form.Fonts.put("Bold-48", loadFont("DejaVuSans-Bold-48.vlw"));
Form.Fonts.put("Normal-12", loadFont("DejaVuSans-12.vlw"));
Form.Fonts.put("Bold-12", loadFont("DejaVuSans-Bold-12.vlw"));
}
}
}

I ve got this message:

Exception in thread "Animation Thread" java.lang.OutOfMemoryError: Java heap space
at processing.core.PImage.init(PImage.java:144)
at processing.core.PImage.<init>(PImage.java:130)
at processing.core.PFont.<init>(PFont.java:207)
at processing.core.PApplet.loadFont(PApplet.java:3500)
at processing.util.Form.setupApplet(Form.java:62)
at main.setup(main.java:12)
at processing.core.PApplet.handleDraw(PApplet.java:1383)
at processing.core.PApplet.run(PApplet.java:1311)
at java.lang.Thread.run(Thread.java:619)

Thanks for your help
Re: loadFont trouble
Reply #1 - Dec 9th, 2008, 12:04pm
 
Hi,

Since you got an  java.lang.OutOfMemoryError you should try to increase the heap size.
java -Xms<initial heap size> -Xmx<maximum heap size>

have you tried to "Increase maximum  available memory to xxx MB" in the Processing Preferences?


Cheers,
Paul
Re: loadFont trouble
Reply #2 - Dec 9th, 2008, 1:09pm
 
papo, unless the generated fonts are MB in size, I doubt the issue is so trivial. Plus vibou seems to run out of Processing, although I am not sure.

vibou, some remarks:
- Since Fonts is part of the class, you don't need to prefix with Form on each call.
- If setupApplet is called only once, no need for the test.
- Why is Form abstract
- Why Form extends PApplet This might be the main culprit. See Processing in Eclipse which explain you should have only one PApplet class. Both conceptually (OO design) and in practice. Other classes should get and use a reference to the PApplet.
Re: loadFont trouble
Reply #3 - Dec 9th, 2008, 8:43pm
 
Quote:
- Since Fonts is part of the class, you don't need to prefix with Form on each call.

I call it with Form because the hashtable is static so that it's better practice to do so. (it avoids a warning in Eclipse Smiley )

Quote:
- If setupApplet is called only once, no need for the test.

Just to make the function more robust

Quote:
- Why is Form abstract?
Why Form extends PApplet?


That's some good question Smiley. I'm trying to make my own library of composents for processing because processing and swing are not very friends Smiley.
It's not finished yet of course... Smiley

Fonts altogether are 1,4 MB.... that's probably why.
I'll make fonts not with all character so...

But I'm still interresting in changing maximum memory available for processing, or my application, but I don't know where is that option.

Thanks a lot for suggestions Wink
Re: loadFont trouble
Reply #4 - Dec 9th, 2008, 9:33pm
 
I don't want to prevent you from using your own style of coding, but I will just point out that using Form.Font is indeed better practice that using instanceOfForm.Font, and necessary when accessing it from another class, but you can just use Font within the Form class. Just to be sure I tested in Eclipse 3.4 and it didn't complained... Smiley

Again, I see a problem with the abstract Form extending PApplet (but I can be wrong here!): you cannot instantiate Form, so you have to instantiate sub-classes, meaning you might have several instances of PApplet, which seems to be a bad thing (if I understood correctly the page I link to).

And Java is very able to manage 1.4MB of data, it shouldn't be an issue. A 800x800 sketch is already using 2.5MB!
Re: loadFont trouble
Reply #5 - Dec 9th, 2008, 9:53pm
 
So first: Sorry you completely right about Form.Font it doesn't complain. ups Smiley so I changed it for your solution.

Yeah I have such a thing in head... Several instances of PApplet... I'm trying to work on Dialog meaning that the parent PApplet will wait for the other. It might be a solution.

Even though I don't use several instance of Form but one, I still usefull to have abstract class you can re-used in other project.

let see my draw in a class which inherits of form.
public void setup()
{
size(500,500);
startButton start = new startButton(10,10,120,30,"Start"); //start button inherits of my class Button Smiley
this.addComponent(start);
//Call after setting all components;
this.setupApplet();
}

public void draw()
{
      this.update();
}

With this code, I'm able to manage whatever I want on my "Form" with my button with 3 function implements overidable.
onMouseOver, onMouseReleased, onMousePressed

onMouseReleased is executed only once of course Smiley

Thanks so much for advice
Page Index Toggle Pages: 1