LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: elias4444 on September 05, 2005, 22:19:08

Title: Mac setIcon() problem
Post by: elias4444 on September 05, 2005, 22:19:08
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?
Title: Mac setIcon() problem
Post by: tomb on September 05, 2005, 22:40:47
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) {
     }
Title: Mac setIcon() problem
Post by: elias4444 on September 05, 2005, 23:30:06
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)
Title: Mac setIcon() problem
Post by: elias4444 on September 05, 2005, 23:36:24
If anyone has a Mac, you can try it at:

//www.tommytwisters.com/twisters/twisters.jnlp

Please let me know.
Title: Mac setIcon() problem
Post by: tomb on September 05, 2005, 23:45:13
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.
Title: Mac setIcon() problem
Post by: elias4444 on September 06, 2005, 01:28:43
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.
Title: Mac setIcon() problem
Post by: Matzon on September 06, 2005, 05:53:16
yup, does indeed sound like a lwjgl bug - I'll commit a fix in the evening, unless kev does it before me