Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4500063

setDisplayMode() requires a delay or createBufferStrategy() fails

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 1.4.0
    • 1.4.0
    • client-libs
    • beta3
    • x86
    • windows_2000
    • Verified



      Name: gm110360 Date: 09/05/2001


      java version "1.4.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta2-b77)
      Java HotSpot(TM) Client VM (build 1.4.0-beta2-b77, mixed mode)

      After changing display mode to full screen mode, if I don't add a delay, the
      first draw to the graphics received from buffer strategy bombs, big time:

      Generated log file:


      An unexpected exception has been detected in native code outside the VM.
      Unexpected Signal : EXCEPTION_ACCESS_VIOLATION occurred at PC=0x6D05D4A1
      Function=Win32SurfaceData_GetWindow+0x95B
      Library=C:\jdk1.4\jre\bin\awt.dll

      Current Java thread:
      at sun.awt.windows.Win32Renderer.doDrawLine(Native Method)
      at sun.awt.windows.Win32Renderer.drawLine(Win32Renderer.java:51)
      at sun.awt.windows.Win32DDRenderer.drawLine(Win32DDRenderer.java:142)
      at sun.java2d.pipe.ValidatePipe.drawLine(ValidatePipe.java:37)
      at sun.java2d.SunGraphics2D.drawLine(SunGraphics2D.java:1937)
      at FullScreen.main(FullScreen.java:63)

      Dynamic libraries:
      0x00400000 - 0x00406000 C:\JDK1.4\bin\java.exe
      0x77F80000 - 0x77FFB000 C:\WINNT\System32\ntdll.dll
      0x77DB0000 - 0x77E0B000 C:\WINNT\system32\ADVAPI32.dll
      0x77E80000 - 0x77F35000 C:\WINNT\system32\KERNEL32.DLL
      0x77D40000 - 0x77DAC000 C:\WINNT\system32\RPCRT4.DLL
      0x78000000 - 0x78046000 C:\WINNT\system32\MSVCRT.dll
      0x6D330000 - 0x6D446000 C:\JDK1.4\jre\bin\client\jvm.dll
      0x77E10000 - 0x77E74000 C:\WINNT\system32\USER32.dll
      0x77F40000 - 0x77F7C000 C:\WINNT\system32\GDI32.DLL
      0x77570000 - 0x775A0000 C:\WINNT\System32\WINMM.dll
      0x75E60000 - 0x75E7A000 C:\WINNT\System32\IMM32.DLL
      0x69F00000 - 0x69F14000 C:\WINNT\System32\sxgb.dll
      0x690A0000 - 0x690AB000 C:\WINNT\System32\PSAPI.DLL
      0x10000000 - 0x10009000 C:\WINNT\System32\SXGBSYS.DLL
      0x6D1D0000 - 0x6D1D7000 C:\JDK1.4\jre\bin\hpi.dll
      0x6D300000 - 0x6D30D000 C:\JDK1.4\jre\bin\verify.dll
      0x6D210000 - 0x6D227000 C:\JDK1.4\jre\bin\java.dll
      0x6D320000 - 0x6D32D000 C:\JDK1.4\jre\bin\zip.dll
      0x6D000000 - 0x6D0F1000 C:\jdk1.4\jre\bin\awt.dll
      0x77800000 - 0x7781D000 C:\WINNT\System32\WINSPOOL.DRV
      0x77A50000 - 0x77B3A000 C:\WINNT\system32\ole32.dll
      0x6D180000 - 0x6D1D0000 C:\jdk1.4\jre\bin\fontmanager.dll
      0x6D2E0000 - 0x6D2E7000 C:\jdk1.4\jre\bin\nio.dll
      0x75030000 - 0x75043000 C:\WINNT\System32\WS2_32.dll
      0x75020000 - 0x75028000 C:\WINNT\System32\WS2HELP.DLL
      0x6D2D0000 - 0x6D2DE000 C:\jdk1.4\jre\bin\net.dll
      0x75050000 - 0x75058000 C:\WINNT\System32\WSOCK32.dll
      0x51000000 - 0x51044000 C:\WINNT\System32\ddraw.dll
      0x728A0000 - 0x728A6000 C:\WINNT\System32\DCIMAN32.dll
      0x0AF50000 - 0x0B01A000 C:\WINNT\System32\G400ICD.DLL
      0x0B0A0000 - 0x0B0B2000 C:\WINNT\System32\PDSHELL.DLL
      0x0B1D0000 - 0x0B1F1000 C:\WINNT\System32\PDTOOLS.DLL
      0x782F0000 - 0x78532000 C:\WINNT\system32\SHELL32.dll
      0x70BD0000 - 0x70C1C000 C:\WINNT\system32\SHLWAPI.DLL
      0x716F0000 - 0x7177A000 C:\WINNT\system32\COMCTL32.DLL
      0x0B310000 - 0x0B335000 C:\WINNT\System32\PDESKRES.DLL
      0x20420000 - 0x2042B000 C:\WINNT\TRAYHOOK.dll
      0x77920000 - 0x77943000 C:\WINNT\system32\imagehlp.dll
      0x72A00000 - 0x72A2D000 C:\WINNT\system32\DBGHELP.dll

      Local Time = Wed Sep 05 15:22:09 2001
      Elapsed Time = 2
      #
      # The exception above was detected in native code outside the VM
      #
      # Java VM: Java HotSpot(TM) Client VM (1.4.0-beta2-b77 mixed mode)
      #

      Code:

      import java.awt.*;
      import java.awt.image.*;

      public class FullScreen {

        private static int counter = 0;
        private static final int MAX = 50;
        private static DisplayMode MODES[] =
          new DisplayMode[] {
            new DisplayMode(640, 480, 32, 0),
            new DisplayMode(640, 480, 16, 0),
            new DisplayMode(640, 480, 8, 0)
          };

        private static DisplayMode getBestDisplayMode(GraphicsDevice device) {
          for (int x=0, xn=MODES.length; x < xn; x++) {
            DisplayMode[] modes = device.getDisplayModes();
            for (int i=0, in=modes.length; i < in; i++) {
              if (modes[i].getWidth() == MODES[x].getWidth()
                && modes[i].getHeight() == MODES[x].getHeight()
                && modes[i].getBitDepth() == MODES[x].getBitDepth()
              ) {
                return MODES[x];
              }
            }
          }
          return null;
        }

        public static void main(String args[]) {
          GraphicsEnvironment graphicsEnvironment =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
          GraphicsDevice graphicsDevice =
            graphicsEnvironment.getDefaultScreenDevice();
          DisplayMode originalDisplayMode = graphicsDevice.getDisplayMode();

          try {
            Frame frame = new Frame();
            frame.setUndecorated(true);
            frame.setIgnoreRepaint(true);
            graphicsDevice.setFullScreenWindow(frame);
            if (graphicsDevice.isDisplayChangeSupported()) {
              graphicsDevice.setDisplayMode(getBestDisplayMode(graphicsDevice));
      /*try {
          Thread.sleep(5000);
      } catch(InterruptedException e) {
      }*/
            }
            System.out.println("Before Create");
            frame.createBufferStrategy(2); // 2 buffers
            System.out.println("After Create");
            Rectangle bounds = frame.getBounds();
            System.out.println("After Get Bounds");
            BufferStrategy bufferStrategy = frame.getBufferStrategy();
            System.out.println("After Get Buffer Strategy");
            while (!done()) {
              Graphics g = null;
              try {
                g = bufferStrategy.getDrawGraphics();
                System.out.println("After Get Draw Graphics");
                g.setColor(Color.red);
                System.out.println("After Set Color");
                g.drawLine(counter, counter*5, bounds.width, bounds.height);
                System.out.println("After Draw Line");
                bufferStrategy.show();
                System.out.println("After Show");
              } finally {
                if (g != null) {
                  g.dispose();
                }
              }
              try {
                Thread.sleep(250);
              } catch (InterruptedException ignored) {
              }
            }
          } finally {
            graphicsDevice.setDisplayMode(originalDisplayMode);
            graphicsDevice.setFullScreenWindow(null);
          }
          System.exit(0);
        }

        private static boolean done() {
          return (counter++ == MAX);
        }
      }
      (Review ID: 131422)
      ======================================================================

            mmartaksunw Michael Martak (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: