From: Mark M. <pat...@lm...> - 2002-02-18 16:16:56
|
Hi Elias, We also struggled with getting all the calls in just the right order to make GL4Java happy (or any Java binding for OpenGL for that matter). Here is what I learned.... There are several basic rules of the game you have to follow when making an app like this. 1) Create your Frame (parent component) 2) Create a class "Foo" that inherits from Panel (not necessary, but I like this approach) 3) In "Foo" define a member variable of type GLDrawable (this will hold the GLAnimCanvas) 4) In "Foo" define your capabilities, then create the GLAnimCanvas (ALWAYS, ALWAYS use the GLDrawableFactory.getFactory() as you did below) 5) Add the GLDrawable to the LayoutManager in "Foo" 6) Create a class "Bar" that implements GLEventListener 7) Add "Bar" as the GLEventListener for your GLDrawable 8) Now make your Frame, Panel, GLDrawable all visible with setVisible(true) **NOTE: Once the components become visible, the GLAnimCanvas will receive its first "display()" call through a GLEvent. When this first display occurs, I believe that GL4Java finally makes the GLContext (OpenGL state machine). NOW, and only now will the context be non-null. 9) Finally, you are allow to call getGLContext().gljMakeCurrent(), OR gl.gl****() ** NOTE: If you intend to make display list before the GLDrawable is visible (and before the GLContext is created), then don't! ;-) We learned this the hard way. Put your display list creating in the init() method of the GLEventListener. This init() method gets called after the components are visible and the GLContext is created and ready to be used. Hope this helps. -mark Elias Naur wrote: > Hi, > > I've recently begun using GL4Java, but I have run into problems with Gl4Java > sometimes (~ every 10 times) hanging at startup, my startup code looks like > this > > frame.setVisible(true); > GLCapabilities caps = new GLCapabilities(true, false, true, 0, 0, 0, > 0, 0); > canvas = GLDrawableFactory.getFactory().createGLAnimCanvas(caps, > Globals.VIEW_WIDTH, Globals.VIEW_HEIGHT); > canvas.setUseRepaint(false); > canvas.setUseFpsSleep(false); > canvas.setUseYield(false); > canvas.addGLEventListener(renderer); > frame.add(canvas, BorderLayout.CENTER); > frame.pack(); > > canvas.requestFocus(); > canvas.start(); > > If I move the line frame.sertVisible(true) further down (e.g. after > canvas.start()), it hangs less often. the thread dump while hanging looks > like this:Full thread dump Java HotSpot(TM) Client VM (1.4.0-b92 mixed mode): > > "AWT-EventQueue-0" prio=1 tid=0x0x81d2cf0 nid=0x2577 runnable > [4cee6000..4cee686c] > at gl4java.GLContext.openOpenGLNative(Native Method) > at gl4java.GLContext.gljInit(GLContext.java:1996) > - locked <0x441426a0> (a gl4java.GLContext) > at gl4java.GLContext.createGLContext(GLContext.java:1942) > at gl4java.GLContext.<init>(GLContext.java:1161) > at gl4java.GLContext.<init>(GLContext.java:1251) > at gl4java.awt.GLCanvas.paint(GLCanvas.java:444) > at sun.awt.RepaintArea.paint(RepaintArea.java:180) > at sun.awt.motif.MComponentPeer.handleEvent(MComponentPeer.java:339) > at java.awt.Component.dispatchEventImpl(Component.java:3586) > at java.awt.Component.dispatchEvent(Component.java:3367) > at java.awt.EventQueue.dispatchEvent(EventQueue.java:445) > at > java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:190) > at > java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:144) > at > java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138) > at > java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:130) > at java.awt.EventDispatchThread.run(EventDispatchThread.java:98) > > "Thread-1" daemon prio=1 tid=0x0x81d53b8 nid=0x2576 waiting on monitor > [4ce65000..4ce6586c] > at java.lang.Object.wait(Native Method) > - waiting on <0x44170450> (a java.util.TaskQueue) > at java.util.TimerThread.mainLoop(Timer.java:429) > - locked <0x44170450> (a java.util.TaskQueue) > at java.util.TimerThread.run(Timer.java:382) > > "AWT-Motif" daemon prio=1 tid=0x0x81c2ef8 nid=0x2575 waiting for monitor > entry [4cde4000..4cde486c] > at sun.awt.motif.MToolkit.run(Native Method) > at java.lang.Thread.run(Thread.java:536) > > "AWT-Shutdown" prio=1 tid=0x0x819d550 nid=0x2574 waiting on monitor > [4cd63000..4cd6386c] > at java.lang.Object.wait(Native Method) > - waiting on <0x4461a478> (a java.lang.Object) > at java.lang.Object.wait(Object.java:426) > at sun.awt.AWTAutoShutdown.run(AWTAutoShutdown.java:259) > - locked <0x4461a478> (a java.lang.Object) > at java.lang.Thread.run(Thread.java:536) > > "Signal Dispatcher" daemon prio=1 tid=0x0x807b880 nid=0x2572 waiting on > monitor [0..0] > > "Finalizer" daemon prio=1 tid=0x0x8074478 nid=0x256f waiting on monitor > [4c2f2000..4c2f286c] > at java.lang.Object.wait(Native Method) > - waiting on <0x445ef168> (a java.lang.ref.ReferenceQueue$Lock) > at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:111) > - locked <0x445ef168> (a java.lang.ref.ReferenceQueue$Lock) > at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:127) > at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159) > > "Reference Handler" daemon prio=1 tid=0x0x8073830 nid=0x256e waiting on > monitor [4c271000..4c27186c] > at java.lang.Object.wait(Native Method) > - waiting on <0x445ef1d0> (a java.lang.ref.Reference$Lock) > at java.lang.Object.wait(Object.java:426) > at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:113) > - locked <0x445ef1d0> (a java.lang.ref.Reference$Lock) > > "main" prio=1 tid=0x0x8051558 nid=0x256b waiting for monitor entry > [bfffd000..bfffd718] > at sun.awt.motif.MComponentPeer.pReshape(Native Method) > at sun.awt.motif.MComponentPeer.setBounds(MComponentPeer.java:739) > at java.awt.Component.reshape(Component.java:1685) > - locked <0x44619fb0> (a java.awt.Component$AWTTreeLock) > at java.awt.Component.setBounds(Component.java:1644) > at java.awt.BorderLayout.layoutContainer(BorderLayout.java:683) > - locked <0x44619fb0> (a java.awt.Component$AWTTreeLock) > at java.awt.Container.layout(Container.java:835) > at java.awt.Container.doLayout(Container.java:825) > at java.awt.Container.validateTree(Container.java:903) > at java.awt.Container.validate(Container.java:878) > - locked <0x44619fb0> (a java.awt.Component$AWTTreeLock) > at java.awt.Window.pack(Window.java:418) > at life3d.Main.run(Main.java:73) > at life3d.Main.main(Main.java:102) > > "VM Thread" prio=1 tid=0x0x80706b0 nid=0x256d runnable > > "VM Periodic Task Thread" prio=1 tid=0x0x807a390 nid=0x2570 waiting on monitor > "Suspend Checker Thread" prio=1 tid=0x0x807ae08 nid=0x2571 runnable > > it looks like that every time (hang in openOpenGLNative()) > > I use red hat linux 7.2 with 2.4.17 kernel and nvidia drivers 2314. JVM > version is 1.4.0 and GL4Java version is 2.8.2.0 > > someone has advice? how can I pinpoint it even further? i.e. how can I > easily tell in which line in openOpenGLNative my app hangs? > > - Elias Naur > > _______________________________________________ > gl4java-usergroup mailing list > gl4...@li... > https://lists.sourceforge.net/lists/listinfo/gl4java-usergroup |