Add some protect code for user-provided frameCount and loopCount to SDAnimatedImagePlayer

This commit is contained in:
DreamPiggy 2019-11-04 12:39:57 +08:00
parent 4c7cbc6aa7
commit 6d4b241c39
1 changed files with 8 additions and 0 deletions

View File

@ -204,6 +204,9 @@
} }
- (void)seekToFrameAtIndex:(NSUInteger)index loopCount:(NSUInteger)loopCount { - (void)seekToFrameAtIndex:(NSUInteger)index loopCount:(NSUInteger)loopCount {
if (index >= self.totalFrameCount) {
return;
}
self.currentFrameIndex = index; self.currentFrameIndex = index;
self.currentLoopCount = loopCount; self.currentLoopCount = loopCount;
} }
@ -219,6 +222,11 @@
NSTimeInterval duration = self.displayLink.duration; NSTimeInterval duration = self.displayLink.duration;
NSUInteger totalFrameCount = self.totalFrameCount; NSUInteger totalFrameCount = self.totalFrameCount;
if (totalFrameCount == 0) {
// Total frame count is 0, wrong configuration
[self stopPlaying];
return;
}
NSUInteger currentFrameIndex = self.currentFrameIndex; NSUInteger currentFrameIndex = self.currentFrameIndex;
NSUInteger nextFrameIndex = (currentFrameIndex + 1) % totalFrameCount; NSUInteger nextFrameIndex = (currentFrameIndex + 1) % totalFrameCount;