Skip to content

Commit 4330fe1

Browse files
committed
fix dispatch_semaphore_wait not nil bug
1 parent 80af37b commit 4330fe1

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

MessageDisplayKit/Classes/Views/MessageContentViews/XHBubblePhotoImageView.m

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,24 @@ - (void)configureMessagePhoto:(UIImage *)messagePhoto thumbnailUrl:(NSString *)t
5555
if ([url.absoluteString isEqualToString:thumbnailUrl]) {
5656

5757
if (CGRectEqualToRect(weakSelf.bounds, CGRectZero)) {
58-
weakSelf.semaphore = dispatch_semaphore_create(0);
59-
dispatch_semaphore_wait(weakSelf.semaphore, DISPATCH_TIME_FOREVER);
60-
weakSelf.semaphore = nil;
58+
if (weakSelf) {
59+
weakSelf.semaphore = dispatch_semaphore_create(0);
60+
dispatch_semaphore_wait(weakSelf.semaphore, DISPATCH_TIME_FOREVER);
61+
weakSelf.semaphore = nil;
62+
}
6163
}
6264

63-
image = [image thumbnailImage:CGRectGetWidth(weakSelf.bounds) * 2 transparentBorder:0 cornerRadius:0 interpolationQuality:1.0];
65+
// if image not nil
6466
if (image) {
67+
// scale image
68+
image = [image thumbnailImage:CGRectGetWidth(weakSelf.bounds) * 2 transparentBorder:0 cornerRadius:0 interpolationQuality:1.0];
6569
dispatch_async(dispatch_get_main_queue(), ^{
66-
weakSelf.messagePhoto = image;
67-
[weakSelf.activityIndicatorView stopAnimating];
70+
// if image not nil
71+
if (image) {
72+
// show image
73+
weakSelf.messagePhoto = image;
74+
[weakSelf.activityIndicatorView stopAnimating];
75+
}
6876
});
6977
}
7078
}

0 commit comments

Comments
 (0)