Author Topic: help on an LWJGL exception  (Read 8950 times)

Offline manumoi

  • long
  • ***
  • Posts: 121
    • View Profile
    • http://www.iro.umontreal.ca/~blanchae
help on an LWJGL exception
« on: July 27, 2005, 12:53:19 am »
hello my question is not a full jpct question but maybe...

I have a JPCT application with a panel showing a AWTGLCanvas and next to it a JEditorPane...

When clicking on some object in my JPCT panel, i ask  the JEditorPane to load different HTML Page at different url... It works fine 1 time, 2 times... and then i have this exception. I tried to look at LWJGL doc but i m not familiar. I don t fully undertand every processes acting when i do such operation... So, if anybody has an idea on how to deal with it, i would greatly appreciate....

here is the exception
Code: [Select]

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: From thread Thread[AWT-EventQueue-0,6,main]: Thread[AWT-EventQueue-0,6,] already has the
 context current
        at org.lwjgl.opengl.Context.checkAccess(Context.java:165)
        at org.lwjgl.opengl.Context.makeCurrent(Context.java:172)
        at org.lwjgl.opengl.AWTGLCanvas.paint(AWTGLCanvas.java:230)
        at org.lwjgl.opengl.AWTGLCanvas.update(AWTGLCanvas.java:248)
        at sun.awt.RepaintArea.updateComponent(Unknown Source)
        at sun.awt.RepaintArea.paint(Unknown Source)
        at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)

and here is the code of my picking method
Code: [Select]


  public void pickingObject(int mouseX, int mouseY){
SimpleVector ray=Interact2D.reproject2D3D(camera, buffer, mouseX, mouseY);
  int[] res=Interact2D.pickPolygon(theWorld.getVisibilityList(), ray);
if (res!=null) {
   Object3D pickedObj=theWorld.getObject(Interact2D.getObjectID(res));
     urlIndex++;
   theFrame.getMyHTMLPane().loadURL(urls[urlIndex%3]);
 }
    }


loadURL method is a call to the setPage(String s) method of JEditorPane

Thanks

Manu

Offline manumoi

  • long
  • ***
  • Posts: 121
    • View Profile
    • http://www.iro.umontreal.ca/~blanchae
help on an LWJGL exception
« Reply #1 on: July 27, 2005, 01:57:55 am »
Ok I didn t fix this problem but i remarked that when my HTML file are local, the problem doesn't occur... And in my app, files are supposed to be local so i m lucky.... But if someone has an idea on how to deal with this exception, i m still interested by it.

Manu.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
help on an LWJGL exception
« Reply #2 on: July 27, 2005, 08:02:15 am »
This usually happens if the awt event dispatch thread bails out for some reason, i.e. it's not the cause of a problem but the consequence. There should be another exception of some kind (for example in an overridden paint() method). Try to log StdErr into a file if you are having problems to spot this on the console (i.e. 2>myfile.txt)

Offline manumoi

  • long
  • ***
  • Posts: 121
    • View Profile
    • http://www.iro.umontreal.ca/~blanchae
hello
« Reply #3 on: February 15, 2006, 11:14:58 pm »
Back with a new LWJGL AWTGLCanvas exception...
I have an application that runs correctly on many different computers but on some others, i have the following exception just after loading an md2 model (all are using winXP) What i don t understand... it s that my application worked on the same computer with a previous version of jpct(1.07) and LWJGL (0.93... or something like that). I change the version in order to fix another exception that looped with the previous version of LWJGL. It is fixed now and  I am currently using the lattest downloadable version of JPCT and the version 0.99 of LWJGL. There has also been some updates on the config of the computer but I don t think those are significative changes. The current video card is a rage 128 pro AGP 4X TMDS but the driver is quite old (microsoft, march 2001)...
Any idea concerning where this error comes from and if it can be bypassed without having to change the config (i don t have such right on this computer).

Thanks

Manu

Code: [Select]

Loading file R:\JAVA\projets\multi\world\models\players\alita\tris.md2
File R:\JAVA\projets\multi\world\models\players\alita\tris.md2 loaded...312396 b
ytes
Magic number: 844121161
Version: 8
Skin width: 256
Skin height: 256
Frame size: 1460
Number of skins: 0
Number of Vertices: 355
Number of Texture coordinates: 346
Number of triangles: 688
Number of GL-commands: 3402
Number of Frames: 198
Reading Texture coordinates...
Done!
Reading polygonal data...
Done!
Reading keyframes...
Done!
Coverting MD2-format into jPCT-format...
Processing: stand...
Processing: run...
Processing: attack...
Processing: pain...
Processing: jump...
Processing: flip...
Processing: salute...
Processing: taunt...
Processing: wave...
Processing: point...
Processing: crstand...
Processing: crwalk...
Processing: crattack...
Processing: crpain...
Processing: crdeath...
Processing: death...
Done!
Loading Texture...R:\JAVA\projets\multi\world\models\players\alita\alita2.jpg
Adding Lightsource: 0
apres camera
fin
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: org.lwjgl.LWJ
GLException: Could not find a valid pixel format
        at org.lwjgl.opengl.AWTGLCanvas.paint(AWTGLCanvas.java:261)
        at sun.awt.RepaintArea.paintComponent(Unknown Source)
        at sun.awt.RepaintArea.paint(Unknown Source)
        at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: org.lwjgl.LWJGLException: Could not find a valid pixel format
        at org.lwjgl.opengl.Win32PeerInfo.nChoosePixelFormat(Native Method)
        at org.lwjgl.opengl.Win32PeerInfo.choosePixelFormat(Win32PeerInfo.java:5
2)
        at org.lwjgl.opengl.Win32AWTGLCanvasPeerInfo.doLockAndInitHandle(Win32AW
TGLCanvasPeerInfo.java:59)
        at org.lwjgl.opengl.PeerInfo.lockAndGetHandle(PeerInfo.java:85)
        at org.lwjgl.opengl.AWTGLCanvas.paint(AWTGLCanvas.java:245)
        ... 11 more

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
help on an LWJGL exception
« Reply #4 on: February 15, 2006, 11:38:47 pm »
The AWTGLRenderer asks for a pixel format with no special requirements (LWJGL's default pixel format...see the LWJGL Javadocs for details). I've no clue why such format isn't available on your setup. A shot in the dark: What's your desktop's color depth? If it's 24bit, try 16 and vice versa. Another thing you can try: What video modes does
Code: [Select]

FrameBuffer.getVideoModes(IRenderer.RENDERER_OPENGL);

return? These are not the modes that i'm using for initializing the AWTGLCanvas (as said, i'm not specifying anything special, so every mode should do), but it could be helpful to see if LWJGL gets some valid modes at all.

Offline manumoi

  • long
  • ***
  • Posts: 121
    • View Profile
    • http://www.iro.umontreal.ca/~blanchae
help on an LWJGL exception
« Reply #5 on: February 16, 2006, 01:39:28 am »
hello Egon, as usual, very quick to answer  :P

I checked the video modes. There are many different ones either with 16 or 32 bits depth (never 24). I also tried to split from 32 to 16 on the desktop. No results.
I checked the car and FPS demo on the same computer. Both work but i suppose they are not using AWTGLRenderer.  Is There a demo with an AWTGLCanvas that i could test?
I tried to modify Config (glColorDepth set to 16, 24 and 32) no results...
I join some of my initialization code... maybe i m doing something wrong...

Code: [Select]

public WorldInterface(String [] args, String mapName, VirtualLearning vl){
[...]
this.setSize(width, height);
try{
       Config.glRefresh=0;
   Config.glMipmap=true;
   World.setDefaultThread(Thread.currentThread());
   buffer = new FrameBuffer(width, height, FrameBuffer.SAMPLINGMODE_NORMAL);
   buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
   myCanvas=buffer.enableGLCanvasRenderer(IRenderer.MODE_OPENGL);
System.out.println("VIDEO MODE");
VideoMode []v = buffer.getVideoModes(IRenderer.RENDERER_OPENGL);
for (int i=0; i<v.length;i++)
System.out.println(v[i]);
   this.add(myCanvas);
   Config.maxPolysVisible = 50000; // max number of polygons that can be shown
   keyMapper = new KeyMapper(myCanvas);
   theWorld = new World();
   texMan = TextureManager.getInstance();
   this.setupLighting();
   this.setupFog();
   this.loadingTerrain(mapName+Constants.SEP);
   [...]
   this.setupCamera();
   Config.tuneForOutdoor();
   new Thread() {
public void run() {
   myCanvas.addMouseListener(new WorldInterfaceMouseListener());
   myCanvas.addMouseMotionListener(new WorldInterfaceMouseMotionListener());
}
   }.start();
}
catch (Exception e){
System.err.println("WorldInterface constructor");
e.printStackTrace();
   this.exit();
}
    }  

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
help on an LWJGL exception
« Reply #6 on: February 16, 2006, 08:28:25 am »
Looks fine to me, albeit but i don't get why you are setting the listeners in a Thread, but anyway...as said, i'm not requesting anything special and i'm ignoring glColor... etc. for the AWTGLRenderer, so i think that the problem is inside LWJGL. Here a little program that you can test: http://www.jpct.net/download/carbench.zip
It has a st_opengl.bat which uses the GLRenderer and mt_opengl.bat which uses the AWTGLRenderer. I expect the first to run and the second to fail then.

Offline manumoi

  • long
  • ***
  • Posts: 121
    • View Profile
    • http://www.iro.umontreal.ca/~blanchae
help on an LWJGL exception
« Reply #7 on: February 16, 2006, 11:01:54 pm »
hum hum
Both versions don`t work and show the similar exception... Here are the error log (slightly different). I just modified your .bat file in order to use java and to see the errors. It failed with LWJGL 0.97 so i tried it with the 0.99.. Same results excepted that with the 0.97, on the MT_OPENGL version, the exception is thrown in loop whereas with the 0.99 it occurs only one time (but it s not related to my main problem) and block...

I was surprised so i come back with the car demo (in the package) and try to switch to openGL mode... And it failed due to the expected exception... So i suppose that this computer doesn t support OpenGL anymore (it worked in the past)... And i have some plans about killing all the technical support of my university... What  do you prefer? a chainsaw? a shotgun? or an axe?

 :evil:  :evil:  :evil:  :evil:  (lost two days on that bug !!!!)

Offline manumoi

  • long
  • ***
  • Posts: 121
    • View Profile
    • http://www.iro.umontreal.ca/~blanchae
help on an LWJGL exception
« Reply #8 on: February 16, 2006, 11:02:59 pm »
back again, i don t post the logs since i know the problem now  :evil:

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
help on an LWJGL exception
« Reply #9 on: February 16, 2006, 11:08:00 pm »
IF the driver is really from Microsoft, it's very likely that it doesn't support OpenGL. Microsoft's own drivers usually never do...

Offline manumoi

  • long
  • ***
  • Posts: 121
    • View Profile
    • http://www.iro.umontreal.ca/~blanchae
help on an LWJGL exception
« Reply #10 on: February 28, 2006, 09:48:07 pm »
Hello Egon,

I come back with the first error i mentioned on this thread (the IllegalStateException). It occured very unfrequently so i didn t check it  until now.
It seems there may be a small problem with the pickPolygon method of Interact2D

Here is the error log
Code: [Select]

Exception in thread "AWT-EventQueue-0" Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 10964
at com.threed.jpct.Interact2D.pickPolygon(Unknown Source)
at com.threed.jpct.Interact2D.pickPolygon(Unknown Source)
at multi.world.WorldInterface.picking(WorldInterface.java:253)
at multi.world.WorldInterface$WorldInterfaceMouseMotionListener.mouseMoved(WorldInterface.java:378)
at java.awt.Component.processMouseMotionEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: From thread Thread[AWT-EventQueue-0,6,main]: Thread[AWT-EventQueue-0,6,main] already has the context current
at org.lwjgl.opengl.Context.checkAccess(Context.java:169)
at org.lwjgl.opengl.Context.makeCurrent(Context.java:176)
at org.lwjgl.opengl.AWTGLCanvas.paint(AWTGLCanvas.java:251)
at org.lwjgl.opengl.AWTGLCanvas.update(AWTGLCanvas.java:269)
at sun.awt.RepaintArea.updateComponent(Unknown Source)
at sun.awt.RepaintArea.paint(Unknown Source)
at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


And here is the line 253 of my program

Code: [Select]

  SimpleVector ray = Interact2D.reproject2D3D(camera, buffer, mX, mY); // mX and mY are the coordinates of the mouse pointer
  int[] res=Interact2D.pickPolygon(theWorld.getVisibilityList(), ray); // line 253




The number afte arrayIndexOutOfBound exception is never the same. I suppose it must refer to a polygon that doesn't exist or something like that.
The error occurs when i try to pick an md2 model (it occurs for different models). The md2 models I use  are taken from http://www.planetquake.com/polycount/ (i can mail them to you if you need it for tests).

Manu

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
help on an LWJGL exception
« Reply #11 on: February 28, 2006, 10:22:57 pm »
Could be a threading issue, because you are accessing the visibility list in one thread (the AWT event thread) triggered by the mouse click but updating it in another one (your actual "game loop"-thread). From time to time, this may make you pick garbage (an half updated vislist for example). Try to store the picking coordinates when the click happens but execute the actual picking in the game loop and see if the problem goes away.

Edit: Whether or not this is the actual problem in this case, it's never a good idea to work on jPCT's objects from outside the game loop thread. It's much better to queue the events and execute them in the game loop. It will save you from lots of almost impossible to debug problems.

Offline manumoi

  • long
  • ***
  • Posts: 121
    • View Profile
    • http://www.iro.umontreal.ca/~blanchae
help on an LWJGL exception
« Reply #12 on: February 28, 2006, 11:09:10 pm »
Thanks for the methodology... The problem doesn t seem to occur anymore... And thanks for the advice also. I wasn t so familiar with the thread process behind awt events... And now i understand many things  8)

I should build a statue in your honor Egon  :P