Source code does not match bytecode - org.lwjgl.system.MemoryTextDecoding#decode

Started by Uze, September 30, 2018, 14:42:56

Previous topic - Next topic

Uze

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:
            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:
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?

KaiHH

Quote from: Uze on September 30, 2018, 14:42:56
...found that simple code like that:
            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.

Uze

Nope, it should start at specified offset "the offset at which to start decoding" otherwise method org.lwjgl.openal.ALUtil#getStringList will not work.

KaiHH

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:
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);

Uze

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:
<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.