Skip to content

Commit a51e07e

Browse files
MostCromulentclaudeHanmac
authored
Fix NPE when cloning Adventure creatures on mobile (#10349)
When a clone (e.g. Superior Spider-Man) copies an Adventure creature, the CardView's AlternateState was null because getAlternateState() only checks original card states, not clone states. The mobile renderer then crashes calling getName() on the null state when rendering with card images disabled. Two fixes: CardView.updateState() falls back to the Secondary clone state, and CardImageRenderer falls back from the backup to the in-game card when the backup lacks the adventure state. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Hans Mackowiak <hanmac@gmx.de>
1 parent 04a9a9a commit a51e07e

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

forge-game/src/main/java/forge/game/card/CardView.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,12 @@ void updateState(Card c) {
11441144
alternateState = c.getState(CardStateName.Original);
11451145
}
11461146

1147+
// When a card is cloned as an Adventure creature, getAlternateState() returns null
1148+
// because it only checks original states. Fall back to the Secondary clone state.
1149+
if (alternateState == null && c.hasState(CardStateName.Secondary)) {
1150+
alternateState = c.getState(CardStateName.Secondary);
1151+
}
1152+
11471153
if (alternateState == null) {
11481154
set(TrackableProperty.AlternateState, null);
11491155
} else {

forge-gui-mobile/src/forge/card/CardImageRenderer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,10 @@ private static void setTextBox(Graphics g, CardView card, CardStateView state, C
656656
if (cv == null || isFaceDown)
657657
cv = card;
658658
CardStateView csv = cv.getState(true);
659+
if (csv == null) { // backup may not have adventure state (e.g. clone of adventure)
660+
cv = card;
661+
csv = cv.getState(true);
662+
}
659663
text = cv.getText(csv, needTranslation && csv != null ? CardTranslation.getTranslationTexts(csv) : null);
660664

661665
} else {

0 commit comments

Comments
 (0)