首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cocos2d on iOS: EXC_BAD_ACCESS in CCGraphicsBufferGLUnsynchronized在广告后离开应用程序

Cocos2d on iOS: EXC_BAD_ACCESS in CCGraphicsBufferGLUnsynchronized在广告后离开应用程序
EN

Stack Overflow用户
提问于 2015-02-28 13:33:00
回答 1查看 190关注 0票数 0

我已经将UnityAds的SKD整合到我的游戏中,以显示全屏间的视频广告。

当视频完成后,广告框架提供到AppStore的链接。当我选择此链接时,将打开AppStore。我的应用程序在这一刻崩溃了,把EXC_BAD_ACCESS扔到了CCGraphicsBufferGLUnsynchronized上。

启动我的应用程序时,UnityAds SDK被初始化如下:

代码语言:javascript
复制
[[UnityAds sharedInstance] startWithGameId:UNITYADS_MYAPP_ID
                                        andViewController:[CCDirector sharedDirector]
                ];

如您所见,我正在传递CCDirector sharedDirector作为视图控制器。我要提这一点,因为这可能是问题的一部分吗?

稍后,我将从这样的UnityAds场景中调用Cocos2D SDK:

代码语言:javascript
复制
-(void)showFullscreenAd {
    //  Stop Cocos2D rendering
    [[CCDirector sharedDirector] pause];
    [[CCDirector sharedDirector] stopAnimation];

    //  Is an ad available?
    if ([[UnityAds sharedInstance] canShowAds]) {
        //  Display the ad
        [[UnityAds sharedInstance] setZone:@"rewardedVideoZone"];
        [[UnityAds sharedInstance] show];
    }
}

如您所见,在显示添加之前,我正在停止Cocos2D呈现。

当我在add中选择AppStore链接时,我的应用程序会崩溃。这是Xcode在崩溃后向我指出的代码(在CCGraphicsBufferGLUnsynchronized类中)

代码语言:javascript
复制
-(void)prepare
{
    _count = 0;

    GLenum target = (GLenum)_type;
    glBindBuffer(_type, _buffer);
 ==>    _ptr = _mapBufferRange(target, 0, (GLsizei)(_capacity*_elementSize), BUFFER_ACCESS_WRITE);
    glBindBuffer(target, 0);
    CC_CHECK_GL_ERROR_DEBUG();
}

有人能为我指出正确的调试方向吗?

我正在iPad和iPhone上运行应用程序,在iOS 8.1.3下运行

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-28 14:25:10

好吧,我自己找到了解决办法。似乎崩溃的发生是因为应用程序在后台,呈现继续进行。所以我所要做的就是确保在应用程序被移到后台之后,渲染不会恢复。

我现在这样做:

代码语言:javascript
复制
//  Added a flag to control resuming of rendering
@property (readwrite) bool resumeRendering;


[...]


-(void)showFullscreenAd {
    //  Stop Cocos2D rendering
    [[CCDirector sharedDirector] pause];
    [[CCDirector sharedDirector] stopAnimation];

    // Set to resume redering by default
     _resumeRendering = YES;

    //  Is an ad available?
    if ([[UnityAds sharedInstance] canShowAds]) {
        //  Display the ad
        [[UnityAds sharedInstance] setZone:@"rewardedVideoZone"];
        [[UnityAds sharedInstance] show];
    }
}


[...]


#pragma mark - UnityAdsDelegate

//  This method is called when the interstitial ad is discarded
//  check if rendering should be resumed
-(void)unityAdsDidHide {
    if ( _resumeRendering ) {
        [[CCDirector sharedDirector] resume];
        [[CCDirector sharedDirector] startAnimation];
    }

    // do anything else here
    // In my case I transfer to the next scene
    [...]
}

-(void)unityAdsWillLeaveApplication {
   // Will leave application. Make sure rendering is not resumed anymore
    _resumeRendering = NO;
}

当用户现在单击广告中的AppStore链接时,将调用unityAdsWillLeaveApplication方法,我可以将resumeRendering标记为false。

希望这能帮助其他人解决同样的问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28782270

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档