I've been having problems getting the new seticon function for work for on Mac. Here's the code I used:
//// load window icons ////
try {
if (System.getProperty("os.name").startsWith("Mac OS")) {
ByteBuffer[] icons = new ByteBuffer[1];
icons[0] = ByteBuffer.allocateDirect(1); // 128x128
BufferedImage bufferedImage1 = ImageIO.read(new BufferedInputStream(getClass().getClassLoader().getResourceAsStream("mainmenu/images/icon128.png")));
icons[0] = convertImageData(bufferedImage1);
Display.setIcon(icons);
} else {
ByteBuffer[] icons = new ByteBuffer[3];
icons[0] = ByteBuffer.allocateDirect(1); // 16x16
icons[1] = ByteBuffer.allocateDirect(1); // 32x32
icons[2] = ByteBuffer.allocateDirect(1); // 128x128
BufferedImage bufferedImage1 = ImageIO.read(new BufferedInputStream(getClass().getClassLoader().getResourceAsStream("mainmenu/images/icon16.png")));
BufferedImage bufferedImage2 = ImageIO.read(new BufferedInputStream(getClass().getClassLoader().getResourceAsStream("mainmenu/images/icon32.png")));
BufferedImage bufferedImage3 = ImageIO.read(new BufferedInputStream(getClass().getClassLoader().getResourceAsStream("mainmenu/images/icon128.png")));
icons[2] = convertImageData(bufferedImage1);
icons[1] = convertImageData(bufferedImage2);
icons[0] = convertImageData(bufferedImage3);
Display.setIcon(icons);
}
} catch (IOException e1) {
}
It works great for Linux and Windows... but the Mac gets a display exception and drops out. Any ideas?
That is very strange. Since the mac version is all awt, a stack trace would be of alot of help.
You could simplify the code alot. There is no need to check for os name and do different versions. Also your creating direct buffers that is never used. Try this instead:
//// load window icons ////
try {
ByteBuffer[] icons = new ByteBuffer[3];
BufferedImage bufferedImage1 = ImageIO.read(new BufferedInputStream(getClass().getClassLoader().getResourceAsStream("mainmenu/images/icon16.png")));
BufferedImage bufferedImage2 = ImageIO.read(new BufferedInputStream(getClass().getClassLoader().getResourceAsStream("mainmenu/images/icon32.png")));
BufferedImage bufferedImage3 = ImageIO.read(new BufferedInputStream(getClass().getClassLoader().getResourceAsStream("mainmenu/images/icon128.png")));
icons[2] = convertImageData(bufferedImage1);
icons[1] = convertImageData(bufferedImage2);
icons[0] = convertImageData(bufferedImage3);
Display.setIcon(icons);
}
} catch (IOException e1) {
}
Here you go:
java.lang.UnsupportedOperationException
at java.nio.IntBuffer.array(IntBuffer.java:903)
at org.lwjgl.opengl.MacOSXDisplay.setIcon(MacOSXDisplay.java:548)
at org.lwjgl.opengl.Display.setIcon(Display.java:855)
at org.lwjgl.opengl.Display.createWindow(Display.java:275)
at org.lwjgl.opengl.Display.create(Display.java:657)
at org.lwjgl.opengl.Display.create(Display.java:630)
at org.lwjgl.opengl.Display.create(Display.java:614)
at tools.ScreenManager.<init>(ScreenManager.java:155)
at mainmenu.MainMenu.<init>(MainMenu.java:172)
at mainmenu.MainMenu.main(MainMenu.java:897)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
a:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.sun.javaws.Launcher.executeApplication(Launcher.java:848)
at com.sun.javaws.Launcher.executeMainClass(Launcher.java:808)
at com.sun.javaws.Launcher.continueLaunch(Launcher.java:682)
at com.sun.javaws.Launcher.handleApplicationDesc(Launcher.java:397)
at com.sun.javaws.Launcher.handleLaunchFile(Launcher.java:199)
at com.sun.javaws.Launcher.run(Launcher.java:167)
at java.lang.Thread.run(Thread.java:552)
If anyone has a Mac, you can try it at:
//www.tommytwisters.com/twisters/twisters.jnlp
Please let me know.
There is a bug in the lwjgl code. IntBuffer.array() is an optional operation wich were not supported in this case. It has the be rewritten to use IntBuffer.get(int[]) instead. Can someone with cvs access confirm that they will fix it?
Until then you can try to allocate the Buffer with allocat(int) instead of allocateDirect(int) and see if that helps.
edit: Using allocate instead of allocateDirect might break the windows and unix version.
Nice to know I'm not just going crazy. For now I'll just option out the code if it's running on a Mac.
Thanks.
yup, does indeed sound like a lwjgl bug - I'll commit a fix in the evening, unless kev does it before me