LWJGL Forum

Programming => Bug Reports / RFE => Topic started by: Uze on September 30, 2018, 14:42:56

Title: Source code does not match bytecode - org.lwjgl.system.MemoryTextDecoding#decode
Post by: Uze on September 30, 2018, 14:42:56
I'm using LWJGL version 3.2.0.
After getting garbage from org.lwjgl.openal.ALUtil#getStringList(NULL, ALC11.ALC_ALL_DEVICES_SPECIFIER) I've tried to find out what's wrong and found that simple code like that:
Code: [Select]
            long addr = ALC10.nalcGetString(NULL, ALC11.ALC_DEVICE_SPECIFIER);
            ByteBuffer buffer = memByteBuffer(addr, 11);
            String str1 = memUTF8(buffer, 11, 0);
            buffer.get();
            String str2 = memUTF8(buffer, 11, 0);
gives different results: str1="OpenAL Soft" while str2="penAL Soft".
When I step into memUTF8 and then into org.lwjgl.system.MemoryTextDecoding#decodeUTF8 my debugger (IntelliJ IDEA) complains about source code version mismatch. I've tried to copy MemoryTextDecoding into my code and then call like that:
Code: [Select]
String str2 = MemoryTextDecoding.decodeUTF8(buffer, 11, 0);
That works Ok, str2="OpenAL Soft" as expected.

I'm sure there is no other versions of LWJGL libs in my classpath, so have no idea - what can be wrong?
Title: Re: Source code does not match bytecode - org.lwjgl.system.MemoryTextDecoding#decode
Post by: KaiHH on September 30, 2018, 16:01:57
...found that simple code like that:
Code: [Select]
            long addr = ALC10.nalcGetString(NULL, ALC11.ALC_DEVICE_SPECIFIER);
            ByteBuffer buffer = memByteBuffer(addr, 11);
            String str1 = memUTF8(buffer, 11, 0);
            buffer.get();
            String str2 = memUTF8(buffer, 11, 0);
gives different results: str1="OpenAL Soft" while str2="penAL Soft".
memUTF8 respects the Buffer's position. You call the relative buffer.get() method on it, which advances the buffer one byte. So the next call to memUTF8 with that buffer, it will start decoding from that new Buffer's position.
Title: Re: Source code does not match bytecode - org.lwjgl.system.MemoryTextDecoding#decode
Post by: Uze on September 30, 2018, 16:12:49
Nope, it should start at specified offset "the offset at which to start decoding" otherwise method org.lwjgl.openal.ALUtil#getStringList will not work.
Title: Re: Source code does not match bytecode - org.lwjgl.system.MemoryTextDecoding#decode
Post by: KaiHH on September 30, 2018, 16:19:31
Indeed. I should have checked the code before. :)
When I execute that code (with LWJGL 3.2.0), both strings are equal. Though I tried with OpenGL:
Code: [Select]
long addr = nglGetString(GL_VENDOR);
int longEnough = 1024;
ByteBuffer buffer = memByteBuffer(addr, longEnough);
String str1 = memUTF8(buffer, longEnough, 0);
buffer.get();
String str2 = memUTF8(buffer, longEnough, 0);
System.out.println(str1 + " , " + str2);
Title: Re: Source code does not match bytecode - org.lwjgl.system.MemoryTextDecoding#decode
Post by: Uze on September 30, 2018, 16:55:58
I've just found that it works as expected with version 3.1.6 (I switched to 3.1.6 and back to 3.2.0 several times). I moved that code to distinct maven module with only these dependencies:
Code: [Select]
<dependencies>
        <dependency>
            <groupId>org.lwjgl</groupId>
            <artifactId>lwjgl</artifactId>
            <version>${lwjgl.version}</version>
        </dependency>
        <dependency>
            <groupId>org.lwjgl</groupId>
            <artifactId>lwjgl</artifactId>
            <version>${lwjgl.version}</version>
            <classifier>${lwjgl.natives}</classifier>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.lwjgl</groupId>
            <artifactId>lwjgl-openal</artifactId>
            <version>${lwjgl.version}</version>
        </dependency>

        <dependency>
            <groupId>org.lwjgl</groupId>
            <artifactId>lwjgl-openal</artifactId>
            <version>${lwjgl.version}</version>
            <classifier>${lwjgl.natives}</classifier>
            <scope>runtime</scope>
        </dependency>
    </dependencies>

And it still works for 3.1.6 and doesn't work for 3.2.0.

So it looks like 3.2.0 is broken somehow? I've also cleared my local maven repo, just in case - still the same picture after new dependency download.

I've attached my PoC maven project.
Title: Re: Source code does not match bytecode - org.lwjgl.system.MemoryTextDecoding#decode
Post by: KaiHH on September 30, 2018, 17:15:02
Oh yes, it is a bug which is fixed in 3.2.1-SNAPSHOT.
See: https://github.com/LWJGL/lwjgl3/issues/409
Title: Re: Source code does not match bytecode - org.lwjgl.system.MemoryTextDecoding#decode
Post by: Uze on September 30, 2018, 17:28:07
Cool, thank you!