Tuesday, November 22, 2011

LWJGL, full screen and Win7 issue...

I couldn't get full screen mode to work. The spaceinvaders demo app (provided right in the LWJGL download) would just silently crash straight back to Eclipse. There was no error output at all. It turns out Direct3D doesn't work well with Vista/Win7. And there's a simple VM argument to turn it off, "-Dsun.java2d.d3d=false". 

Ah, the joys of computer configuration complexity. It ensures I spend lots of time on damn near useless tangents. After a nice time burn like this, I so can see why developing for only one specific platform can be quite desirable. Anywho...

So, in my quest towards writing a space invaders clone in Scala, I decided to first get the space invaders Java application supplied as a demo in the main LWJGL download's demo folder. I was able to get all the .java files copied into the proper path. And then was happy when it worked first time with almost no editing. I did go and clean up several warnings that were shown by the compiler.

And then I decided to try and turn on full screen mode (as opposed to the windowed mode that was the default). The application would clearly start, appear to get close to running (full screen of black would appear) and then it just sat there until I clicked with the mouse. Then it would crash right back to Eclipse with no error output whatsoever. Quite frustrating.

After spending several hours slowly going through the code placing copious amounts of System.out.println() statements and lots of try{...} catch (Throwable t) {t.printStackTrace()}, I finally narrowed the intermittent failures down to a line in LWJGL itself, Display.sync(60). I have the LWJGL source attached so I can examine the related source code easily.

After examining the code for sync() and then evaluating whether I wanted to go to the trouble of making the LWJGL source editable, I decided to stop and see if I could Google and see if anyone else was having the issue. It only took 5 minutes using the starting search terms of "LWJGL full screen crash" to discover a possible answer on a forum message thread (related StackOverflow topic). For Vista/Win7, I must pass a VM argument of "-Dsun.java2d.d3d=false" to turn off Direct3D. Of course, as soon as I did that, everything sprang up and worked like a charm.

Lesson Learned:
Google with simplest set of key words as soon as possible. It might save a whole bunch of time attempting to isolate an intermittent issue.

No comments:

Post a Comment