From c256aa59f7fa25daa4141f2bed000805c66f0327 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Fri, 5 Feb 2021 20:54:04 +0400 Subject: [PATCH] GUI: fixed error on closing dialogs/games (#7507); --- .../java/org/mage/card/arcane/CardPanel.java | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java b/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java index 0bc70c2193..038abf71eb 100644 --- a/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java +++ b/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java @@ -74,7 +74,7 @@ public abstract class CardPanel extends MagePermanent implements ComponentListen private boolean showCastingCost; private float alpha = 1.0f; - private ActionCallback callback; + private ActionCallback callback; // callback can be null after closed game/dialog, so you must check it before call protected boolean tooltipShowing; protected final TextPopup tooltipText; @@ -596,6 +596,9 @@ public abstract class CardPanel extends MagePermanent implements ComponentListen @Override public void mouseClicked(MouseEvent e) { + if (callback == null) { + return; + } data.setComponent(this); data.setCard(this.getGameCard()); data.setGameId(this.gameId); @@ -624,10 +627,12 @@ public abstract class CardPanel extends MagePermanent implements ComponentListen mouseResetTimer.schedule(new TimerTask() { @Override public void run() { - if (mouseClicksCount == 1) { - callback.mouseClicked(e, data, false); - } else if (mouseClicksCount > 1) { - callback.mouseClicked(e, data, true); + if (callback != null) { + if (mouseClicksCount == 1) { + callback.mouseClicked(e, data, false); + } else if (mouseClicksCount > 1) { + callback.mouseClicked(e, data, true); + } } mouseClicksCount = 0; } @@ -637,6 +642,9 @@ public abstract class CardPanel extends MagePermanent implements ComponentListen @Override public void mouseEntered(MouseEvent e) { + if (callback == null) { + return; + } if (getGameCard().hideInfo()) { return; } @@ -655,6 +663,9 @@ public abstract class CardPanel extends MagePermanent implements ComponentListen @Override public void mouseExited(MouseEvent e) { + if (callback == null) { + return; + } if (getGameCard().hideInfo()) { return; } @@ -673,6 +684,9 @@ public abstract class CardPanel extends MagePermanent implements ComponentListen @Override public void mousePressed(MouseEvent e) { + if (callback == null) { + return; + } data.setComponent(this); data.setCard(this.getGameCard()); data.setGameId(this.gameId); @@ -681,6 +695,9 @@ public abstract class CardPanel extends MagePermanent implements ComponentListen @Override public void mouseReleased(MouseEvent e) { + if (callback == null) { + return; + } data.setComponent(this); data.setCard(this.getGameCard()); data.setGameId(this.gameId); @@ -689,6 +706,9 @@ public abstract class CardPanel extends MagePermanent implements ComponentListen @Override public void mouseDragged(MouseEvent e) { + if (callback == null) { + return; + } data.setComponent(this); data.setCard(this.getGameCard()); data.setGameId(this.gameId); @@ -697,6 +717,9 @@ public abstract class CardPanel extends MagePermanent implements ComponentListen @Override public void mouseMoved(MouseEvent e) { + if (callback == null) { + return; + } if (getGameCard().hideInfo()) { return; } @@ -708,6 +731,9 @@ public abstract class CardPanel extends MagePermanent implements ComponentListen @Override public void mouseWheelMoved(MouseWheelEvent e) { + if (callback == null) { + return; + } if (getGameCard().hideInfo()) { return; }