Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-102867

chat key bound to unicode char causes crash in creative inventory

    Details

    • Type: Bug
    • Status: Resolved
    • Resolution: Fixed
    • Affects Version/s: Minecraft 1.9.4, Minecraft 1.10
    • Fix Version/s: Minecraft 1.10.1
    • Labels:
      None
    • Environment:

      Windows 7 Java 8 64 bit

    • Confirmation Status:
      Confirmed

      Description

      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

          Activity

            People

            • Assignee:
              grum [Mojang] Grum (Erik Broes)
              Reporter:
              mamiyaotaru Jason Winzenried
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                CHK: