Przeglądaj źródła

Merge pull request #2825 from dreampiggy/fix_sdanimatedimageview_dealloc_on_global_queue

Fix the case when SDAnimatedImageView dealloc on the fetch queue, will cause it trigger the UIKit/AppKit method on non-main queue and captured by UI Main Thread Checker
Kinarobin 6 lat temu
rodzic
commit
c9ea3f12bf
1 zmienionych plików z 9 dodań i 0 usunięć
  1. 9 0
      SDWebImage/Core/SDAnimatedImageView.m

+ 9 - 0
SDWebImage/Core/SDAnimatedImageView.m

@@ -665,7 +665,12 @@ static NSUInteger SDDeviceFreeMemory() {
     if (!fetchFrame && !bufferFull && self.fetchQueue.operationCount == 0) {
         // Prefetch next frame in background queue
         UIImage<SDAnimatedImage> *animatedImage = self.animatedImage;
+        @weakify(self);
         NSOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
+            @strongify(self);
+            if (!self) {
+                return;
+            }
             UIImage *frame = [animatedImage animatedImageFrameAtIndex:fetchFrameIndex];
 
             BOOL isAnimating = NO;
@@ -679,6 +684,10 @@ static NSUInteger SDDeviceFreeMemory() {
                 self.frameBuffer[@(fetchFrameIndex)] = frame;
                 SD_UNLOCK(self.lock);
             }
+            // Ensure when self dealloc, it dealloced on the main queue (UIKit/AppKit rule)
+            dispatch_async(dispatch_get_main_queue(), ^{
+                [self class];
+            });
         }];
         [self.fetchQueue addOperation:operation];
     }