From 22a7de36224bc6370ccce689687789dcaaf2a133 Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Fri, 14 Jul 2023 13:36:14 +0800 Subject: [PATCH] update potential NPE on CardView --- .../forge/player/PlayerControllerHuman.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java b/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java index fe2528d0ae0..e2799e89d70 100644 --- a/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java +++ b/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java @@ -832,7 +832,13 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont } } if (GuiBase.getInterface().isLibgdxPort()) { - return this.getGui().confirm(wrapper.getView().getHostCard(), buildQuestion.toString().replaceAll("\n", " ")); + CardView cardView; + SpellAbilityView spellAbilityView = wrapper.getView(); + if (spellAbilityView != null) //updated view + cardView = spellAbilityView.getHostCard(); + else + cardView = wrapper.getCardView(); + return this.getGui().confirm(cardView, buildQuestion.toString().replaceAll("\n", " ")); } else { final InputConfirm inp = new InputConfirm(this, buildQuestion.toString(), wrapper); inp.showAndWait(); @@ -1432,8 +1438,9 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont GameEntity affected, final String question) { if (GuiBase.getInterface().isLibgdxPort()) { CardView cardView; - if (effectSA.getView() != null) //updated view - cardView = effectSA.getView().getHostCard(); + SpellAbilityView spellAbilityView = effectSA.getView(); + if (spellAbilityView != null) //updated view + cardView = spellAbilityView.getHostCard(); else //fallback cardView = effectSA.getCardView(); return this.getGui().confirm(cardView, question.replaceAll("\n", " ")); @@ -1866,7 +1873,11 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont try { cardView = CardView.getCardForUi(ImageUtil.getPaperCardFromImageKey(sa.getView().getHostCard().getCurrentState().getTrackableImageKey())); } catch (Exception e) { - cardView = sa.getView().getHostCard(); + SpellAbilityView spellAbilityView = sa.getView(); + if (spellAbilityView != null) //updated view + cardView = spellAbilityView.getHostCard(); + else //fallback + cardView = sa.getCardView(); } return this.getGui().confirm(cardView, question.replaceAll("\n", " ")); } else {