mojira.dev
MC-102867

chat key bound to unicode char causes crash in creative inventory

If the chat key is bound to a unicode char, opening the creative inventory GUI and pressing a key causes java.lang.IndexOutOfBoundsException

I expect that pressing the chat button opens the inventory filter field to allow me to type

what happens instead is pressing any key (not just the chat key) causes an immediate crash.

Steps to Reproduce:

  1. bind chat to a unicode char (non US keyboard needed, or edit options.txt to include the line "key_key.chat:427")

  2. load a creative world

  3. open your inventory

  4. press any key

Code explanation for this follows.

Using MCP names, undoubtedly different from the names used in the code internally. Sorry. Obfuscation 😞

This happens due to GuiContainerCreative.keyTyped(char, int) calling GameSettings.isKeyDown(this.mc.gameSettings.keyBindChat)

That method is as follows:

public static boolean isKeyDown(KeyBinding key)
    {
        return key.getKeyCode() == 0 ? false : (key.getKeyCode() < 0 ? Mouse.isButtonDown(key.getKeyCode() + 100) : Keyboard.isKeyDown(key.getKeyCode()));
    }

keyBindChat.getKeyCode() in my instance is 427. Point being it is something greater than 256.

Keyboard.isKeyDown(int) method is as follows:

public static boolean isKeyDown(int key) {
		synchronized (OpenGLPackageAccess.global_lock) {
			if (!created)
				throw new IllegalStateException("Keyboard must be created before you can query key state");
			return keyDownBuffer.get(key) != 0;
		}
	}

keyDownBuffer was created so:

private static final ByteBuffer keyDownBuffer = BufferUtils.createByteBuffer(KEYBOARD_SIZE);

where KEYBOARD_SIZE is defined as 256.

so keyDownBuffer.get(427) of course causes IndexOutOfBoundsException


Description: Updating screen events

java.lang.IndexOutOfBoundsException: 427
	at java.nio.DirectByteBuffer.get(DirectByteBuffer.java:253)
	at org.lwjgl.input.Keyboard.isKeyDown(Keyboard.java:407)
	at bcf.a(SourceFile:385)
	at bga.a(SourceFile:327)
	at bez.l(SourceFile:420)
	at bez.p(SourceFile:387)
	at bcd.t(SourceFile:1582)
	at bcd.av(SourceFile:969)
	at bcd.a(SourceFile:399)
	at net.minecraft.client.main.Main.main(SourceFile:124)

Attachments

Comments 3

It works fine when the value is set to 255 and crashes at 256.

Fixed by not crashing, but we cannot support these keys since LWJGL doesn't.
So now the keys outside of LWJGL's supported range cannot be pressed any longer.

Jason Winzenried

Erik Broes

Confirmed

Minecraft 1.9.4, Minecraft 1.10

Minecraft 1.10.1

Retrieved