Open b9AobJ opened 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
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).
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.
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?
@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.
@canpoyrazoglu No, I think this is a problem, because the GPUImageVideo starts slower
This seems to fix it while not breaking anything either: https://github.com/BradLarson/GPUImage/pull/2533/files
@lacyrhoades hmm! It seems not good for SimpleVideoFilter project! So!!! I try to change some code,maybe it will change this problem!
I think it's not good maybe someone have more good idea. So i don't PR this Code
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.
Check out this changes :-
(void)recalculateViewGeometry{ __block CGRect currentBounds;
dispatch_async(dispatch_get_main_queue(), ^(void){ //Run UI Updates currentBounds = self.bounds; runSynchronouslyOnVideoProcessingQueue(^{ CGFloat heightScaling, widthScaling;
// CGFloat imageAspectRatio = inputImageSize.width / inputImageSize.height;
// CGFloat viewAspectRatio = currentViewSize.width / currentViewSize.height;
CGRect insetRect = AVMakeRectWithAspectRatioInsideRect(inputImageSize, currentBounds);
switch(_fillMode)
{
case kGPUImageFillModeStretch:
{
widthScaling = 1.0;
heightScaling = 1.0;
}; break;
case kGPUImageFillModePreserveAspectRatio:
{
widthScaling = insetRect.size.width / currentBounds.size.width;
heightScaling = insetRect.size.height / currentBounds.size.height;
}; break;
case kGPUImageFillModePreserveAspectRatioAndFill:
{
// CGFloat widthHolder = insetRect.size.width / currentBounds.size.width;
widthScaling = currentBounds.size.height / insetRect.size.height;
heightScaling = currentBounds.size.width / insetRect.size.width;
}; break;
}
imageVertices[0] = -widthScaling;
imageVertices[1] = -heightScaling;
imageVertices[2] = widthScaling;
imageVertices[3] = -heightScaling;
imageVertices[4] = -widthScaling;
imageVertices[5] = heightScaling;
imageVertices[6] = widthScaling;
imageVertices[7] = heightScaling;
});
}); }
It makes unit test failed
__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
@JohnJGL now you can check edited Comment ...
@Sumit-2singh Perfect👍
So what's the solution of this problem? Still got the console. Using Swift.
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.
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!!
@lacyrhoades hmm! It seems not good for SimpleVideoFilter project! So!!! I try to change some code,maybe it will change this problem!
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.
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?