我已经将UnityAds的SKD整合到我的游戏中,以显示全屏间的视频广告。
当视频完成后,广告框架提供到AppStore的链接。当我选择此链接时,将打开AppStore。我的应用程序在这一刻崩溃了,把EXC_BAD_ACCESS扔到了CCGraphicsBufferGLUnsynchronized上。
启动我的应用程序时,UnityAds SDK被初始化如下:
[[UnityAds sharedInstance] startWithGameId:UNITYADS_MYAPP_ID
andViewController:[CCDirector sharedDirector]
];如您所见,我正在传递CCDirector sharedDirector作为视图控制器。我要提这一点,因为这可能是问题的一部分吗?
稍后,我将从这样的UnityAds场景中调用Cocos2D SDK:
-(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类中)
-(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下运行
发布于 2015-02-28 14:25:10
好吧,我自己找到了解决办法。似乎崩溃的发生是因为应用程序在后台,呈现继续进行。所以我所要做的就是确保在应用程序被移到后台之后,渲染不会恢复。
我现在这样做:
// 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。
希望这能帮助其他人解决同样的问题。
https://stackoverflow.com/questions/28782270
复制相似问题