BradLarson / GPUImage

An open source iOS framework for GPU-based image and video processing
http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
BSD 3-Clause "New" or "Revised" License
20.22k stars 4.62k forks source link

Main Thread Checker: Xcode 9,iOS 11 #2512

Open b9AobJ opened 6 years ago

b9AobJ commented 6 years ago

when in xcode 9 build gpuImage project and run in ios 11,the console show this:

================================================================= Main Thread Checker: UI API called on a background thread: -[UIView bounds] PID: 2054, TID: 149860, Thread name: (none), Queue name: com.sunsetlakesoftware.GPUImage.openGLESContextQueue, QoS: 21 Backtrace: 4 SimpleVideoFilter 0x00000001043cb790 39-[GPUImageView recalculateViewGeometry]_block_invoke + 56 5 SimpleVideoFilter 0x00000001043d578c runSynchronouslyOnVideoProcessingQueue + 108 6 SimpleVideoFilter 0x00000001043cb738 -[GPUImageView recalculateViewGeometry] + 108 7 SimpleVideoFilter 0x00000001043cc240 37-[GPUImageView setInputSize:atIndex:]_block_invoke + 312 8 SimpleVideoFilter 0x00000001043d578c runSynchronouslyOnVideoProcessingQueue + 108 9 SimpleVideoFilter 0x00000001043cc0e8 -[GPUImageView setInputSize:atIndex:] + 136 10 SimpleVideoFilter 0x00000001043c6c80 -[GPUImageFilter informTargetsAboutNewFrameAtTime:] + 748 11 SimpleVideoFilter 0x00000001043c9534 -[GPUImageFilter newFrameReadyAtTime:atIndex:] + 216 12 SimpleVideoFilter 0x00000001043d1370 -[GPUImageVideoCamera updateTargetsForVideoCameraUsingCacheTextureAtWidth:height:time:] + 1720 13 SimpleVideoFilter 0x00000001043d1fd8 -[GPUImageVideoCamera processVideoSampleBuffer:] + 2980 14 SimpleVideoFilter 0x00000001043d285c __74-[GPUImageVideoCamera captureOutput:didOutputSampleBuffer:fromConnection:]_block_invoke + 176 15 libdispatch.dylib 0x0000000104cdd49c _dispatch_call_block_and_release + 24 16 libdispatch.dylib 0x0000000104cdd45c _dispatch_client_callout + 16 17 libdispatch.dylib 0x0000000104cec110 _dispatch_queue_serial_drain + 692 18 libdispatch.dylib 0x0000000104ce09a4 _dispatch_queue_invoke + 332 19 libdispatch.dylib 0x0000000104ced104 _dispatch_root_queue_drain_deferred_wlh + 424 20 libdispatch.dylib 0x0000000104cf4100 _dispatch_workloop_worker_thread + 652 21 libsystem_pthread.dylib 0x00000001864dafe0 _pthread_wqthread + 932 22 libsystem_pthread.dylib 0x00000001864dac30 start_wqthread + 4

i think it warn this funtion: GPUImageView.m =====> - (void)recalculateViewGeometry in line 238: CGSize currentViewSize = self.bounds.size;

but i don't know how to fix it,can anybody know that?

b9AobJ commented 6 years ago

Choose scheme -> Diagnotics, remove main thread checker, then the warning will disappear. scheme editor

it could close this warning,but I don't know what other harm it might have

canpoyrazoglu commented 6 years ago

I don't think disabling main thread checker should be the way to go. recalculateViewGeometry method dispatches code to the video processing queue (which is not the main thread) where it accesses the bounds property of the UI element, which should be done from the main thread. Although this is relatively harmless, it'd be nice to see it called there. Maybe (since we're certain that this code is run at video queue, not the main queue) dispatch_sync'ing the call to the bounds property to the main queue would fix that (but I haven't tried).

dkoerner85 commented 6 years ago

Maybe (since we're certain that this code is run at video queue, not the main queue) dispatch_sync'ing the call to the bounds property to the main queue would fix that (but I haven't tried).

This will lead to a deadlock, e. g. init a GPUImagePicture on the main queue -> dispatch sync to video queue -> dispatch sync to main queue, which is still waiting on that first dispatch. I think a true solution would require a deeper change in the dispatch queue usage of the library.

dondonut commented 6 years ago

Have the same problem: Main Thread Checker: UI API called on a background thread: -[UIView layer] PID: 412, TID: 54746, Thread name: (none), Queue name: com.sunsetlakesoftware.GPUImage.processingQueue, QoS: 0

Is it fixable?

canpoyrazoglu commented 6 years ago

@dondonut Apparently it's not something we (as users) can fix by ourselves. However, it doesn't seem to cause any problem (other than the log in the console). I don't think it ever will cause harm unless you are repeatedly editing/animating a frame of a GPUImageView.

dondonut commented 6 years ago

@canpoyrazoglu No, I think this is a problem, because the GPUImageVideo starts slower

lacyrhoades commented 6 years ago

This seems to fix it while not breaking anything either: https://github.com/BradLarson/GPUImage/pull/2533/files

b9AobJ commented 6 years ago

@lacyrhoades hmm! It seems not good for SimpleVideoFilter project! So!!! I try to change some code,maybe it will change this problem!

image

image

I think it's not good maybe someone have more good idea. So i don't PR this Code

dkoerner85 commented 6 years ago

I can only think of one solution: to remove all main-queue-specific code from the runSynchronouslyOnVideoProcessingQueue Blocks. Otherwise, you can always create a scenario, where one call is dispatched sync from the main queue to the video processing queue, which itself dispatches sync to the main queue again, resulting in a deadlock.

Sumit-2singh commented 6 years ago

Check out this changes :-

DamonChen117 commented 6 years ago

It makes unit test failed

codingingBoy commented 6 years ago
__block CGRect currentBounds;

runOnMainQueueWithoutDeadlocking(^{
     currentBounds = self.bounds;
});

There is a certain rist to this solution, it's not in main thread, currentBounds = self.bounds; will be excute after dispatch asyc to main thread, the next time we usecurrentBounds, it may not be changed in main thread, or by the time we use, it changed by the main thread

Sumit-2singh commented 6 years ago

@JohnJGL now you can check edited Comment ...

codingingBoy commented 6 years ago

@Sumit-2singh Perfect👍

Lec2cn commented 6 years ago

So what's the solution of this problem? Still got the console. Using Swift.

jongrall commented 6 years ago

I would also like to see this fixed since GPUImage2 isn't ready for production use (no releases yet), and the original framework is widely used. The new automated tools in Xcode have revealed some issues with this library, but doesn't seem to be actively maintained any longer. @BradLarson what would you suggest?

In fact, looking at the issues reported for GPUImage2, the same problem seems to persist despite the rewrite.

VictorZhang2014 commented 4 years ago

This seems to fix it while not breaking anything either: https://github.com/BradLarson/GPUImage/pull/2533/files

According to the fix 2533 we change the source code and then re-run the build.sh file, finally drag build/Release-iphone folder to your Xcode application project. Then it'd be very good to work!!

Turkey-man commented 3 years ago

@lacyrhoades hmm! It seems not good for SimpleVideoFilter project! So!!! I try to change some code,maybe it will change this problem!

image

image

I think it's not good maybe someone have more good idea. So i don't PR this Code

This solution works and must be accepted as the correct answer.