[MC-102867] chat key bound to unicode char causes crash in creative inventory Created: 01/Jun/16  Updated: 21/Jun/16  Resolved: 21/Jun/16

Status: Resolved
Project: Minecraft: Java Edition
Component/s: None
Affects Version/s: Minecraft 1.9.4, Minecraft 1.10
Fix Version/s: Minecraft 1.10.1

Type: Bug
Reporter: Jason Winzenried Assignee: [Mojang] Grum (Erik Broes)
Resolution: Fixed Votes: 0
Labels: None

Windows 7 Java 8 64 bit

Attachments: Text File crashlog.txt     PNG File keybind.png    
Confirmation Status: Confirmed


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)

Comment by [Mod] Anon Ymus [ 10/Jun/16 ]

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

Comment by [Mod] Anon Ymus [ 10/Jun/16 ]


Comment by [Mojang] Grum (Erik Broes) [ 21/Jun/16 ]

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.

Generated at Fri Dec 14 18:06:46 CST 2018 using Jira 7.11.2#711002-sha1:fdc329dee91471a641faabfe39b5ff8c0a5b3f66.