createFont(), P2D and memory problem

edit with change in question category (was testing in android but the samething happens in windows)

Hello,

I have a freak problem in a program i'm making.

my program gets public feeds from twiter and displays them. I'm using createFont() with the system sans serif font and rendering in P2D because is the only way it is fast enough. Very soon after starting the program the characters of the text become corrupt. I attribute this to the use of many characters of different languages. Once getGlyphCount() goes higher than about 1000, text starts to become unreadable.

Trying to work around this problem i started to recall createFont() once in a while as it would bring the glyph count back to 0. But when doing this the allocated memory rises steadily until it crashes the app, got this error on windows:

java.lang.RuntimeException: java.lang.OutOfMemoryError: GC overhead limit exceeded
    at processing.opengl.PSurfaceJOGL$2.run(PSurfaceJOGL.java:443)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.OutOfMemoryError: GC overhead limit exceeded
    at processing.opengl.FontTexture.addToTexture(FontTexture.java:349)
    at processing.opengl.FontTexture.addToTexture(FontTexture.java:253)
    at processing.opengl.PGraphicsOpenGL.textCharImpl(PGraphicsOpenGL.java:3596)
    at processing.core.PGraphics.textLineImpl(PGraphics.java:4981)
    at processing.opengl.PGraphicsOpenGL.textLineImpl(PGraphicsOpenGL.java:3563)
    at processing.core.PGraphics.textLineAlignImpl(PGraphics.java:4971)
    at processing.core.PGraphics.text(PGraphics.java:4644)
    at processing.core.PGraphics.text(PGraphics.java:4595)
    at processing.core.PApplet.text(PApplet.java:12529)
    at paraforum.draw(paraforum.java:40)
    at processing.core.PApplet.handleDraw(PApplet.java:2399)
    at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:731)
    at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692)
    at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674)
    at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:443)
    at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293)
    at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
    at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:759)
    at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81)
    at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:452)
    at com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)

Is there anyway to clear the opengl font texture?

Here's a code sample that produces the corrupted text (when getGlyphCount() goes up to about 1000):

PFont f;
String lines[];
String[] show = {};
int counter=0;

void setup() {
  size(displayWidth, displayHeight, P2D);
  frameRate(10);
  f = createFont("SansSerif", 36, true);
  lines = loadStrings("texto_lixo.txt");
  fill(0);
  textFont(f);

  for (int i=0; i<15; i++) {
    show = append(show, lines[i]);
  }
}

void draw() {
  background(255);
  for (int i=0; i<show.length; i++) {
    text(show[i], 0, i*40);
  }
  if (counter<lines.length) {
    show = append(show, lines[counter]);
    show = subset(show, 1);
    counter++;
  } else {
    counter=0;
  }
  long allocated = Runtime.getRuntime().totalMemory();
  long free = Runtime.getRuntime().freeMemory();
  println(allocated+"    :    "+free+"   :   "+f.getGlyphCount());
}

you can get the file i'm using here: https://www.dropbox.com/s/zy17qwxa36app6d/texto_lixo.txt?dl=0

thanks in advance Luís

Sign In or Register to comment.