From 010f3adcea532420bee2382d57f9f5d4e5ad968f Mon Sep 17 00:00:00 2001 From: Agetian Date: Sat, 20 May 2017 18:30:58 +0000 Subject: [PATCH] - Fix rare corner case crashes when an attempt is made to insert a card to the zone at a specific index position but that zone ends up being empty at that point (for instance, this can happen when clicking "Concede" during a mana payment for a spell). Currently this is set to issue a console warning for testing purposes to see if this happens in any other cases. --- forge-game/src/main/java/forge/game/zone/Zone.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/forge-game/src/main/java/forge/game/zone/Zone.java b/forge-game/src/main/java/forge/game/zone/Zone.java index d6232afa8cb..a00de79a554 100644 --- a/forge-game/src/main/java/forge/game/zone/Zone.java +++ b/forge-game/src/main/java/forge/game/zone/Zone.java @@ -80,6 +80,13 @@ public class Zone implements java.io.Serializable, Iterable { } public void add(final Card c, final Integer index, final Card latestState) { + if (index != null && cardList.isEmpty() && index.intValue() > 0) { + // something went wrong, most likely the method fired when the game was in an unexpected state + // (e.g. conceding during the mana payment prompt) + System.out.println("Warning: tried to add a card to zone with a specific non-zero index, but the zone was empty! Canceling Zone#add to avoid a crash."); + return; + } + // Immutable cards are usually emblems and effects if (!c.isImmutable()) { final Zone oldZone = game.getZoneOf(c);