Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSB: Fix null reference error in 'Drifting' ability #10824

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

DieterReinert
Copy link
Contributor

@DieterReinert DieterReinert commented Jan 13, 2025

Fixed a crash caused by a TypeError when the defender is null in the Drifting ability.

Stack Trace:

A battle crashed: TypeError: Cannot read properties of null (reading 'activeTurns')
at Battle.onModifyAtk (/home/ps/main/data/mods/gen9ssb/abilities.ts:1725:18)
at Battle.runEvent (/home/ps/main/sim/battle.ts:845:34)
at Pokemon.getStat (/home/ps/main/sim/pokemon.ts:602:23)
at Battle.onModifyMove (/home/ps/main/data/mods/gen9ssb/moves.ts:6018:16)
at Battle.singleEvent (/home/ps/main/sim/battle.ts:585:25)
at BattleActions.useMoveInner (/home/ps/main/data/mods/gen9ssb/scripts.ts:1308:16)
at BattleActions.useMove (/home/ps/main/sim/battle-actions.ts:386:27)
at BattleActions.runMove (/home/ps/main/data/mods/gen9ssb/scripts.ts:1216:34)
at Battle.runAction (/home/ps/main/data/mods/gen9ssb/scripts.ts:443:17)
at Battle.turnLoop (/home/ps/main/sim/battle.ts:2802:9)

Fixed a crash caused by a `TypeError` when the `defender` is `null` in the `Drifting` ability. Added necessary null checks in the `onModifyAtk` and `onModifySpA` methods to ensure `defender` is valid before accessing its properties.

**Stack Trace:**
```TS
A battle crashed: TypeError: Cannot read properties of null (reading 'activeTurns')
at Battle.onModifyAtk (/home/ps/main/data/mods/gen9ssb/abilities.ts:1725:18)
at Battle.runEvent (/home/ps/main/sim/battle.ts:845:34)
at Pokemon.getStat (/home/ps/main/sim/pokemon.ts:602:23)
at Battle.onModifyMove (/home/ps/main/data/mods/gen9ssb/moves.ts:6018:16)
at Battle.singleEvent (/home/ps/main/sim/battle.ts:585:25)
at BattleActions.useMoveInner (/home/ps/main/data/mods/gen9ssb/scripts.ts:1308:16)
at BattleActions.useMove (/home/ps/main/sim/battle-actions.ts:386:27)
at BattleActions.runMove (/home/ps/main/data/mods/gen9ssb/scripts.ts:1216:34)
at Battle.runAction (/home/ps/main/data/mods/gen9ssb/scripts.ts:443:17)
at Battle.turnLoop (/home/ps/main/sim/battle.ts:2802:9)
```
@urkerab
Copy link
Contributor

urkerab commented Jan 13, 2025

Huh, why doesn't Stakeout crash all the time for the same reason? I guess nobody ever runs it...

@DieterReinert
Copy link
Contributor Author

Huh, why doesn't Stakeout crash all the time for the same reason? I guess nobody ever runs it...

When getStat invokes runEvent for ModifyAtk, it passes source as null.
Consequently, in the onModifyAtk handler, the defender parameter becomes null, leading to the TypeError when trying to access defender.activeTurns.

@urkerab
Copy link
Contributor

urkerab commented Jan 13, 2025

That particular SSB ability also has the effect of Wandering Spirit, which means it can easily find itself swapped onto a user of a move that calls getStat. (In theory the crash could happen with Stakeout, if it got swapped onto a user of, say, Shell Side Arm.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants