sojamo / controlp5

A gui library for processing.org
GNU Lesser General Public License v2.1
490 stars 142 forks source link

IndexOutOfBounds exception with console on Windows #153

Open nielmistry opened 5 years ago

nielmistry commented 5 years ago

We get an StringIndexOutOfBoundsException on the .draw() function when we have console output on the screen:

java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.String.substring(String.java:1967)
    at controlP5.ControlFont.calculateHeight(Unknown Source)
    at controlP5.ControlFont.adjust(Unknown Source)
    at controlP5.Label$MultilineLabel.draw(Unknown Source)
    at controlP5.Label.draw(Unknown Source)
    at controlP5.ControllerGroup.draw(Unknown Source)
    at controlP5.ControllerGroup.drawControllers(Unknown Source)
    at controlP5.ControllerGroup.draw(Unknown Source)
    at controlP5.ControlWindow.draw(Unknown Source)
    at controlP5.ControlWindow.draw(Unknown Source)
    at controlP5.ControlP5.draw(Unknown Source)
    at PBAI_Engine$VisGui.go(PBAI_Engine.java:3219)
    at PBAI_Engine.do_gui(PBAI_Engine.java:293)
    at PBAI_Engine.draw(PBAI_Engine.java:260)
    at processing.core.PApplet.handleDraw(PApplet.java:2476)
    at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:866)
    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)

Here are the lines that seem to be causing the problem:

myConsole = vgui.addTextarea("txt")
                  .setPosition(50, 550)
                  .setSize(600, 200)
                  .setFont(new ControlFont(gill, 12))    // createFont("gill", 10))
                  .setLineHeight(14)
                  .setColor(color(200))
                  .setColorBackground(color(0, 100))
                  .setColorForeground(color(255, 100));
  ;

     console = vgui.addConsole(myConsole) // if this line is removed, the index out of bounds exception goes away
                   .setMax(50); 

This issue only happens on Windows computers but never on MacOS computers. Thank you!

mgorbet commented 5 years ago

PS - "console" in the above example is an instance of controlP5 Println:

class VisGui {

  Textarea myConsole;
  Println console; 
  ButtonBar bar;
...

And I'll reiterate that this all works perfectly on MacOS X but not on any Windows machines, oddly.

(Also, we've tried different fonts, sizes etc. and it doesn't seem to make a difference).