CoreAnimation:[EAGLContext renderbufferStorage:fromDrawable:] 是从非主线程调用的

Posted

技术标签:

【中文标题】CoreAnimation:[EAGLContext renderbufferStorage:fromDrawable:] 是从非主线程调用的【英文标题】:CoreAnimation:[EAGLContext renderbufferStorage:fromDrawable:] was called from a non-main thread 【发布时间】:2018-07-26 11:53:30 【问题描述】:

在我的音乐应用程序中当我尝试显示广告时(我正在使用 Triton SDK),有时应用程序会崩溃并给我这个错误:

CoreAnimation:[EAGLContext renderbufferStorage:fromDrawable:] 在隐式事务中从非主线程调用!请注意,如果没有明确的 CATransaction 或调用 [CATransaction flush],这可能是不安全的。

我的广告包含横幅和音频 MP3,请任何人帮助我。

这里是流歌代码,连续调用:-

- (void) configureAudiostremaing 

if ([Singletone sharedSingletone].playMusic == NO) 



    NSError *setCategoryError = nil;

    NSError *activationError = nil;

    [[AVAudioSession sharedInstance] setActive:YES withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:&activationError];



    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:&setCategoryError];

    [app beginReceivingRemoteControlEvents];







else 



    NSError *setCategoryError = nil;

    NSError *activationError = nil;


    [[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:&activationError];

    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:&setCategoryError];

        [app beginReceivingRemoteControlEvents];



当广告显示所有在主线程中调用的函数时,已经调用了以下函数,但有时我仍然遇到崩溃问题:-

//for banner view



- (void) showAdbanner 



[Singletone sharedSingletone].impressionUrlCalled = NO;

[[Singletone sharedSingletone].bannerView removeFromSuperview];



BOOL adFrameFound = NO;



for (int i = 0; i < [[Singletone sharedSingletone].ad.companionBanners count]; i++) 



    TDCompanionBanner *banner = [[Singletone sharedSingletone].ad.companionBanners objectAtIndex:i];



    if (banner.width == 300 && banner.height == 250) 

        [Singletone sharedSingletone].bannerView = [[TDBannerView alloc] initWithWidth:banner.width andHeight:banner.height];

        adFrameFound = YES;

        break;

    





if (adFrameFound == NO) 

    [Singletone sharedSingletone].bannerView = [[TDBannerView alloc] initWithWidth:300 andHeight:250];





if (songProgressView!=nil) 

    [Singletone sharedSingletone].bannerView.translatesAutoresizingMaskIntoConstraints = NO;

    [Singletone sharedSingletone].bannerView.backgroundColor = [blackColor colorWithAlphaComponent:0.5];

    [self.view addSubview:[Singletone sharedSingletone].bannerView];



    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:[Singletone sharedSingletone].bannerView

                                                          attribute:NSLayoutAttributeTop

                                                          relatedBy:NSLayoutRelationEqual

                                                          toItem:songProgressView

                                                          attribute:NSLayoutAttributeBottom

                                                         multiplier:1.0 constant:0.0]];



    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:[Singletone sharedSingletone].bannerView

                                                          attribute:NSLayoutAttributeCenterX

                                                          relatedBy:NSLayoutRelationEqual

                                                             toItem:self.view

                                                          attribute:NSLayoutAttributeCenterX

                                                         multiplier:1.0 constant:0.0]];

    [[Singletone sharedSingletone].bannerView presentAd:[Singletone sharedSingletone].ad];

    

我从 crashlytics 得到这份报告:

http://prntscr.com/kbl58s

【问题讨论】:

请添加代码 【参考方案1】:

试试这个

dispatch_async(dispatch_get_main_queue(), ^

// put your code here to be call
);

【讨论】:

我已经在必填字段中使用了这个 dispatch_async 你能告诉我我需要在哪个函数中使用它并且我已经更新了我的问题请检查一次 还要检查一下这个presentAd函数调用背后的代码,那里一定有一些过渡 感谢您的回复..是的,我在主线程中调用了 ShowAdbanner,如何检查当前广告中的转换对不起,我无法理解,请解释一下 只需右键单击 presentAd 即可跳转到其定义 PresentAd 中不存在转换请检查 SS (prntscr.com/kbm3sj) 并请检查从 Crashlytics 收到的此 SS (prntscr.com/kbl58s)

以上是关于CoreAnimation:[EAGLContext renderbufferStorage:fromDrawable:] 是从非主线程调用的的主要内容,如果未能解决你的问题,请参考以下文章

CloudKit CoreAnimation 错误

CoreAnimation汇总

—— CoreAnimation

iOS CoreAnimation 基础动画CABasicAnimation

CoreAnimation - 获取绘制内容纹理的最快方法

iOS关于CoreAnimation动画知识总结