.llms/rules/ACR_loop_variable_misuse.md
Severity: HIGH — D95237240 caused animation glitches in variable frame rate GIFs
for or while loops where the declared iterator variable is not referenced in the loop bodyframeNumber vs i)i or similar, but loop body uses outer scope variable insteadfor (i in 0 until n) { array[n] } — uses n instead of i@Suppress("UNUSED_VARIABLE") annotation// BAD — uses parameter frameNumber instead of loop variable i
for (i in 0 until frameNumber) {
sum += frameDurations[frameNumber] // ❌ Wrong: adds same duration N times
}
// GOOD — uses loop variable i correctly
for (i in 0 until frameNumber) {
sum += frameDurations[i] // ✅ Correct: sums durations 0 to frameNumber-1
}
When writing loops that iterate through a range, always verify the loop body uses the iterator variable for indexing, not the range boundary parameter.
getTargetRenderTimeMs() in DropFramesFrameScheduler used frameNumber instead of i, causing incorrect animation timing for GIFs with variable frame durationsjumpToFrame() calculated wrong loop counts, causing premature animation termination