From 48c2bdf1d82dee7e7ee5efe5eb0bc54b3a6d2784 Mon Sep 17 00:00:00 2001 From: MokaStitcher <54149968+MokaStitcher@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:29:35 +0200 Subject: [PATCH] [Bug] fix starter select crash when a variant preference is incorrect (#4209) --- src/ui/starter-select-ui-handler.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/ui/starter-select-ui-handler.ts b/src/ui/starter-select-ui-handler.ts index d99c25bc612..ac6af5cbb04 100644 --- a/src/ui/starter-select-ui-handler.ts +++ b/src/ui/starter-select-ui-handler.ts @@ -995,15 +995,14 @@ export default class StarterSelectUiHandler extends MessageUiHandler { delete starterAttributes.shiny; } - if (starterAttributes.variant !== undefined && !isNaN(starterAttributes.variant)) { + if (starterAttributes.variant !== undefined) { const unlockedVariants = [ - hasNonShiny, hasShiny && caughtAttr & DexAttr.DEFAULT_VARIANT, hasShiny && caughtAttr & DexAttr.VARIANT_2, hasShiny && caughtAttr & DexAttr.VARIANT_3 ]; - if (!unlockedVariants[starterAttributes.variant + 1]) { // add 1 as -1 = non-shiny - // requested variant wasn't unlocked, purging setting + if (isNaN(starterAttributes.variant) || starterAttributes.variant < 0 || !unlockedVariants[starterAttributes.variant]) { + // variant value is invalid or requested variant wasn't unlocked, purging setting delete starterAttributes.variant; } }