From 48ff8b248b34b80d5cbf9f6c589a6a5471b98ecd Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Thu, 4 Apr 2024 14:24:02 -0400 Subject: [PATCH] Fix crash on starter screen related to form index out of bounds --- src/data/pokemon-species.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/data/pokemon-species.ts b/src/data/pokemon-species.ts index 3bf1d4653..afbc51708 100644 --- a/src/data/pokemon-species.ts +++ b/src/data/pokemon-species.ts @@ -269,6 +269,10 @@ export abstract class PokemonSpeciesForm { let ret = speciesId.toString(); const forms = getPokemonSpecies(speciesId).forms; if (forms.length) { + if (formIndex >= forms.length) { + console.warn(`Attempted accessing form with index ${formIndex} of species ${getPokemonSpecies(speciesId).getName()} with only ${forms.length || 0} forms`); + formIndex = Math.min(formIndex, forms.length - 1); + } const formKey = forms[formIndex || 0].formKey; switch (formKey) { case SpeciesFormKey.MEGA: @@ -618,6 +622,10 @@ export default class PokemonSpecies extends PokemonSpeciesForm { } getFormSpriteKey(formIndex?: integer) { + if (this.forms.length && formIndex >= this.forms.length) { + console.warn(`Attempted accessing form with index ${formIndex} of species ${this.getName()} with only ${this.forms?.length || 0} forms`); + formIndex = Math.min(formIndex, this.forms.length - 1); + } return this.forms?.length ? this.forms[formIndex || 0].getFormSpriteKey() : '';