Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDWebImageCombinedOperation setCancelBlock:]: message sent to deallocated instance #798

Closed
alexiscreuzot opened this issue Jul 10, 2014 · 16 comments
Labels
Milestone

Comments

@alexiscreuzot
Copy link
Contributor

I get this crash in my app. I'm doing a lot of prefetching, don't know if it's relevant to this issue.

@bpoplauschi
Copy link
Member

Could you please provide a stack trace? Also, try using the Zombies Instrument to determine the object that is causing the crash and why

@alexiscreuzot
Copy link
Contributor Author

The culprit seems to be :
self.cancelBlock = nil; line 271 of SDWebImageCombinedOperation
It happens only sporadically so I'll have to find a way to make it happen again so I get the stack trace.

@alexiscreuzot
Copy link
Contributor Author

This is the best I get :
capture decran 2014-07-11 a 17 39 49
My last logs being :
[SDWebImageCombinedOperation setCancelBlock:]: message sent to deallocated instance 0xc5a9c10
Zombies don't help much as well as trying to go forward :/

@alexiscreuzot
Copy link
Contributor Author

I managed to get a raw crash log, SDWebImagePrefetcher seems definitely at fault. I'll dig into this.
__
Application Specific Information:
objc_msgSend() selector name: setCancelBlock:

Thread 0 Crashed:
0 libobjc.A.dylib 0x389ac626 objc_msgSend + 6
1 CoreFoundation 0x2e177a55 -[NSArray makeObjectsPerformSelector:] + 178
2 winkli 0x00154699 -SDWebImageManager cancelAll
3 winkli 0x00155613 -SDWebImagePrefetcher cancelPrefetching
4 winkli 0x00155495 -SDWebImagePrefetcher prefetchURLs:progress:completed:
5 winkli 0x00155459 -SDWebImagePrefetcher prefetchURLs:
6 winkli 0x00087a81 -Event parseEventParticipants:
7 winkli 0x0007f6c3 +FQLRequest parseQueryForEvent:withResponse:
8 winkli 0x0007f335 54+[FQLRequest friendsOfFriendsForEvent:withCompletion:]_block_invoke (FQLRequest.m:299)
9 winkli 0x000dc975 __51-[FBRequestConnection completeWithResults:orError:]_block_invoke602 (FBRequestConnection.m:1283)
10 winkli 0x000eb845 __39-[FBTask dependentTaskWithBlock:queue:]_block_invoke_2 (FBTask.m:254)
11 libdispatch.dylib 0x38e8bd53 _dispatch_call_block_and_release + 8
12 libdispatch.dylib 0x38e8bd3f _dispatch_client_callout + 20
13 libdispatch.dylib 0x38e8e6c3 _dispatch_main_queue_callback_4CF + 276
14 CoreFoundation 0x2e1d2641 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE
+ 6
15 CoreFoundation 0x2e1d0f0d __CFRunLoopRun + 1306
16 CoreFoundation 0x2e13b729 CFRunLoopRunSpecific + 522
17 CoreFoundation 0x2e13b50b CFRunLoopRunInMode + 104
18 GraphicsServices 0x330aa6d3 GSEventRunModal + 136
19 UIKit 0x30a9c871 UIApplicationMain + 1134
20 winkli 0x00086477 main (main.m:16)
21 libdyld.dylib 0x38ea0ab7 start + 0

@bpoplauschi
Copy link
Member

@kirualex we appreciate you working on this. I will take a look as soon as I have some time.

@bpoplauschi bpoplauschi added this to the 3.7.0 milestone Jul 14, 2014
@bpoplauschi
Copy link
Member

What version of SDWebImage are you using? Does it reproduce with the latest master version? It might be an issue with the SDWebImagePrefetcher, but it could also be an issue with the block you are passing.

@bpoplauschi bpoplauschi modified the milestones: Future, 3.7.0 Jul 14, 2014
@rromanchuk
Copy link
Contributor

I am also getting this using latest 3.7.0

when calling [sharedImagePrefetcher cancelPrefetching]; i am getting the following crash

Incident Identifier: B2B50A5B-0EEF-4767-878B-16BD6CCD3141
CrashReporter Key:   375A9052-1C42-4A48-A4A8-90061C692FE1
Hardware Model:      iPhone6,1
Process:         Frontback β [4084]
Path:            /Users/USER/Frontback β.app/Frontback β
Identifier:      me.frontback.beta
Version:         2342
Code Type:       ARM
Parent Process:  launchd [1]

Date/Time:       2014-07-16T02:41:06Z
OS Version:      iPhone OS 7.1.1 (11D201)
Report Version:  104

Exception Type:  SIGSEGV
Exception Codes: SEGV_ACCERR at 0x1
Crashed Thread:  0

Application Specific Information:
objc_msgSend() selector name: setCancelBlock:

Thread 0 Crashed:
0   libobjc.A.dylib                      0x3861f636 objc_msgSend + 22
1   CoreFoundation                       0x2ddf2a95 -[NSArray makeObjectsPerformSelector:] + 178
2   Frontback β                          0x0018165d -[SDWebImageManager cancelAll] (SDWebImageManager.m:286)
3   Frontback β                          0x001825d7 -[SDWebImagePrefetcher cancelPrefetching] (SDWebImagePrefetcher.m:135)
4   Frontback β                          0x001c783d __unnamed_356 + 10
5   Frontback β                          0x00baa761 rb_vm_dispatch + 4866
6   Frontback β                          0x0079e891 vm_dispatch + 362
7   Frontback β                          0x007abe75 rb_scope__openFullscreen:__ (grid_controller.rb:382)

@alexiscreuzot
Copy link
Contributor Author

Same problem.

- (void)cancelAll in SDWebImageManager seems to be the issue, when called from - (void)cancelPrefetching in SDWebImagePrefetcher.
Digging.

@bpoplauschi
Copy link
Member

Until we can figure out the exact cause, made a temp fix (e95224b) with the suggested _cancelBlock = nil

@bpoplauschi
Copy link
Member

3.7.1 just got out. Could you please check and see if this crash still reproduces or is fixed as it should be?

@alexiscreuzot
Copy link
Contributor Author

This seems to do the trick for me, but I will have a definitive answer next week after more intensive testing.

@bpoplauschi
Copy link
Member

Great, please post the feedback as soon as you have it

@alexiscreuzot
Copy link
Contributor Author

Well the fix did improve things but the issue still arise :/ I'm pulling directly from the git repo though.

@Air-Craft
Copy link

Just been looking into this as it's causing a significant number of crashes amongst users in the app I'm working on. Might it be a BAD_ACCESS in disguise (memory gets freed and repurposed into another class type resulting in the "cancel" or "setCancelBlock" to crash)?

A bit of guesswork here but might this be a result of a stack overflow due to a circular loop here:

~L244

        operation.cancelBlock = ^{
            [subOperation cancel];

            @synchronized (self.runningOperations) {
                [self.runningOperations removeObject:weakOperation];
            }
        };

and ~L318

- (void)cancel {
    self.cancelled = YES;
    if (self.cacheOperation) {
        [self.cacheOperation cancel];
        self.cacheOperation = nil;
    }
    if (self.cancelBlock) {
        self.cancelBlock();

...ie cancelBlock calls cancel which calls cancelBlock...

Unfortunately, I can't recreate this error so I'm trying to come at it by following the code logic...

@timkoma
Copy link

timkoma commented May 7, 2015

You can try my PR: #1069

@bpoplauschi
Copy link
Member

Let's see if this still happens with 4.0. It shouldn't

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants