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

[macosx] IllegalArgumentException: Invalid display mode when returning from full screen

XMLWordPrintable

    • x86
    • os_x

      FULL PRODUCT VERSION :
      java version " 1.7.0_07 "
      Java(TM) SE Runtime Environment (build 1.7.0_07-b10)
      Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      OS X 10.7.5
      Darwin 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64


      EXTRA RELEVANT SYSTEM CONFIGURATION :
      External beamer connected, display running in mirror (aka. clone) mode, at 1024x768 px.

      A DESCRIPTION OF THE PROBLEM :
      Leaving full screen mode by calling setFullScreenWindow(null) will cause an IllegalArgumentException originating in native code and mentioning " Invalid display mode " in its message. This only happens when the external beamer is connected.

      The key cause seems to be the fact that CGDisplayCopyAllDisplayModes only returns 640x480 and 800x600 display modes, even though the current mode, which also is the original mode, is 1024x768. http://stackoverflow.com/q/11637904/1468366 describes that phenomenon as well.

      I assume that this issue was introduced by http://hg.openjdk.java.net/jdk7u/jdk7u/jdk/rev/bf5bf37108c1 as that seems to be the change which introduced mode switching in connection with full-screen windows.

      The issue can be reproduced using current jdk7u code. I recently reported this issue as http://java.net/jira/browse/MACOSX_PORT-805 but was since told on IRC that that bug tracker is no longer actively used.

      REGRESSION. Last worked in version 5.0

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Connect beamer, clone display
      2. Run example program below

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Full screen mode entered for one moment, no errors printed, program terminating normally.
      ACTUAL -
      Exception thrown when leaving full screen mode.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Entering full screen mode
      2012-10-16 09:44:55.466 java[65321:8007] Cocoa AWT: Not running on AppKit thread 0 when expected. (
      0 liblwawt.dylib 0x000000010f04450f Java_sun_lwawt_macosx_CPlatformWindow_nativeGetNSWindowDisplayID_1AppKitThread + 59
      1 ??? 0x0000000106747f90 0x0 + 4403265424
      2 ??? 0x000000010673c2d4 0x0 + 4403217108
      3 ??? 0x000000010673c9e1 0x0 + 4403218913
      )
      2012-10-16 09:44:55.467 java[65321:8007] Please file a bug report at http://java.net/jira/browse/MACOSX_PORT with this message and a reproducible test case.
      Leaving full screen mode
      java.lang.IllegalArgumentException: Invalid display mode
      at sun.awt.CGraphicsDevice.nativeSetDisplayMode(Native Method)
      at sun.awt.CGraphicsDevice.setDisplayMode(CGraphicsDevice.java:200)
      at sun.awt.CGraphicsDevice.setFullScreenWindow(CGraphicsDevice.java:135)
      at FullScreenTest.run(FullScreenTest.java:16)
      at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:241)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)
      at java.awt.EventQueue.access$200(EventQueue.java:103)
      at java.awt.EventQueue$3.run(EventQueue.java:682)
      at java.awt.EventQueue$3.run(EventQueue.java:680)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:691)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      class FullScreenTest implements Runnable {
          public static void main(String[] args) throws Exception {
              EventQueue.invokeAndWait(new FullScreenTest());
          }
          public void run() {
              try {
                  Frame f = new Frame( " FullScreenTest " );
                  GraphicsDevice gd =
                      GraphicsEnvironment
                      .getLocalGraphicsEnvironment()
                      .getDefaultScreenDevice();
                  System.err.println( " Entering full screen mode " );
                  gd.setFullScreenWindow(f);
                  System.err.println( " Leaving full screen mode " );
                  gd.setFullScreenWindow(null);
              }
              catch (Exception e) {
                  e.printStackTrace();
              }
              finally {
                  System.exit(0);
              }
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Compile OpenJDK with the following patch in place:

      Index: jdk/src/macosx/classes/sun/awt/CGraphicsDevice.java
      ===================================================================
      --- jdk/src/macosx/classes/sun/awt/CGraphicsDevice.java
      +++ jdk/src/macosx/classes/sun/awt/CGraphicsDevice.java
      @@ -197,6 +197,8 @@ public class CGraphicsDevice extends Gra
               if (dm == null) {
                   throw new IllegalArgumentException( " Attempt to set null as a DisplayMode " );
               }
      + if (dm.equals(getDisplayMode()))
      + return;
               nativeSetDisplayMode(displayID, dm.getWidth(), dm.getHeight(), dm.getBitDepth(), dm.getRefreshRate());
               if (isFullScreenSupported() && getFullScreenWindow() != null) {
                   getFullScreenWindow().setSize(dm.getWidth(), dm.getHeight());
      Index: jdk/src/macosx/native/sun/awt/CGraphicsDevice.m
      ===================================================================
      --- jdk/src/macosx/native/sun/awt/CGraphicsDevice.m
      +++ jdk/src/macosx/native/sun/awt/CGraphicsDevice.m
      @@ -79,7 +79,7 @@ static CGDisplayModeRef getBestModeForPa
                   // Exact match
                   return cRef;
               }
      - if (CGDisplayModeGetRefreshRate(cRef) == 0) {
      + if ((int)CGDisplayModeGetRefreshRate(cRef) == 0) {
                   // Not exactly what was asked for, but may fit our needs if we don't find an exact match
                   bestGuess = cRef;
               }

            serb Sergey Bylokhov
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: