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

Game crash when rendering stuck arrows in entities

    XMLWordPrintable

Details

    • Bug
    • Status: Open
    • Resolution: Unresolved
    • 1.15.1
    • None
    • None
    • Plausible
    • Crash, Resource Packs, Textures and models
    • Low

    Description

      (note I'm using yarn names, as they're what I'm familiar with and I'm unsure if using mojang names here would be in violation of Microsoft licence)

      There's a rather subtle bug I've found whilst working with custom entity models that doesn't seem to happen in vanilla, but will most definitely occur when you have either a model with 0 parts, or a part with 0 cubes.

      Simply put, if you have a model patching any of the above criteria, and try to shoot arrows at it, the game will attempt to render stuck arrows in a random cube, and the game will crash with "IllegalArgumentException: bound parameter must be positive"

      The relevant methods are:

      PlayerEntityModel.java
      public ModelPart getRandomPart(Random random) {
          return this.parts.get(random.nextInt(this.parts.size())); // exception when size == 0
      }
      
      ModelPart.java
      public Cuboid getRandomCuboid(Random random) {
          return this.cuboids.get(random.nextInt(this.cuboids.size())); // exception when size == 0
      }
      

      This issue seems to come in three portions:

      1. The initial exception. A model with no parts is, of course, invalid, though there should be some checks in place to either prevent that or not call this method on empty models. Likewise a part with no cubes can still be valid if all the cubes are stored in child parts, so this should perhaps still check for that.
      2. Exceptions thrown by features aren't properly caught. They bubble up to the top of the game and generate a crash report, rather than simply causing an exception to be logged and the entity to fail rendering, as they did in previous versions.

      Easiest solution might be to just check for the empty list in both methods and return null, then check for nulls in the arrow renderer (FIX). One could also add in something in ModelPart.getRandomCuboid to explore the children as well when searching for a random cube (ENHANCEMENT).

      Attachments

        Activity

          People

            Unassigned Unassigned
            awr_* Sollace
            Votes:
            4 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              CHK: