Fix a crash, when SDAnimatedImageView dealloc, displayLinkContext in block will be a bad pointer

This commit is contained in:
Gondnat 2019-03-29 14:16:36 +08:00
parent d9c8ba6da2
commit d85f94da96
1 changed files with 3 additions and 1 deletions

View File

@ -742,8 +742,10 @@ static CVReturn renderCallback(CVDisplayLinkRef displayLink, const CVTimeStamp *
// Calculate refresh duration
NSTimeInterval duration = (double)inOutputTime->videoRefreshPeriod / ((double)inOutputTime->videoTimeScale * inOutputTime->rateScalar);
// CVDisplayLink callback is not on main queue
SDAnimatedImageView *imageView = (__bridge SDAnimatedImageView *)displayLinkContext;
__weak SDAnimatedImageView *weakImageView = imageView;
dispatch_async(dispatch_get_main_queue(), ^{
[(__bridge SDAnimatedImageView *)displayLinkContext displayDidRefresh:displayLink duration:duration];
[weakImageView displayDidRefresh:displayLink duration:duration];
});
return kCVReturnSuccess;
}