unblockjam: (fix) use coerceIn in changeLevel to prevent OOB level index
- Commit
c0d97993fb8d763612122095dc5594750ec6d4d0- Author
- Anonymous <[email protected]>
- When
- 2026-03-16 08:34 UTC (8 months ago)
- Parents
350cb2c
Diff
games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/MainActivity.kt
diff --git a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/MainActivity.kt b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/MainActivity.ktindex 0383cb987f..213f33733f 100644--- a/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/MainActivity.kt+++ b/games/unblockjam/src/main/java/com/vayunmathur/games/unblockjam/MainActivity.kt@@ -141,7 +141,8 @@ fun GameScreen(backStack: NavBackStack<Route>, completedLevelsRepository: Comple var levelStats by remember { mutableStateOf(completedLevelsRepository.getLevelStats()) } fun changeLevel(newLevelIndex: Int) {- backStack[backStack.lastIndex] = Route.Game(newLevelIndex)+ val boundedIndex = newLevelIndex.coerceIn(0, LevelData.LEVELS.lastIndex)+ backStack[backStack.lastIndex] = Route.Game(boundedIndex) } fun getCurrentMoves(): Int {