I set out to do some compatibility testing with the Mac and I blew up on my splash screen!
My splash screen fades in from white on a Canvas placed on a JWindow. This code works INTERMITTENLY!?!? Argh! There’s a 1 in 3 chance that my Splash Screen will work because 2 times out of 3 the Canvas’ size reverts to ( 0, 0 ) and my call to createBufferStrategy(2) blows up!
`
Exception in thread “main” java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0
at apple.awt.IntegerNIORaster.createNIORaster(IntegerNIORaster.java:22)
at apple.awt.CGraphicsConfig.createCompatibleImage(CGraphicsConfig.java:53)
at apple.awt.OSXOffScreenSurfaceData.createData(OSXOffScreenSurfaceData.java:115)
at apple.awt.OSXVolatileImage.createHWData(OSXVolatileImage.java:77)
at apple.awt.OSXVolatileImage.initAcceleratedBackground(OSXVolatileImage.java:87)
at sun.awt.image.SunVolatileImage.(SunVolatileImage.java:86)
at sun.awt.image.SunVolatileImage.(SunVolatileImage.java:77)
at apple.awt.OSXVolatileImage.(OSXVolatileImage.java:52)
at apple.awt.ComponentModel.createVolatileImage(ComponentModel.java:104)
at java.awt.Component.createVolatileImage(Component.java:2684)
at java.awt.Component$BltBufferStrategy.createBackBuffers(Component.java:3194)
at java.awt.Component$BltBufferStrategy.(Component.java:3180)
at java.awt.Component.createBufferStrategy(Component.java:2927)
at java.awt.Canvas.createBufferStrategy(Canvas.java:166)
at java.awt.Component.createBufferStrategy(Component.java:2867)
at java.awt.Canvas.createBufferStrategy(Canvas.java:141)
at org.???.cio.visual.comp.SplashScreen.(SplashScreen.java:42)
at org.???.cio.visual.comp.MainFrame.launchSplashScreen(MainFrame.java:265)
at org.???.cio.visual.comp.MainFrame.(MainFrame.java:81)
at org.???.cio.ExPattern.main(ExPattern.java:26)
`
Canvas canvas = new Canvas();
SplashScreenAnimator splashAnimator =
new SplashScreenAnimator( productName, versionNumber );
System.out.println( splashAnimator.getPreferredSize() ); // see expected size
canvas.setSize( splashAnimator.getPreferredSize() );
getContentPane().add( canvas, BorderLayout.CENTER);
pack();
System.out.println( canvas.getHeight() + " " + canvas.getWidth() ); // see unexpected 0 0
canvas.createBufferStrategy( 2 ); //BOOM!
disclaimer: I’m not working on a game. in the future I’ll be doing more interactive graphics and i hope to have things to contribute.