Problem with AWTGLRenderer

Started by JavaMan, March 07, 2008, 12:44:35 AM

Previous topic - Next topic

JavaMan

Hi, I am trying to get a program to render into a Canvas with the GLRenderer, and then when the container around the Canvas becomes bigger, I need to remove the canvas from its container, create a new framebuffer, and add the new canvas from the framebuffer into the container where the old canvas was. I have everything working up to the point where the canvas is removed. Whenver I try to remove the canvas, the program crashes: no exception or anything just Windows tells me java.exe has caused an error and needs to close. I created some code that is like my real code, and creates the crash.
Quoteimport java.awt.*;
import javax.swing.*;
import com.threed.jpct.*;
class CanTest {

   public static void main(String args[]){
   final JPanel top = new JPanel();

   World w = new World();
   Object3D o = new Object3D(200);
   o.addTriangle(new SimpleVector(0,0,0),new SimpleVector(0,300,0),new SimpleVector(300,0,0));
   o.build();
   w.addObject(o);
   w.setAmbientLight(200,200,200);
   w.newCamera();
   Camera cam = w.getCamera();
   cam.moveCamera(Camera.CAMERA_MOVEOUT,100);
   
   JFrame f = new JFrame();
   f.setLayout(new GridLayout(1,1));
   f.add(top);
   f.setVisible(true);
   f.setSize(500,500);
   top.setBackground(Color.blue);
        try{ Thread.sleep } catch(Exception e){}
   FrameBuffer b = new FrameBuffer(top.getWidth(),top.getHeight(),FrameBuffer.SAMPLINGMODE_NORMAL);
   final Canvas c = b.enableGLCanvasRenderer();
   b.disableRenderer(IRenderer.RENDERER_SOFTWARE);
   top.setLayout(new GridLayout(1,1));
   top.add(c);
   int i = 0;
   i=0;
   while(i<5000){
         b.clear();
         //System.out.println("RENDERSCENE");
         w.renderScene(b);
         //System.out.println("DRAW");
         w.draw(b);
         //System.out.println("UPDATE");
         b.update();
         //System.out.println("GLONLY");
         b.displayGLOnly();
         //System.out.println("CANVAS__REPAINT");
         c.repaint();
         System.out.println("" + ++i);
   }
   b.dispose();
         FrameBuffer framebuffer =new FrameBuffer(top.getWidth(),top.getHeight(),FrameBuffer.SAMPLINGMODE_NORMAL);   
         System.out.println("E");
         System.out.println("l1");
            framebuffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
   System.out.println("About to crash...");
   /** Uncommenting the line below makes the program crash. */
   //top.remove(c);
   
   /**It doesn't matter is you try this. Still the same result: a crash*/
   /*
   SwingUtilities.invokeLater(new Runnable(){
      public void run(){
         top.remove(c);
      }
   });
   */
   }
}

Anybody, know why this happens? ???
JMan

I tried this little program on another computer, and the jre printed out this message before exiting the program, but windows didn't put up that error dialog
Quote
About to crash...
#
# An unexpected error has been detected by Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x696a0508, pid=3752, tid=2748
#
# Java VM: Java HotSpot(TM) Client VM (1.6.0_03-b05 mixed mode, sharing)
# Problematic frame:
# C  [nvoglnt.dll+0x1a0508]
#
# An error report file with more information is saved as hs_err_pid3752.log
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
#

[error occurred during error reporting, step 270, id 0xc0000005]

Melssj5

I am having the same problem when trying to quit my jpct app. In fact I guess that many people has this problem when trying to quit jpct apps since using java 6. I guess is an issue when trying to remove the buffer or the world or something. IDK how to fix it.
Nada por ahora

JavaMan

#2
Quote
In fact I guess that many people has this problem when trying to quit jpct apps since using java 6.
Huh,thats weird. Maybe I'll try it out with jre 1.5 instead.


I tried out the program with 1.5: the app runs slower and crashes. Joy...

EgonOlsen

There is one problem (but not limited to Java6) when quitting jPCT apps on some GeForce cards, that causes the VM to write a dump. I have no idea where it comes from and you can usually avoid it by simply doing a System.exit(0) at the end without disabling the renderer. It's a hard way to exit but it usually works. I have no idea what causes this...i've already tried a lot of things but to no avail.

However, i don't think that this is the problem here. Have you tried to switch top.remove(c) and b.dispose()? I'm not sure if the canvas is still valid after disposing the FrameBuffer.

EgonOlsen

This one works for me:


   top.remove(c);
   b.disableRenderer(IRenderer.RENDERER_OPENGL);
   b.dispose();
         FrameBuffer framebuffer =new FrameBuffer(top.getWidth(),top.getHeight(),FrameBuffer.SAMPLINGMODE_NORMAL);   
         System.out.println("E");
         System.out.println("l1");
            framebuffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
   System.out.println("About to crash...");
   System.exit(0);


BTW: What is the purpose of the new FrameBuffer instance in that code?

JavaMan

#5
With that code, it still crashes right when I try to remove the canvas. It even crashes when I try to remove the JPanel.

QuoteBTW: What is the purpose of the new FrameBuffer instance in that code?

I forgot that to go to software rendering all I have to do is call disableRenderer(...). I was going to create a whole new FrameBuffer.  ??? Also, I put that new FrameBuffer in the wrong spot; it should go after removing the canvas. This isn't my real code, just what my code does.

I wonder if it is something with the lwjgl, because removing a non-gl-canvas from a jpanel works fine.

EgonOlsen

Which LWJGL version are you using? It obviously crashes inside the Nvidia OGL driver, but i'm, not sure if this is really related to LWJGL alone. Does it help to make the JPanel invisible before trying to remove the canvas?

JavaMan

#7
QuoteWhich LWJGL version are you using?

I tried out using jpct1.15 and lwjgl that came with it as well as jpct1.16 and its lwjgl.

QuoteDoes it help to make the JPanel invisible before trying to remove the canvas?

Unfortunately, not; well at least not all the time. Before I tried that out, the it always crashed. Now it only crashes sometimes. ??? And other times, it removes it and all goes well.

Also, if this helps any, I tried out creating a AWTGLCanvas(with the lwjgl AWTGLCanvas constructor) and adding it to the panel. I used the software renderer to render into it, and that worked fine along with removing it.

EgonOlsen

Maybe trying to add a sleep between making it invisible and actually removing it may help!?

JavaMan

#9
No, that doesn't do anything. This is so weird. When I first run the program, like after the pc has been rebooted, it removes the canvas without any problems, but upon running it the second time: bang the error.

I ran it on a different laptop than I have been using and it runs ok.

I think I'll just use the GL renderer, instead of trying to support both. Maybe in a new version of lwjgl this will be worked out.  ::) Thanks for the help:)

EgonOlsen

Yes, sticking with one renderer might be the better solution. Or let the user decide when starting the application or restart the application after a change. Some games do it in the same way...there has to be a reason for this... ;)