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

iOS 11 - Main Thread Checker: UI API called on a background thread: -[UIView layer] #143

Open
codegastudio opened this issue Sep 28, 2017 · 3 comments

Comments

@codegastudio
Copy link

Hi,

With Xcode 9 and device with iOS 11
When i activate blur i get the following message in logger

Main Thread Checker: UI API called on a background thread: -[UIView layer]
PID: 2255, TID: 1737593, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 21
Backtrace:
4 MyApp 0x00000001004a9b94 -[FXBlurView blurLayer] + 40
5 MyApp 0x00000001004a976c -[FXBlurView blurRadius] + 40
6 MyApp 0x00000001004abb8c __46-[FXBlurView updateAsynchronously:completion:]_block_invoke + 68
7 libdispatch.dylib 0x000000010082149c _dispatch_call_block_and_release + 24
8 libdispatch.dylib 0x000000010082145c _dispatch_client_callout + 16
9 libdispatch.dylib 0x000000010082d56c _dispatch_queue_override_invoke + 980
10 libdispatch.dylib 0x0000000100832b54 _dispatch_root_queue_drain + 616
11 libdispatch.dylib 0x0000000100832880 _dispatch_worker_thread3 + 136
12 libsystem_pthread.dylib 0x0000000182c5f130 _pthread_wqthread + 1268
13 libsystem_pthread.dylib 0x0000000182c5ec30 start_wqthread + 4

- (void)updateAsynchronously:(BOOL)async completion:(void (^)())completion
{
    if ([self shouldUpdate])
    {
        UIImage *snapshot = [self snapshotOfUnderlyingView];
        if (async)
        {
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

                UIImage *blurredImage = [self blurredSnapshot:snapshot radius:self.blurRadius];
                dispatch_sync(dispatch_get_main_queue(), ^{

                    [self setLayerContents:blurredImage];
                    if (completion) completion();
                });
            });
        }
        else
        {
            [self setLayerContents:[self blurredSnapshot:snapshot radius:[self blurPresentationLayer].blurRadius]];
            if (completion) completion();
        }
    }
    else if (completion)
    {
        completion();
    }
}

Possible to try with

...
dispatch_async(dispatch_get_main_queue(), ^{
        ...
});
...

Best regards,

@mixiu7992
Copy link

i encounter this problem and some can fix it?

@floschliep
Copy link

I fixed this by getting the blur radius before entering the background queue:

CGFloat blurRadius = self.blurRadius;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    UIImage *blurredImage = [self blurredSnapshot:snapshot radius:blurRadius];
    dispatch_sync(dispatch_get_main_queue(), ^{

        [self setLayerContents:blurredImage];
        if (completion) completion();
    });
});

hongrich added a commit to hongrich/FXBlurView that referenced this issue Oct 19, 2017
@zerocc2017
Copy link

I fixed this by getting the blur radius before entering the background queue:

CGFloat blurRadius = self.blurRadius;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    UIImage *blurredImage = [self blurredSnapshot:snapshot radius:blurRadius];
    dispatch_sync(dispatch_get_main_queue(), ^{

        [self setLayerContents:blurredImage];
        if (completion) completion();
    });
});

this bug is why? can explain for me。thx

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

No branches or pull requests

4 participants