- 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.

This commit is contained in:
Agetian
2017-05-20 18:30:58 +00:00
parent f79009c544
commit 010f3adcea

View File

@@ -80,6 +80,13 @@ public class Zone implements java.io.Serializable, Iterable<Card> {
} }
public void add(final Card c, final Integer index, final Card latestState) { 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 // Immutable cards are usually emblems and effects
if (!c.isImmutable()) { if (!c.isImmutable()) {
final Zone oldZone = game.getZoneOf(c); final Zone oldZone = game.getZoneOf(c);