Hello Guest

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

  • 6 Replies
  • 97 Views
*

Offline Uze

  • *
  • 4
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?

*

Offline KaiHH

  • ***
  • 136
...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.

*

Offline Uze

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

*

Offline KaiHH

  • ***
  • 136
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);

*

Offline Uze

  • *
  • 4
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.

*

Offline KaiHH

  • ***
  • 136
Oh yes, it is a bug which is fixed in 3.2.1-SNAPSHOT.
See: https://github.com/LWJGL/lwjgl3/issues/409

*

Offline Uze

  • *
  • 4
Cool, thank you!