2016-12-11 35 views
0

我正在開發一個處理視圖(v2.2.1仍然擴展Applet)。我使用一些pushMatrix()/ popMatrix()做轉換和表示複合對象(我知道32深度矩陣堆棧限制,並相對確定我沒有達到組合和/或連續轉換的深度或不要雙推和正確彈出)。處理太多的調用popMatrix

到目前爲止,我沒有任何意外問題,但引入另一個組件(不是第一個文本啓用的組件在所有)之後,我開始偶爾出現錯誤這樣的:

字體大小過大到用OpenGL

異常正確顯示在線程「動畫線程」了java.lang.RuntimeException: 圖像的寬度和高度不可能是大於0與此圖形 卡。 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) 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)

是指(請注意,我把它都在第一和第二文本在不同的運行)*父親是PApplet實例

  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(); 

在線程異常「動畫主題的」 java。 lang.RuntimeException:太多 許多調用popMatrix(),並不足以pushMatrix()。在 處處理.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。 ygg.desktop.view.MainView.draw(MainView.java:180)在 ygg.desktop.vm.groups.RenderArea.render(RenderArea.java:167) ygg.desktop.view.MainView.draw(MainView.java:180)在 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)

  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();** 
    } 

我在OpenGL和/或處理方面的專家,在所有的,所以我不知道如何可以連續執行(以前沒有JVM懸空)導致不同的結局,而不我的代碼中的任何隨機元素(顯然,如果應用程序不立即崩潰,無論我創建了多少個對象,它都會繼續工作),我也不會erstand在給定所有調用都處於繪製週期並且當然沒有線程(我知道)的情況下,我怎麼才能在popMatrix上獲得該異常。

在繼續之前,我想知道我的錯誤是什麼(如果它已經發生了),我該怎麼做才能在每次運行中實現穩定性,我想知道是否需要多個PApplet客戶端實例互相交流。

回答

1

如果沒有完整的代碼列表,很難指出所有的錯誤。

從您發佈的內容看,您看起來像有不成對的pushMatrix()/ popMatrix()調用。對於每個pushMatrix()操作,當完成局部座標系轉換時,您將需要一個popMatrix()。

請務必閱讀2D Transformations Processing tutorial瞭解更多詳情。