LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: asyx on September 18, 2015, 15:07:12

Title: Possible bug in STBTTFontInfo
Post by: asyx on September 18, 2015, 15:07:12
Hello!

I played around with the TrueType STB bindings a little and tried to port a C example that renders text into a PNG.

So, that works now but I think there's a bug in the STBTTFontInfo.malloc() method.

http://pastebin.com/ZbVC7k4L (http://pastebin.com/ZbVC7k4L)

Here's my code (working). If you uncomment line 72 and comment line 73, it crashes with

Exception in thread "main" java.lang.UnsatisfiedLinkError: org.lwjgl.stb.STBTTFontinfo.offsets()I

on line 72.

At first I thought that it might be a problem with my library path but I then just got the size of the struct via C and created the buffer manually and that works flawlessly.

I'm using the LWJGL version from the snapshot maven repository.
Title: Re: Possible bug in STBTTFontInfo
Post by: Kai on September 18, 2015, 15:18:07
You are likely using an old DLL/shared library of LWJGL. This native function is available in the latest 3.0.0a release and the latest 3.0.0b nightly. In Maven it comes with the `org.lwjgl:lwjgl-natives-<os>` artifact.
Check your -Djava.library.path.
Title: Re: Possible bug in STBTTFontInfo
Post by: asyx on September 18, 2015, 15:39:51
Cleaned it and repackaged it. Everything but this method works. And the library path works as well. Otherwise, I couldn't use all the other STB stuff I'm using.
Title: Re: Possible bug in STBTTFontInfo
Post by: Kai on September 18, 2015, 17:21:47
Quote from: asyx on September 18, 2015, 15:39:51
Otherwise, I couldn't use all the other STB stuff I'm using.
Not necessarily. Could have been that the native interface of the structs changed with one build version which added that "offset" function.
My theory is that you are linking against an old version of the LWJGL3 native/shared library. ;)
Title: Re: Possible bug in STBTTFontInfo
Post by: asyx on September 18, 2015, 17:40:27
But wouldn't maven do that for me? Like, I unpacked the native libraries from the jar that I got together with the lwjgl.jar. I mean, maven should prevent f*ckups like that, right?
Title: Re: Possible bug in STBTTFontInfo
Post by: spasi on September 18, 2015, 17:46:23
Thanks asyx, this is a bug in LWJGL. It happens because STBTTFontInfo.malloc() is the first native LWJGL method you call and the library is not properly initialized (because this particular struct is opaque = has no public fields). It will be fixed in the next nightly build.

In the meantime, a workaround is to call LWJGLUtil.initialize() before STBTTFontInfo.malloc().
Title: Re: Possible bug in STBTTFontInfo
Post by: spasi on September 19, 2015, 21:53:14
This should be fixed in the latest nightly build (3.0.0b #28).
Title: Re: Possible bug in STBTTFontInfo
Post by: FortressBuilder on September 20, 2015, 06:45:17
@spasi 3.0.0b build 28 does not include the glfw natives, leading to errors during initialization.
Title: Re: Possible bug in STBTTFontInfo
Post by: spasi on September 20, 2015, 07:18:15
Thanks, fixed in build #29.