too many calls to popMatrix and issues generating text (Eclipse IDE)

I'm developing a Processing view (with v2.2.1 that still extends Applet). I use some pushMatrix()/popMatrix() to do transformations and to represent composite objects (I'm aware of the 32 depth matrix stack limit and relatively sure I don't reach that depth in composition and/or successive transformations or dont pair push and pops properly).

So far I didn't have any unexpected issue, but after introducing yet another component(not the first text enabled component at all), I'm starting to occasionally get errors like these:

The font size is too large to be properly displayed with OpenGL

Exception in thread "Animation Thread" java.lang.RuntimeException: Image width and height cannot be larger than 0 with this graphics card. at processing.opengl.Texture.setSize(Texture.java:1148) at processing.opengl.Texture.init(Texture.java:213) at processing.opengl.Texture.(Texture.java:160) at processing.opengl.FontTexture.addTexture(FontTexture.java:134) at processing.opengl.FontTexture.initTexture(FontTexture.java:103) at processing.opengl.FontTexture.(FontTexture.java:71) at processing.opengl.PGraphicsOpenGL.textLineImpl(PGraphicsOpenGL.java:3602) at processing.core.PGraphics.textLineAlignImpl(PGraphics.java:4659) at processing.core.PGraphics.text(PGraphics.java:4356) at processing.core.PGraphics.text(PGraphics.java:4307) at processing.core.PApplet.text(PApplet.java:13183) at ygg.desktop.vm.extVM.MetadataProcessingVM.render(MetadataProcessingVM.java:81) at ygg.desktop.vm.extVM.MetadataProcessingVM.render(MetadataProcessingVM.java:88) at ygg.desktop.vm.groups.TreeLayout.render(TreeLayout.java:43) at ygg.desktop.vm.groups.RenderArea.render(RenderArea.java:167) at ygg.desktop.view.MainView.draw(MainView.java:179) at processing.core.PApplet.handleDraw(PApplet.java:2386) at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240) at processing.core.PApplet.run(PApplet.java:2256) at java.lang.Thread.run(Thread.java:745) which refers to (note that I get it both on first and second text on different runs) *father is the PApplet instance

      father.pushMatrix();
      father.translate(posX, posY+8);

      father.rotate(-father.HALF_PI);

      father.fill(father.color(30,30,30));
      father.textAlign(father.CENTER);
      father.textSize(16);
      **father.text(md.getId()!=null?md.getId():"NONE",-(finalY-posY)/2,width/2);**
      father.fill(father.color(220,220,50));
      father.textSize(12);
      **father.text(md.getId()!=null?md.getId():"NONE",-(finalY-posY)/2,width/2);**

      father.popMatrix();

or

Exception in thread "Animation Thread" java.lang.RuntimeException: Too many calls to popMatrix(), and not enough to pushMatrix(). at processing.opengl.PGraphicsOpenGL.popMatrix(PGraphicsOpenGL.java:3811) at processing.core.PApplet.popMatrix(PApplet.java:13322) at ygg.desktop.vm.extVM.MetadataProcessingVM.render(MetadataProcessingVM.java:72) at ygg.desktop.vm.groups.TreeLayout.render(TreeLayout.java:43) at ygg.desktop.vm.groups.TreeLayout.render(TreeLayout.java:46) at ygg.desktop.vm.groups.TreeLayout.render(TreeLayout.java:46) at ygg.desktop.vm.groups.RenderArea.render(RenderArea.java:167) at ygg.desktop.view.MainView.draw(MainView.java:180) at processing.core.PApplet.handleDraw(PApplet.java:2386) at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240) at processing.core.PApplet.run(PApplet.java:2256) at java.lang.Thread.run(Thread.java:745) on

      father.pushMatrix();
      father.translate(posX, posY+8);
      father.rotate(-father.HALF_PI);
      father.fill(father.color(30,30,30));
      father.textAlign(father.CENTER);
      father.textSize(16);

      father.text(md.getId()!=null?md.getId():"NONE",-(finalY-posY)/2,width/2);
      father.fill(father.color(220,220,50));
      father.textSize(12);
      father.text(md.getId()!=null?md.getId():"NONE",-(finalY-posY)/2,width/2);      
      **father.popMatrix();**
}

I am no expert in OpenGl and/or Processing at all, so I was wondering how can successive executions (with no previous jvm left open) lead to different outcomes without any random element in my code (apparently if the application doesnt crash immediately it keeps working no matter how many objects I create), also I don't understand how can I get that exception on popMatrix right after a push given that all the calls are in the draw cycle and of course no thread (that I'm aware) there.

Before proceeding I would like to know what am I getting so wrong (if it as already transpired) and what could I do to achieve stability at each run, also I would like to know if multiple instances of PApplet clients will necessarly confict with each others.

Answers

  • The error says you are popping more than pushing. Without seeing your whole code, it is difficult or impossible to know how that is happening.

    If your code is complex, have your tried stepping through the code?

  • Search all your pop and push calls and double check them, make sure they aren't split by a condition or a loop.

    And the error being reported here can be misleading - this is only where the code has to give up, not necessarily where the error is.

  • Also -- what is 'md'? Are you accessing an object in another thread?

  • the application works fine sometimes, and i can populate the view with as many object as i want (if too many framerate will drop). but sometimes i get errors on the start.Immagine

    i dont understand how sometime it works and sometime not if i do the same, and i think i lack knowledge in opengl the most

  • What exactly is md? Are you using multithreading?

  • edited December 2016

    md is for "metadata" and its poorly represented on the right of the image. It should have vertical text on each node and links at the end of each leaf node. For testing purposes i had a structure where md instances where utilized in more than one branch (to populate the tree faster), now that i use proper data and i start with empty metadata im not having trouble anymore... i dont know if it is correlated to the initiation of the whole thing or what.

    So the code from before its cycled in a tree like manner and some of the md where the same istance as other, can this cause the problem?

    Just to be sure

    md belongs to model and has an array of itself and a location. the object(metadataVM) that represents it copy its structure by calling recursively its constructor. the treeLayout sets up the width height and positions of the previous visual composite object(metadataVM) in its constructor. the rendering process starts from treelayout and its propagated to each child. the only trasformation used here its the flip on the text while outside there is a clip area and then the PApplet

Sign In or Register to comment.