Org.lwjgl.LWJGLException: SetPixelFormat failed (0)

can any kind soul shed light on the below exception? this appeared the first time i tried to test my game on WinXP (i develop on a different platform). i think it happens when i first call start() on my StandardGame. am i right to assume that this has something to do with the values (like depth and frequency) i'm passing to the display system? thanks in advance for any assistance!



Nov 25, 2007 11:40:00 PM com.jme.system.lwjgl.LWJGLDisplaySystem initDisplay

SEVERE: Cannot create window

Nov 25, 2007 11:40:00 PM class com.jme.system.lwjgl.LWJGLDisplaySystem initDisplay()

SEVERE: Exception

org.lwjgl.LWJGLException: SetPixelFormat failed (0)

        at org.lwjgl.opengl.WindowsPeerInfo.nChoosePixelFormat(Native Method)

        at org.lwjgl.opengl.WindowsPeerInfo.choosePixelFormat(WindowsPeerInfo.java:52)

        at org.lwjgl.opengl.WindowsDisplayPeerInfo.initDC(WindowsDisplayPeerInfo.java:54)

        at org.lwjgl.opengl.WindowsDisplay.createWindow(WindowsDisplay.java:135)



        at org.lwjgl.opengl.Display.createWindow(Display.java:252)

        at org.lwjgl.opengl.Display.create(Display.java:694)

        at org.lwjgl.opengl.Display.create(Display.java:648)

        at com.jme.system.lwjgl.LWJGLDisplaySystem.initDisplay(Unknown Source)

        at com.jme.system.lwjgl.LWJGLDisplaySystem.createWindow(Unknown Source)

        at com.jmex.game.StandardGame.initSystem(Unknown Source)

        at com.jmex.game.StandardGame.run(Unknown Source)

        at java.lang.Thread.run(Unknown Source)

Nov 25, 2007 11:40:00 PM com.jmex.game.DefaultUncaughtExceptionHandler uncaughtException

SEVERE: Main game loop broken by uncaught exception

com.jme.system.JmeException: Cannot create window: SetPixelFormat failed (0)

        at com.jme.system.lwjgl.LWJGLDisplaySystem.initDisplay(Unknown Source)

        at com.jme.system.lwjgl.LWJGLDisplaySystem.createWindow(Unknown Source)

        at com.jmex.game.StandardGame.initSystem(Unknown Source)

        at com.jmex.game.StandardGame.run(Unknown Source)

        at java.lang.Thread.run(Unknown Source)

Try setting the pixel depth to be the same as the desktop… If you are using 32 bit colors on your desktop, set 32 or 24 bit color in game. And if your desktop is 16 bit, set 16 bit in game.

can anyone also tell me if/how i can catch either of the above two exceptions? i'd like to be able to exit gracefully when the above happens.



i've tried wrapping my standardgame.start(); with a catch for both LWJGLException and JmeException but neither of them get caught even tho the exception fires. (is it maybe because LWJGLException fires too low down in the library that the thread is dead before the exception even gets up to JME?)



i've also put an UncaughtExceptionHandler on my StandardGame. this works, but the problem is that my app dies before i can do anything useful with the input to UncaughtExceptionHandler. i can print the UncaughtExceptionHandler input to the console, but i'd prefer to do something like alert the user to the problem using a dialog window and/or post a bug report via http. i.e. something more interactive before my app dies.



my dialog window appears, but it's empty and has no buttons etc. which i believe are symptoms caused by a thread not being able to fully execute its function (which would be consistent w/ my app dying on the original exception).



suggestions?

StandardGame display settings detection is somewhat uncomplete as it will present a fixed list of settings, even if your system does not support all of them. You could avoid the problem all together by detecting and allowing only valid display settings. See how display settings are detected in SimpleGame.

thanks, but yeah i'm already using the same technique for getting the display settings that is in PropertiesDialog2.java



anyone have an idea how to catch the exception gracefully?

You need to register a default unhandled exception manager… Check the code in StandardGame/SimpleGame for an example.

if you mean UncaughtExceptionHandler, yes i'm already doing that (see post #3 above)

:// You are completely right… this is what happens when you try to answer a question without reading the whole thing first.



Have your tried spawning a new thread to show the pop-up dialog with the options to send the bug report? That might just get rid of your problem.

:slight_smile: yeah i use a JOptionPane inside of its own thread. the JOptionPane appears, it just doesn't get populated w/ the string and with the buttons etc. i'm not sure why – but maybe if a parent thread dies, the child thread dies too? no idea…


   public static void window(final String s) {
      System.err.println("[Log] window(n"+s+"n)");

      new Thread(new Runnable() { public void run() {
            JOptionPane.showMessageDialog(null, s);
      } }).start();
   }



could i fork a separate process maybe? it would be nice to have a bombproof way to exit gracefully from uncaught exceptions.

or is there any way to simply test the user's machine to see if graphics acceleration is supported in the first place? (i think my original JmeException/LWJGLException problem results from the fact that the test PC in question simply doesn't have a good enough graphics card to run opengl at all. so testing for that would solve the problem.)

The problem with spawning a new process (or thread for that matter) is that sometimes the VM crashes with a horrendous error, and if you really wanted a bullet proof system, it will have to be platform dependent, I guess. Or be really clever with processes and several VMs  :expressionless:

Why not copy StandardGame, paste it into your project and modify it to include the right exception handlers in the right place?

lex said:

Why not copy StandardGame, paste it into your project and modify it to include the right exception handlers in the right place?


I can't believe you said that.  :-o

That's what i had to do… StandardGame is a greate template, but at some point I had no choice but to copy it and add modification to make it suitable for my app.

If there is something StandardGame cannot do that would require you to extend it means there's a problem in StandardGame that needs to be fixed.

There's a lot of problems in StandardGame, thankfully I don't have to deal with them as I use my own display system. :slight_smile:

If there is something StandardGame cannot do that would require you to extend it means there's a problem in StandardGame that needs to be fixed.


I have done some work on it, mostly fixing shutdown issues, simplifying queue management and locking system. And also removing all the singletons and adding deadlock detection (was not possible with singletons).

If you are interested at looking at it, I can send it over. Since it's your baby, you would probably have further ideas and improvements, or maybe point out if I did something wrong.

No code can be everything to everyone.  Not even StandardGame.  ;) 

renanse said:

No code can be everything to everyone.  Not even StandardGame.  ;) 


Ha ha! There is where you are mistaken!  :P

StandardGame CAN handle ANY "standard" game without requiring it to be extended.  I have held to that since I first created it and still hold to that.

Whose standard though?    :stuck_out_tongue:

the standard of the original poster, me :slight_smile:



again, the question is: can an UncaughtExceptionHandler assigned to StandardGame allow me to exit gracefully from a thrown JmeException and/or LWJGLException exception?



if the answer is no, then the follow up question: should StandardGame be changed in order to facilitate this?