diff --git a/src/itdelatrisu/opsu/downloads/DownloadList.java b/src/itdelatrisu/opsu/downloads/DownloadList.java index 89102d69..2c396c9b 100644 --- a/src/itdelatrisu/opsu/downloads/DownloadList.java +++ b/src/itdelatrisu/opsu/downloads/DownloadList.java @@ -56,9 +56,15 @@ public class DownloadList { } /** - * Returns the DownloadNode at an index. + * Returns the DownloadNode at an index, or null if the index is out of bounds. */ - public DownloadNode getNode(int index) { return nodes.get(index); } + public DownloadNode getNode(int index) { + try { + return nodes.get(index); + } catch (IndexOutOfBoundsException e) { + return null; + } + } /** * Gets the Download for a beatmap set ID, or null if not in the list. @@ -100,8 +106,10 @@ public class DownloadList { * Removes a DownloadNode from the list at the given index. */ public void remove(int index) { - DownloadNode node = nodes.remove(index); - map.remove(node.getID()); + try { + DownloadNode node = nodes.remove(index); + map.remove(node.getID()); + } catch (IndexOutOfBoundsException e) {} } /** diff --git a/src/itdelatrisu/opsu/states/DownloadsMenu.java b/src/itdelatrisu/opsu/states/DownloadsMenu.java index db2cc1f6..52d46087 100644 --- a/src/itdelatrisu/opsu/states/DownloadsMenu.java +++ b/src/itdelatrisu/opsu/states/DownloadsMenu.java @@ -300,7 +300,10 @@ public class DownloadsMenu extends BasicGameState { int index = startDownloadIndex + i; if (index >= downloadsSize) break; - DownloadList.get().getNode(index).drawDownload(g, i, index, DownloadNode.downloadContains(mouseX, mouseY, i)); + DownloadNode node = DownloadList.get().getNode(index); + if (node == null) + break; + node.drawDownload(g, i, index, DownloadNode.downloadContains(mouseX, mouseY, i)); } // scroll bar @@ -632,6 +635,8 @@ public class DownloadsMenu extends BasicGameState { if (DownloadNode.downloadIconContains(x, y, i)) { SoundController.playSound(SoundEffect.MENUCLICK); DownloadNode node = DownloadList.get().getNode(index); + if (node == null) + return; Download dl = node.getDownload(); switch (dl.getStatus()) { case CANCELLED: