LWJGL 3.0 - GLFWErrorCallback usage

Started by xsupermetroidx, December 23, 2014, 18:09:06

Previous topic - Next topic

xsupermetroidx

This is a simple question about how to properly use GLFW's error callbacks. The error event callback has the signature "int error, long description", where description is supposed to be a pointer to a char array according to GLFW's documentation. How can I access the error description string, or is this an oversight/impossibility at the moment?

spasi

See the org.lwjgl.glfw.Callbacks class. There is a method errorCallbackDescriptionString, which converts the description pointer value to a Java String. There also two GLFWErrorCallback implementations (errorCallbackPrint & errorCallbackThrow).

If you're interested in seeing how this is implemented, see the memDecode* methods in the org.lwjgl.system.MemoryUtil class.

xsupermetroidx

Thanks for the swift reply... got it figured out now.

SHC

Shouldn't I use MemoryUtil.memDecodeUTF8(description); for that Spasi?

spasi

Yes, you can use memDecode* directly, but keep in mind that MemoryUtil is considered internal/unsafe API. The same is true for everything else in the org.lwjgl.system package. Technically, it is subject to change at any time, though I'm pretty sure that changes will be minimal if it ever comes to that.

SHC

Thanks for the clarification Spasi. I was already using memDecodeUTF8 in my code, so I was in doubt whether it was correct. I think I should better change it to Callbacks.errorCallbackDescriptionString() now.