NoRelect NoRelect - 1 year ago 187
Java Question

GLFW_PLATFORM_ERROR when using glfwSetWindowIcon()

I currently coding a Project using LWJGL 3. Since GLFW 3.2 its possible to add a window icon. I used it like you can see below, but I keep getting the error, and I have no clue why. What am I doing wrong?

What I have tried already:

  • I have made sure that the file is present in "res/img/icon.png".

  • The PNGLoader (Found here) works, as I am using textures and it loads them without any problems.


PNGDecoder dec = null;
try {
dec = new PNGDecoder(new FileInputStream("res/img/icon.png"));
int width = dec.getWidth();
int height = dec.getHeight();
ByteBuffer buf = BufferUtils.createByteBuffer(width * height * 4);
dec.decode(buf, width * 4, PNGDecoder.Format.RGBA);
Buffer images = new Buffer(buf);
GLFW.glfwSetWindowIcon(window, images);
} catch (IOException e) {

Here's the error that I get:

Description : Win32: Failed to create RGBA bitmap
Stacktrace :

Answer Source

You are passing the raw pixel data as a GLFWImage.Buffer, but GLFW needs the width and height as well. GLFWImage.Buffer is just a convenience class for putting several GLFWImages next to each other, which each hold properties about an image.

GLFWImage image = GLFWImage.malloc();
image.set(width, height, buf);
GLFWImage.Buffer images = GLFWImage.malloc(1);
images.put(0, image);

glfwSetWindowIcon(window, images);;;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download