LWJGL / lwjgl3

LWJGL is a Java library that enables cross-platform access to popular native APIs useful in the development of graphics (OpenGL, Vulkan, bgfx), audio (OpenAL, Opus), parallel computing (OpenCL, CUDA) and XR (OpenVR, LibOVR, OpenXR) applications.
https://www.lwjgl.org
BSD 3-Clause "New" or "Revised" License
4.67k stars 631 forks source link

glfwGetClipboardString produces error logs on Mac #815

Closed mcslee closed 1 year ago

mcslee commented 1 year ago

Version

3.3.1

Platform

macOS arm64

JDK

Temurin 17.0.4 Eclipse Adoptium

Module

GLFW

Bug description

The method glfwGetClipboardString produces error logs if the system clipboard content is not convertible a string (for instance, if it contains an image). It is expected that the method will return NULL in this case per the documentation, but there does not seem to be any way to suppress the call from producing error log output.

If an application needs to poll to monitor for a clipboard change, this creates enormous log spew. Even in the case of just checking the system clipboard once in response to user action, it doesn't seem like an error log is appropriate if the method is documented as returning NULL if the clipboard content is not convertible to a string (and there seems to be no other way of checking whether this is the case other than invoking the method).

The error log appears as follows:

[LWJGL] GLFW_FORMAT_UNAVAILABLE error
    Description : Cocoa: Failed to retrieve string from pasteboard
    Stacktrace  :
        org.lwjgl.glfw.GLFW.nglfwGetClipboardString(GLFW.java:4727)
        org.lwjgl.glfw.GLFW.glfwGetClipboardString(GLFW.java:4754)

Stacktrace or crash log output

[LWJGL] GLFW_FORMAT_UNAVAILABLE error
    Description : Cocoa: Failed to retrieve string from pasteboard
    Stacktrace  :
        org.lwjgl.glfw.GLFW.nglfwGetClipboardString(GLFW.java:4727)
        org.lwjgl.glfw.GLFW.glfwGetClipboardString(GLFW.java:4754)
octylFractal commented 1 year ago

I suspect this is because GLFW calls the error callback, and you have it set to print out all errors. Try changing it and skipping GLFW_FORMAT_UNAVAILABLE in the callback. Be aware that this may not be a perfect solution due to the ambiguity of that error code.

mcslee commented 1 year ago

Ah, yes that's exactly right I do have a print handler in place for the error callback. I have updated that, setting a flag when I make this clipboard call to suppress the error log, as ignoring all GLFW_FORMAT_UNAVAILABLE potentially feels too broad.

Thanks for the quick response and great suggestion. Closing this out.