koral--/android-gif-drawable · error · IndexOutOfBoundsException
Frame index is not in range <0;
Error message
Frame index is not in range <0;<numberOfFrames>>
What it means
throwIfFrameIndexOutOfBounds verifies a frame index against the GIF's total frame count and throws IndexOutOfBoundsException('Frame index is not in range <0;<numberOfFrames>>') when index < 0 or index >= numberOfFrames. It guards frame-addressing calls like getFrameDuration and seekToFrameGL.
Solutions
- Check index against gifDrawable.getNumberOfFrames() (or getNumberOfFrame on handle) before use.
- Fix off-by-one loops: iterate i < numberOfFrames, not <=.
- Clamp or wrap the index: Math.min(index, numberOfFrames - 1).
Example fix
// before
int duration = gifInfoHandle.getFrameDuration(frameIndex);
// after
if (frameIndex >= 0 && frameIndex < gifInfoHandle.getNumberOfFrames()) {
int duration = gifInfoHandle.getFrameDuration(frameIndex);
} Defensive patterns
Strategy: validation
Validate before calling
if (index >= 0 && index < gifInfoHandle.getNumberOfFrames()) { gifInfoHandle.getFrameDuration(index); } Type guard
boolean isFrameIndexValid(GifInfoHandle h, int i) { return i >= 0 && i < h.getNumberOfFrames(); } Try / catch
try { int d = gifInfoHandle.getFrameDuration(index); } catch (IndexOutOfBoundsException e) { /* clamp index or skip */ } Prevention
- Iterate frames with i < getNumberOfFrames()
- Recompute frame counts after loading a new GIF
- Never hardcode frame indices
When it happens
Trigger: Calling getFrameDuration(index) or seekToFrame index >= getNumberOfFrames(), or a negative index; often caching a frame index across different GIFs with fewer frames.
Common situations: Iterating frames with an off-by-one (<= numberOfFrames); hardcoding frame numbers; reusing indices after loading a shorter GIF.
Related errors
- Loop count of range <0, 65535>
- Speed factor is not positive
- Sample size out of range <1, 65535>
- Bitmap is recycled
- Bitmap ia too small, size must be greater than or equal to…
AI-assisted analysis of koral--/android-gif-drawable@26ff795f78 (2026-09-10).
Data as JSON: /api/errors/677c18ce0c06c335.
Report an issue: GitHub.
Appendix: source
Thrown at android-gif-drawable/src/main/java/pl/droidsonroids/gif/GifInfoHandle.java:372
}
void stopDecoderThread() {
stopDecoderThread(gifInfoPtr);
}
void initTexImageDescriptor() {
initTexImageDescriptor(gifInfoPtr);
}
void seekToFrameGL(@IntRange(from = 0) final int index) {
throwIfFrameIndexOutOfBounds(index);
seekToFrameGL(gifInfoPtr, index);
}
private void throwIfFrameIndexOutOfBounds(@IntRange(from = 0) final int index) {
final int numberOfFrames = getNumberOfFrames(gifInfoPtr);
if (index < 0 || index >= numberOfFrames) {
throw new IndexOutOfBoundsException("Frame index is not in range <0;" + numberOfFrames + '>');
}
}
}View on GitHub (pinned to 26ff795f78)