New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text() throws NullPointerException when using loadFont instead of createFont and textMode(SHAPE) #4680

Closed
D3add3d opened this Issue Sep 28, 2016 · 14 comments

Comments

Projects
None yet
5 participants
@D3add3d

D3add3d commented Sep 28, 2016

When using loadFont("ArialMT-32.vlw") instead of createFont("Arial", 32, true) and calling textMode(SHAPE) before text() it throws NPE

Processing 3.2.1
Windows 7 SP1 Ultimate 64-bit
Java 8 (1.8.0_11-b12)

@gohai

This comment has been minimized.

Show comment
Hide comment
@gohai

gohai Sep 28, 2016

Contributor

Do you get some information as to where this NullPointerException is happening (in the Processing source code)?

Contributor

gohai commented Sep 28, 2016

Do you get some information as to where this NullPointerException is happening (in the Processing source code)?

@D3add3d

This comment has been minimized.

Show comment
Hide comment
@D3add3d

D3add3d Sep 29, 2016

No, there is no stacktrace, it just writes NullPointerException to the console and highlights the first text() call. (Also tried with text("Hello World", 5, 5); to eliminate NPEs that might have been caused by variables and such)

D3add3d commented Sep 29, 2016

No, there is no stacktrace, it just writes NullPointerException to the console and highlights the first text() call. (Also tried with text("Hello World", 5, 5); to eliminate NPEs that might have been caused by variables and such)

@D3add3d

This comment has been minimized.

Show comment
Hide comment
@D3add3d

D3add3d Sep 29, 2016

When I get home from school I will try wrapping the text() call in a try catch block and see if I can get a stacktrace that way

D3add3d commented Sep 29, 2016

When I get home from school I will try wrapping the text() call in a try catch block and see if I can get a stacktrace that way

@KhaledTo

This comment has been minimized.

Show comment
Hide comment
@KhaledTo

KhaledTo Oct 1, 2016

Hi,

I think it happens when the file for the font is missing, I hope this can help :

java.lang.NullPointerException
    at java.io.DataInputStream.readInt(DataInputStream.java:387)
    at processing.core.PFont.<init>(PFont.java:350)
    at processing.core.PApplet.loadFont(PApplet.java:6124)
    at firstTry.setup(firstTry.java:19)
    at processing.core.PApplet.handleDraw(PApplet.java:2387)
    at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1540)
    at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:316)

KhaledTo commented Oct 1, 2016

Hi,

I think it happens when the file for the font is missing, I hope this can help :

java.lang.NullPointerException
    at java.io.DataInputStream.readInt(DataInputStream.java:387)
    at processing.core.PFont.<init>(PFont.java:350)
    at processing.core.PApplet.loadFont(PApplet.java:6124)
    at firstTry.setup(firstTry.java:19)
    at processing.core.PApplet.handleDraw(PApplet.java:2387)
    at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1540)
    at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:316)
@D3add3d

This comment has been minimized.

Show comment
Hide comment
@D3add3d

D3add3d Oct 1, 2016

@KhaledTo I did not have time to try the try catch block but I'm 100% sure the file is in the /data folder and as I said: it WORKS without throwing any error when I don't use the textMode(SHAPE)

D3add3d commented Oct 1, 2016

@KhaledTo I did not have time to try the try catch block but I'm 100% sure the file is in the /data folder and as I said: it WORKS without throwing any error when I don't use the textMode(SHAPE)

@KhaledTo

This comment has been minimized.

Show comment
Hide comment
@KhaledTo

KhaledTo Oct 1, 2016

@D3add3d so that's something different, I couldn't reproduce this issue. Maybe you should post your code.

Ubuntu 14.04.5 LTS
Processing 3.2.1
Java 8 (1.8.0_101)

KhaledTo commented Oct 1, 2016

@D3add3d so that's something different, I couldn't reproduce this issue. Maybe you should post your code.

Ubuntu 14.04.5 LTS
Processing 3.2.1
Java 8 (1.8.0_101)

@D3add3d

This comment has been minimized.

Show comment
Hide comment
@D3add3d

D3add3d Oct 1, 2016

@KhaledTo unfortunatelly I'm not allowed to post the code where this issue occured but I will try to reproduce it using new sketch and post that code.

D3add3d commented Oct 1, 2016

@KhaledTo unfortunatelly I'm not allowed to post the code where this issue occured but I will try to reproduce it using new sketch and post that code.

@D3add3d

This comment has been minimized.

Show comment
Hide comment
@D3add3d

D3add3d Oct 1, 2016

Ok I managed to reproduce it using this code:

PFont pismo;

void setup() {
  size(1280, 720, P3D);
  pixelDensity(displayDensity());
  pismo = loadFont("ArialMT-32.vlw");
  textFont(pismo, 32);
  textSize(32);
  textAlign(CENTER, CENTER);
}

void draw() {
  textMode(SHAPE);
  try {
    text("test",5,5);
  } catch(Exception e) {
    e.printStackTrace();
  }
  noLoop();
}

The stack trace is:

java.lang.NullPointerException
    at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)
    at sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:281)
    at sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:250)
    at sun.awt.SunToolkit.getFontMetrics(SunToolkit.java:649)
    at sun.awt.windows.WToolkit.getFontMetrics(WToolkit.java:644)
    at processing.opengl.PJOGL.getFontMetrics(PJOGL.java:468)
    at processing.opengl.PJOGL.getFontRenderContext(PJOGL.java:476)
    at processing.opengl.PJOGL.access$2(PJOGL.java:475)
    at processing.opengl.PJOGL$FontOutline.<init>(PJOGL.java:695)
    at processing.opengl.PJOGL.createFontOutline(PJOGL.java:686)
    at processing.opengl.PJOGL.createFontOutline(PJOGL.java:1)
    at processing.opengl.PGraphicsOpenGL.textCharShapeImpl(PGraphicsOpenGL.java:3680)
    at processing.opengl.PGraphicsOpenGL.textCharImpl(PGraphicsOpenGL.java:3626)
    at processing.core.PGraphics.textLineImpl(PGraphics.java:4984)
    at processing.opengl.PGraphicsOpenGL.textLineImpl(PGraphicsOpenGL.java:3597)
    at processing.core.PGraphics.textLineAlignImpl(PGraphics.java:4974)
    at processing.core.PGraphics.text(PGraphics.java:4647)
    at processing.core.PGraphics.text(PGraphics.java:4598)
    at processing.core.PApplet.text(PApplet.java:12595)
    at sketch_161001b.draw(sketch_161001b.java:31)
    at processing.core.PApplet.handleDraw(PApplet.java:2412)
    at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:871)
    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)

EDIT: http://puu.sh/rulCg/c95d6e2148.png screen showing the placement of the created font in the data folder

D3add3d commented Oct 1, 2016

Ok I managed to reproduce it using this code:

PFont pismo;

void setup() {
  size(1280, 720, P3D);
  pixelDensity(displayDensity());
  pismo = loadFont("ArialMT-32.vlw");
  textFont(pismo, 32);
  textSize(32);
  textAlign(CENTER, CENTER);
}

void draw() {
  textMode(SHAPE);
  try {
    text("test",5,5);
  } catch(Exception e) {
    e.printStackTrace();
  }
  noLoop();
}

The stack trace is:

java.lang.NullPointerException
    at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)
    at sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:281)
    at sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:250)
    at sun.awt.SunToolkit.getFontMetrics(SunToolkit.java:649)
    at sun.awt.windows.WToolkit.getFontMetrics(WToolkit.java:644)
    at processing.opengl.PJOGL.getFontMetrics(PJOGL.java:468)
    at processing.opengl.PJOGL.getFontRenderContext(PJOGL.java:476)
    at processing.opengl.PJOGL.access$2(PJOGL.java:475)
    at processing.opengl.PJOGL$FontOutline.<init>(PJOGL.java:695)
    at processing.opengl.PJOGL.createFontOutline(PJOGL.java:686)
    at processing.opengl.PJOGL.createFontOutline(PJOGL.java:1)
    at processing.opengl.PGraphicsOpenGL.textCharShapeImpl(PGraphicsOpenGL.java:3680)
    at processing.opengl.PGraphicsOpenGL.textCharImpl(PGraphicsOpenGL.java:3626)
    at processing.core.PGraphics.textLineImpl(PGraphics.java:4984)
    at processing.opengl.PGraphicsOpenGL.textLineImpl(PGraphicsOpenGL.java:3597)
    at processing.core.PGraphics.textLineAlignImpl(PGraphics.java:4974)
    at processing.core.PGraphics.text(PGraphics.java:4647)
    at processing.core.PGraphics.text(PGraphics.java:4598)
    at processing.core.PApplet.text(PApplet.java:12595)
    at sketch_161001b.draw(sketch_161001b.java:31)
    at processing.core.PApplet.handleDraw(PApplet.java:2412)
    at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:871)
    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)

EDIT: http://puu.sh/rulCg/c95d6e2148.png screen showing the placement of the created font in the data folder

@KhaledTo

This comment has been minimized.

Show comment
Hide comment
@KhaledTo

KhaledTo Oct 1, 2016

Thank you @D3add3d,

Ok first i have to say it's my first day with prototype, so i might be wrong, but I think that if you move textMode(SHAPE); after text("test",5,5); it should work. Looks like the text object needs to be drawn before you call textMode(SHAPE);.

KhaledTo commented Oct 1, 2016

Thank you @D3add3d,

Ok first i have to say it's my first day with prototype, so i might be wrong, but I think that if you move textMode(SHAPE); after text("test",5,5); it should work. Looks like the text object needs to be drawn before you call textMode(SHAPE);.

@D3add3d

This comment has been minimized.

Show comment
Hide comment
@D3add3d

D3add3d Oct 1, 2016

@KhaledTo calling it after the text() call beats the purpose of it, the text would be drawn in the "MODEL" mode.

D3add3d commented Oct 1, 2016

@KhaledTo calling it after the text() call beats the purpose of it, the text would be drawn in the "MODEL" mode.

@KhaledTo

This comment has been minimized.

Show comment
Hide comment
@KhaledTo

KhaledTo Oct 2, 2016

Oh, ok thank you for this info @D3add3d. Anyway i don't know anything about processing but this doesn't look like a bug coming from processing to me, more like something you have to change inside your code. I hope an experienced processing developer helps you on this one.

KhaledTo commented Oct 2, 2016

Oh, ok thank you for this info @D3add3d. Anyway i don't know anything about processing but this doesn't look like a bug coming from processing to me, more like something you have to change inside your code. I hope an experienced processing developer helps you on this one.

@D3add3d

This comment has been minimized.

Show comment
Hide comment
@D3add3d

D3add3d Oct 2, 2016

@KhaledTo to me it seems that there are some syncing issues in Processing itself, it is using some hash map from multiple threads and that map somehow does not exist.

D3add3d commented Oct 2, 2016

@KhaledTo to me it seems that there are some syncing issues in Processing itself, it is using some hash map from multiple threads and that map somehow does not exist.

@JakubValtar

This comment has been minimized.

Show comment
Hide comment
@JakubValtar

JakubValtar Oct 4, 2016

Contributor

WLV fonts are bitmap fonts, they don't have shape data in them. You have to use TTF for that.

In this case, I'm not sure if we try to find the font of the same name in the system or not. In any case, we should show some reasonable error message instead of a NPE.

Contributor

JakubValtar commented Oct 4, 2016

WLV fonts are bitmap fonts, they don't have shape data in them. You have to use TTF for that.

In this case, I'm not sure if we try to find the font of the same name in the system or not. In any case, we should show some reasonable error message instead of a NPE.

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry Oct 29, 2016

Member

Added code to show a warning and switch back to textMode(MODEL) when the native font is not available (i.e. when a .vlw is used)

Member

benfry commented Oct 29, 2016

Added code to show a warning and switch back to textMode(MODEL) when the native font is not available (i.e. when a .vlw is used)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment