Drawing more than a certain number of triangles at one time/method/stack crash
Posted by loremipsum on Dec 14, 2015; 11:47pm
URL: https://forum.jogamp.org/Drawing-more-than-a-certain-number-of-triangles-at-one-time-method-stack-crash-tp4035900.html
I have a GLJPanel with swing components (JInternalPane renders beautifully on top). On render, the parent container/gl event listener (JDesktopPane) calls the game's render, which calls the level's render. Inside the level's render, I have about 24,000 float vertices waiting to be drawn. Cutting the for loop short by a few thousand vertices seems to not crash, but rendering all of them does. Other than that, everything seems to work.
SO.. when I go over, I get spammed with this crap (again, Swing DispatchThread woes -.-):
java.lang.reflect.InvocationTargetException
at java.awt.EventQueue.invokeAndWait(EventQueue.java:1086)
at java.awt.EventQueue.invokeAndWait(EventQueue.java:1063)
at javax.swing.SwingUtilities.invokeAndWait(SwingUtilities.java:1326)
at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:98)
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:512)
at java.util.TimerThread.run(Timer.java:462)
Caused by: com.jogamp.opengl.GLException: Error making context 0x20001 current on Thread AWT-EventQueue-0, drawableWrite 0xffffffff8c010bb9, drawableRead 0xffffffff8c010bb9, werr: -1073282985, WindowsWGLContext [Version 2.1 (Compat profile, compat[], FBO, hardware) - 2.1.1 [GL 2.1.0, vendor 0.0.0 (n/a)], options 0x4002, this 0x78482bad, handle 0x20001, isShared false, jogamp.opengl.gl4.GL4bcImpl@3821b42f,
quirks: [NoDoubleBufferedBitmap, NoSurfacelessCtx],
Drawable: ResizeableImpl[Initialized true, realized true, texUnit 0, samples 0,
Factory jogamp.opengl.windows.wgl.WindowsWGLDrawableFactory@2cbc9673,
Handle 0xffffffff8c010bb9,
Caps GLCaps[wgl vid 7 arb: rgba 8/8/8/0, opaque, accum-rgba 0/0/0/0, dp/st/ms 16/0/0, one, mono , hw, GLProfile[GL2/GL2.hw], offscr[fbo]],
fboI back 0, front 0, num 1,
FBO front read 1, FBO[name r/w 1/1, init true, bound false, size 1440x900, samples 0/16, modified false/false, depth RenderAttachment[type DEPTH, format 0x81a5, samples 0, 1440x900, name 0x1, obj 0x51a422f6], stencil null, colorbuffer attachments: 1/8, with 1 textures: [TextureAttachment[type COLOR_TEXTURE, target GL_TEXTURE_2D, level 0, format 0x8051, 1440x900, border 0, dataFormat 0x1907, dataType 0x1401; min/mag 0x2600/0x2600, wrap S/T 0x812f/0x812f; name 0x1, obj 0x11396ef7], null, null, null, null, null, null, null], msaa[null, hasSink false, dirty true], state OK, obj 0x6ef36e59],
FBO back write 1, FBO[name r/w 1/1, init true, bound false, size 1440x900, samples 0/16, modified false/false, depth RenderAttachment[type DEPTH, format 0x81a5, samples 0, 1440x900, name 0x1, obj 0x51a422f6], stencil null, colorbuffer attachments: 1/8, with 1 textures: [TextureAttachment[type COLOR_TEXTURE, target GL_TEXTURE_2D, level 0, format 0x8051, 1440x900, border 0, dataFormat 0x1907, dataType 0x1401; min/mag 0x2600/0x2600, wrap S/T 0x812f/0x812f; name 0x1, obj 0x11396ef7], null, null, null, null, null, null, null], msaa[null, hasSink false, dirty true], state OK, obj 0x6ef36e59],
Surface GDISurface[ displayHandle 0x0
, surfaceHandle 0xffffffff8c010bb9
, size 1440x900
, UOB[ OWNS_SURFACE | OWNS_DEVICE | WINDOW_INVISIBLE ]
, WindowsWGLGraphicsConfiguration[DefaultGraphicsScreen[WindowsGraphicsDevice[type .windows, connection decon, unitID 0, handle 0x0, owner false, NullToolkitLock[obj 0x2fd1cdf7]], idx 0], pfdID 7, ARB-Choosen true,
requested GLCaps[rgba 8/8/8/0, opaque, accum-rgba 0/0/0/0, dp/st/ms 16/0/0, one, mono , hw, GLProfile[GL2/GL2.hw], on-scr[.]],
chosen GLCaps[wgl vid 7 arb: rgba 8/8/8/0, opaque, accum-rgba 0/0/0/0, dp/st/ms 16/0/0, one, mono , hw, GLProfile[GL2/GL2.hw], offscr[fbo]]]
, surfaceLock <77292ba7, 2ff11e0f>[count 1, qsz 0, owner <AWT-EventQueue-0>]
, GDIDummyUpstreamSurfaceHook[pixel 1440x900]
, upstreamSurface false ]]]
at jogamp.opengl.windows.wgl.WindowsWGLContext.makeCurrentImpl(WindowsWGLContext.java:442)
at jogamp.opengl.GLContextImpl.makeCurrentWithinLock(GLContextImpl.java:840)
at jogamp.opengl.GLContextImpl.makeCurrent(GLContextImpl.java:648)
at jogamp.opengl.GLContextImpl.makeCurrent(GLContextImpl.java:586)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1279)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
at com.jogamp.opengl.awt.GLJPanel$OffscreenBackend.doPaintComponent(GLJPanel.java:2095)
at com.jogamp.opengl.awt.GLJPanel.paintComponent(GLJPanel.java:569)
at javax.swing.JComponent.paint(JComponent.java:1037)
at javax.swing.JComponent.paintChildren(JComponent.java:870)
at javax.swing.JComponent.paint(JComponent.java:1046)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:567)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5132)
at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:278)
at javax.swing.RepaintManager.paint(RepaintManager.java:1257)
at javax.swing.JComponent._paintImmediately(JComponent.java:5080)
at javax.swing.JComponent.paintImmediately(JComponent.java:4890)
at javax.swing.RepaintManager$3.run(RepaintManager.java:814)
at javax.swing.RepaintManager$3.run(RepaintManager.java:802)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:802)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:745)
at com.jogamp.opengl.util.AWTAnimatorImpl$1.run(AWTAnimatorImpl.java:170)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:672)
at java.awt.EventQueue.access$400(EventQueue.java:81)
at java.awt.EventQueue$2.run(EventQueue.java:633)
Here's the code:
This doesn't work:
gl2.glBegin(GL2.GL_TRIANGLES);
for (int i = 0; i < terrainTris.length-6; i+=6) {
gl2.glVertex3f(terrainTris[i].x, terrainTris[i].y, terrainTris[i].z);
gl2.glVertex3f(terrainTris[i+1].x, terrainTris[i+1].y, terrainTris[i+1].z);
gl2.glVertex3f(terrainTris[i+2].x, terrainTris[i+2].y, terrainTris[i+2].z);
gl2.glVertex3f(terrainTris[i+3].x, terrainTris[i+3].y, terrainTris[i+3].z);
gl2.glVertex3f(terrainTris[i+4].x, terrainTris[i+4].y, terrainTris[i+4].z);
gl2.glVertex3f(terrainTris[i+5].x, terrainTris[i+5].y, terrainTris[i+5].z);
}
gl2.glEnd();
This doesn't work:
for (int i = 0; i < terrainTris.length-200; i+=6) {
This, however, DOES work:
for (int i = 0; i < terrainTris.length-2000; i+=6) {
What gives? I tried calling the GLJPanel's paint, repaint and display; in many ways: separate thread, separate thread with sleep, same thread with FPSAnimator, different thread with FPSAnimator, etc, etc.
Am I running out of memory? If so, how can I avoid this? Would VBOs help in any way?