From d85f94da9674c85db89e9b87898d2041a8840b66 Mon Sep 17 00:00:00 2001 From: Gondnat Date: Fri, 29 Mar 2019 14:16:36 +0800 Subject: [PATCH] Fix a crash, when SDAnimatedImageView dealloc, displayLinkContext in block will be a bad pointer --- SDWebImage/SDAnimatedImageView.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SDWebImage/SDAnimatedImageView.m b/SDWebImage/SDAnimatedImageView.m index 42c731d2..fc4a9988 100644 --- a/SDWebImage/SDAnimatedImageView.m +++ b/SDWebImage/SDAnimatedImageView.m @@ -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; }