Merge pull request #2782 from kinarobin/fix_frame_buffer_bug_when_displayLink_is_pause

Fix frame buffer bug when display link is pause
This commit is contained in:
DreamPiggy 2019-07-09 23:33:00 +08:00 committed by GitHub
commit 2d62616cb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 3 deletions

View File

@ -459,6 +459,8 @@ static NSUInteger SDDeviceFreeMemory() {
- (void)stopAnimating
{
if (self.animatedImage) {
[_fetchQueue cancelAllOperations];
// Using `_displayLink` here because when UIImageView dealloc, it may trigger `[self stopAnimating]`, we already release the display link in SDAnimatedImageView's dealloc method.
#if SD_MAC
CVDisplayLinkStop(_displayLink);
#else
@ -665,9 +667,18 @@ static NSUInteger SDDeviceFreeMemory() {
UIImage<SDAnimatedImage> *animatedImage = self.animatedImage;
NSOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
UIImage *frame = [animatedImage animatedImageFrameAtIndex:fetchFrameIndex];
SD_LOCK(self.lock);
self.frameBuffer[@(fetchFrameIndex)] = frame;
SD_UNLOCK(self.lock);
BOOL isAnimating = NO;
#if SD_MAC
isAnimating = CVDisplayLinkIsRunning(self.displayLink);
#else
isAnimating = !self.displayLink.isPaused;
#endif
if (isAnimating) {
SD_LOCK(self.lock);
self.frameBuffer[@(fetchFrameIndex)] = frame;
SD_UNLOCK(self.lock);
}
}];
[self.fetchQueue addOperation:operation];
}