Fix crash when frames not preloaded in time.

This commit is contained in:
Daniel Farrelly 2016-05-27 13:07:25 +10:00
parent aa2e6a11c5
commit 79f01b02ad
2 changed files with 7 additions and 1 deletions

View File

@ -20,6 +20,12 @@ class GifuTests: XCTestCase {
XCTAssertTrue(animator.isAnimatable)
}
func testCurrentFrame() {
XCTAssertEqual(animator.currentFrameIndex, 0)
XCTAssertEqual(animator.currentFrameDuration, NSTimeInterval.infinity)
XCTAssertNil(animator.currentFrameImage)
}
func testFramePreload() {
let expectation = expectationWithDescription("frameDuration")

View File

@ -92,7 +92,7 @@ class Animator {
/// - parameter index: The index of the duration.
/// - returns: The duration of the given frame.
func durationAtIndex(index: Int) -> NSTimeInterval {
return animatedFrames[index].duration
return animatedFrames[safe: index]?.duration ?? NSTimeInterval.infinity
}
/// Checks whether the frame should be changed and calls a handler with the results.