Skip to content

Commit

Permalink
JBR-4666 java.lang.InternalError: Error - unable to initialize Metal …
Browse files Browse the repository at this point in the history
…after recreation of graphics device.

Reverted fix of the JRE-359 (CGraphicsEnvironment.getDefaultScreenDevice() returns null)
Logged exception after first attempt to create graphics device
  • Loading branch information
avu authored and vprovodin committed Feb 21, 2023
1 parent ccd8c95 commit 9b20efd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public CGraphicsDevice(final int displayID) {
if (MTLGraphicsConfig.isMetalUsed()) {
// Should not fall back to OpenGL if Metal has been used before
// (it could cause CCE during replace of surface data)
throw new InternalError("Error - unable to initialize Metal" +
throw new IllegalStateException("Error - unable to initialize Metal" +
" after recreation of graphics device." + errorMessage);
}

Expand Down
36 changes: 14 additions & 22 deletions src/java.desktop/macosx/classes/sun/awt/CGraphicsEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import sun.java2d.MacosxSurfaceManagerFactory;
import sun.java2d.SunGraphicsEnvironment;
import sun.java2d.SurfaceManagerFactory;
import sun.lwawt.macosx.CThreading;
import sun.util.logging.PlatformLogger;

/**
* This is an implementation of a GraphicsEnvironment object for the default
Expand All @@ -52,6 +52,9 @@
*/
public final class CGraphicsEnvironment extends SunGraphicsEnvironment {

private static final PlatformLogger logger =
PlatformLogger.getLogger(CGraphicsEnvironment.class.getName());

/**
* Fetch an array of all valid CoreGraphics display identifiers.
*/
Expand Down Expand Up @@ -160,35 +163,24 @@ protected void finalize() throws Throwable {
private synchronized void initDevices() {
Map<Integer, CGraphicsDevice> old = new HashMap<>(devices);
devices.clear();
try {
mainDisplayID = CThreading.privilegedExecuteOnAppKit(
CGraphicsEnvironment::getMainDisplayID);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("Could not get main display ID: " +
e.getMessage() );
}
mainDisplayID = getMainDisplayID();

// initialization of the graphics device may change list of displays on
// hybrid systems via an activation of discrete video.
// So, we initialize the main display first, then retrieve actual list
// of displays, and then recheck the main display again.
if (!old.containsKey(mainDisplayID)) {
old.put(mainDisplayID, new CGraphicsDevice(mainDisplayID));
}

int[] displayIDs;
try {
displayIDs = CThreading.privilegedExecuteOnAppKit(
CGraphicsEnvironment::getDisplayIDs);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("Could not get display IDs: " +
e.getMessage());
try {
old.put(mainDisplayID, new CGraphicsDevice(mainDisplayID));
} catch (IllegalStateException e) {
if (logger.isLoggable(PlatformLogger.Level.FINE)) {
logger.fine("Unable to initialize graphics device for displayID=" +
mainDisplayID + " : " + e);
}
}
}

int[] displayIDs = getDisplayIDs();
if (displayIDs.length == 0) {
// we could throw AWTError in this case.
displayIDs = new int[]{mainDisplayID};
Expand Down

0 comments on commit 9b20efd

Please sign in to comment.