MightyPirates / TIS-3D

TIS-100 inspired low-tech computing in Minecraft.
https://www.curseforge.com/minecraft/mc-mods/tis-3d
Other
108 stars 35 forks source link

Fix crash when providing invalid instrument value to AudioModule #68

Closed Paspartout closed 7 years ago

Paspartout commented 7 years ago

By providing invalid instrument id's to the AudioModule the game crashed with ArrayIndexOutOfBounds:

java.lang.ArrayIndexOutOfBoundsException: 5
    at li.cil.tis3d.common.module.ModuleAudio.playNote(ModuleAudio.java:125)
    at li.cil.tis3d.common.module.ModuleAudio.stepInput(ModuleAudio.java:93)
    at li.cil.tis3d.common.module.ModuleAudio.step(ModuleAudio.java:58)
    at li.cil.tis3d.common.machine.CasingImpl.stepModules(CasingImpl.java:119)
    at li.cil.tis3d.common.tileentity.TileEntityCasing.stepModules(TileEntityCasing.java:221)
    at java.util.ArrayList.forEach(ArrayList.java:1251)
    at li.cil.tis3d.common.tileentity.TileEntityController.step(TileEntityController.java:520)
    at li.cil.tis3d.common.tileentity.TileEntityController.update(TileEntityController.java:358)
    at net.minecraft.world.World.updateEntities(World.java:1807)
    at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:614)
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:761)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:665)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:185)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:523)
    at java.lang.Thread.run(Thread.java:748)

I fixed it by simply returning when the instrumentId is out of bounds of the INSTRUMENTS array.

I hope that pull requesting into this branch is fine and you can merge this change back into the other branches.

fnuecke commented 7 years ago

Thanks for bringing this to my attention! Actual problem here was that the array with instrument sound events didn't match the enum anymore though (due to added instruments).

Fixed in 5963f7e72dfa0f3bf65a6cd2fd8b7ca7a98abf5c.