Author Topic: Problem with AWTGLRenderer  (Read 5936 times)

Offline JavaMan

  • long
  • ***
  • Posts: 231
    • View Profile
Problem with AWTGLRenderer
« on: March 07, 2008, 12:44:35 am »
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.
Quote
import 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]
« Last Edit: March 07, 2008, 12:50:08 am by JavaMan »

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Re: Problem with AWTGLRenderer
« Reply #1 on: March 07, 2008, 01:23:02 am »
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

Offline JavaMan

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Problem with AWTGLRenderer
« Reply #2 on: March 07, 2008, 01:26:10 am »
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...
« Last Edit: March 07, 2008, 02:19:44 am by JavaMan »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Problem with AWTGLRenderer
« Reply #3 on: March 07, 2008, 07:47:28 am »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Problem with AWTGLRenderer
« Reply #4 on: March 07, 2008, 07:55:18 am »
This one works for me:

Code: [Select]
   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?

Offline JavaMan

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Problem with AWTGLRenderer
« Reply #5 on: March 07, 2008, 09:25:48 pm »
With that code, it still crashes right when I try to remove the canvas. It even crashes when I try to remove the JPanel.

Quote
BTW: 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.
« Last Edit: March 07, 2008, 09:27:43 pm by JavaMan »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Problem with AWTGLRenderer
« Reply #6 on: March 07, 2008, 09:43:47 pm »
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?

Offline JavaMan

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Problem with AWTGLRenderer
« Reply #7 on: March 08, 2008, 12:05:23 am »
Quote
Which 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.

Quote
Does 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.
« Last Edit: March 08, 2008, 12:08:06 am by JavaMan »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Problem with AWTGLRenderer
« Reply #8 on: March 08, 2008, 11:46:40 am »
Maybe trying to add a sleep between making it invisible and actually removing it may help!?

Offline JavaMan

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Problem with AWTGLRenderer
« Reply #9 on: March 09, 2008, 02:11:05 am »
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:)
« Last Edit: March 09, 2008, 02:12:49 am by JavaMan »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Problem with AWTGLRenderer
« Reply #10 on: March 09, 2008, 10:42:08 am »
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... ;)