Left: with three columns, coerceIn(0, 2) clamps the value 5 to 2. Right: with zero columns the range 0..-1 is empty and coerceIn(0, -1) throws IllegalArgumentException; below, a timeline shows why the crash fired only on the first frame of a session and never in tests.
Kotlin

Kotlin’s coerceIn throws « Cannot coerce value to an empty range » instead of clamping

coerceIn(0, n – 1) is not a safe clamp: when n == 0 the range is empty and Kotlin throws IllegalArgumentException. Floor the upper bound or guard n == 0.