JVM crashes on exit from fullscreen mode

If I run the code below and press escape to exit my “game” the JVM crashes, why?

JVM Error:

An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x2CFB326
Function=Java_sun_print_Win32PrintJob_endPrintRawData+0x5182
Library=C:\Program\Java\j2sdk1.4.2_03\jre\bin\awt.dll

Current Java thread:
at sun.java2d.DefaultDisposerRecord.invokeNativeDispose(Native Method)
at sun.java2d.DefaultDisposerRecord.dispose(DefaultDisposerRecord.java:25)
at sun.java2d.Disposer.run(Disposer.java:102)
at java.lang.Thread.run(Thread.java:534)

Dynamic libraries:
0x00400000 - 0x00407000 C:\Program\Java\j2sdk1.4.2_03\bin\javaw.exe
0x77F50000 - 0x77FF9000 C:\WINDOWS\System32\ntdll.dll
0x77E60000 - 0x77F4A000 C:\WINDOWS\system32\kernel32.dll
0x77DC0000 - 0x77E5D000 C:\WINDOWS\system32\ADVAPI32.dll
0x78000000 - 0x78087000 C:\WINDOWS\system32\RPCRT4.dll
0x77D30000 - 0x77DBC000 C:\WINDOWS\system32\USER32.dll
0x7E190000 - 0x7E1D1000 C:\WINDOWS\system32\GDI32.dll
0x77C00000 - 0x77C53000 C:\WINDOWS\system32\MSVCRT.dll
0x08000000 - 0x08138000 C:\Program\Java\j2sdk1.4.2_03\jre\bin\client\jvm.dll
0x76B30000 - 0x76B5D000 C:\WINDOWS\System32\WINMM.dll
0x10000000 - 0x10007000 C:\Program\Java\j2sdk1.4.2_03\jre\bin\hpi.dll
0x003D0000 - 0x003DE000 C:\Program\Java\j2sdk1.4.2_03\jre\bin\verify.dll
0x003E0000 - 0x003F9000 C:\Program\Java\j2sdk1.4.2_03\jre\bin\java.dll
0x008A0000 - 0x008AD000 C:\Program\Java\j2sdk1.4.2_03\jre\bin\zip.dll
0x02C90000 - 0x02D9F000 C:\Program\Java\j2sdk1.4.2_03\jre\bin\awt.dll
0x72FD0000 - 0x72FF3000 C:\WINDOWS\System32\WINSPOOL.DRV
0x76370000 - 0x7638C000 C:\WINDOWS\System32\IMM32.dll
0x7CCC0000 - 0x7CDE4000 C:\WINDOWS\system32\ole32.dll
0x5B270000 - 0x5B2A4000 C:\WINDOWS\System32\uxtheme.dll
0x02E10000 - 0x02E60000 C:\Program\Java\j2sdk1.4.2_03\jre\bin\fontmanager.dll
0x51000000 - 0x51047000 C:\WINDOWS\System32\ddraw.dll
0x73B90000 - 0x73B96000 C:\WINDOWS\System32\DCIMAN32.dll
0x5C000000 - 0x5C0C8000 C:\WINDOWS\System32\D3DIM700.DLL
0x030B0000 - 0x031C2000 C:\Program\Messenger Plus! 2\MsgPlusH1.dll
0x77330000 - 0x773BB000 C:\WINDOWS\system32\COMCTL32.dll
0x76390000 - 0x763D5000 C:\WINDOWS\system32\comdlg32.dll
0x70A70000 - 0x70AD5000 C:\WINDOWS\system32\SHLWAPI.dll
0x773C0000 - 0x77BBB000 C:\WINDOWS\system32\SHELL32.dll
0x77110000 - 0x7719B000 C:\WINDOWS\system32\OLEAUT32.dll
0x71950000 - 0x71A34000 C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.1331_x-ww_7abf6d02\comctl32.dll
0x746F0000 - 0x74734000 C:\WINDOWS\System32\MSCTF.dll
0x76C80000 - 0x76CA2000 C:\WINDOWS\system32\imagehlp.dll
0x6DAA0000 - 0x6DB1D000 C:\WINDOWS\system32\DBGHELP.dll
0x77BF0000 - 0x77BF7000 C:\WINDOWS\system32\VERSION.dll
0x76BE0000 - 0x76BEB000 C:\WINDOWS\System32\PSAPI.DLL

Heap at VM Abort:
Heap
def new generation total 576K, used 1K [0x10010000, 0x100b0000, 0x104f0000)
eden space 512K, 0% used [0x10010000, 0x10010450, 0x10090000)
from space 64K, 0% used [0x10090000, 0x10090000, 0x100a0000)
to space 64K, 0% used [0x100a0000, 0x100a0000, 0x100b0000)
tenured generation total 4372K, used 3821K [0x104f0000, 0x10935000, 0x14010000)
the space 4372K, 87% used [0x104f0000, 0x108ab7f8, 0x108ab800, 0x10935000)
compacting perm gen total 4096K, used 2821K [0x14010000, 0x14410000, 0x18010000)
the space 4096K, 68% used [0x14010000, 0x142d1698, 0x142d1800, 0x14410000)

Local Time = Thu May 13 23:13:26 2004
Elapsed Time = 4

The exception above was detected in native code outside the VM

Java VM: Java HotSpot™ Client VM (1.4.2_03-b02 mixed mode)

An error report file has been saved as hs_err_pid3224.log.

Please refer to the file for further information.

/*
 * Created on 2004-maj-13
 */
package demo;

import java.awt.Color;
import java.awt.DisplayMode;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferStrategy;

/**
 * @author Johan Tibell
 */
public class Game implements Runnable, KeyListener
{
      private GraphicsDevice gd;
      private Frame window;
      private BufferStrategy strategy;
      private boolean running = true;
      
      public Game()
      {
            GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
            gd = ge.getDefaultScreenDevice();
            GraphicsConfiguration gc = gd.getDefaultConfiguration();
            
            window = new Frame("Test", gc);
            window.setUndecorated(true);
            window.setIgnoreRepaint(true);
            gd.setFullScreenWindow(window);
            gd.setDisplayMode(new DisplayMode(640, 480, 32, 0));
            window.createBufferStrategy(2);
            strategy = window.getBufferStrategy();
            window.addKeyListener(this);
            
            new Thread(this).start();
      }
      
      public void run()
      {
            while(running)
            {
                  Graphics g = strategy.getDrawGraphics();
                  
                  g.setColor(Color.BLACK);
                  g.fillRect(0, 0, 640, 480);
                  g.setColor(Color.WHITE);
                  g.drawString("TEST", 20, 20);
                  
                  strategy.show();
                  g.dispose();
            }

            gd.setFullScreenWindow(null);
      }

      public void keyPressed(KeyEvent e)
      {
      }

      public void keyReleased(KeyEvent e)
      {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
                  running = false;
      }

      public void keyTyped(KeyEvent e)
      {
      }
      
      public static void main(String[] args)
      {
            new Game();
      }
}

'cos your running 1.4.x =o

'tis fixed in 1.5.

So what you’re saying is that it’s impossible to use fullscreen in 1.4.x, that it’s a broken “feature”?

[quote]So what you’re saying is that it’s impossible to use fullscreen in 1.4.x, that it’s a broken “feature”?
[/quote]
Well not impossible, but it will be a major source of bugs if you try to use it =D

1 thing you can try, is upgrading your gfx card drivers.
Another, is to setFullScreenWindow(null) before you dispose() of the window. Perhaps even setVisible(false) before dispose() also. If you change the DisplayMode, then you may also want to manually restore it to its original setting before the setFullScreenWindow(null).

System.exit(0) instead of dispose()ing of the window works for some people.

Basically, its abit hit&miss as to what fixes the disposer crash.

Another thing you could try, is either specifying a blitting BufferStrategy (rather than page flipping), or even worse, lose the BufferStrategy all together and do the back buffering yourself with a volatille image. (these 2 options won’t allow you vsync… but then, vsync is driver dependant anyway, so you can’t rely on it)