Billbris
Billbris

Reputation: 703

Cocos2d fails on iPad yet works in simulator

I have a very simple game using Xcode v4.2.1, Cocos2d v5.0.1. I've tried both compilers in Xcode (LLVM GCC 4.2 and Apple LLVM compiler 3.0. Is there a preference??) On the game screen is a UIKit button that presents the user with a Interface Builder (nib) Settings/Options screen to customize the game a bit. This is all based on what I learned in Ray Wenderlich's tutorial (http://www.raywenderlich.com/4817/how-to-integrate-cocos2d-and-uikit).

After the user makes their changes, they are returned to the game and the changes are in place.

This all works as I want in the simulator, however, when I test the game on an iPad I get the following errors in the debug window:

2012-01-27 18:25:27.305 BonkBonk[1082:707] failed to call context
2012-01-27 18:25:27.310 BonkBonk[1082:707] cocos2d: surface size: 1024x768
2012-01-27 18:25:27.316 BonkBonk[1082:707] Failed to make complete framebuffer object 8cdd
OpenGL error 0x0506 in -[EAGLView swapBuffers]
OpenGL error 0x0506 in -[EAGLView swapBuffers]
OpenGL error 0x0506 in -[EAGLView swapBuffers]

The OpeenGl errors continue on indefinitely.

I use the function viewWillAppear to capture the return from the settings/options screen so that I can pass the new settings to the game layer. If I comment out this code the problem goes away, however, I am not able to get the new user settings to the game layer.

Here is the code:

- (void) viewWillAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    //CCScene *scene = [[CCDirector sharedDirector] runningScene];
    CCScene *scene = [BonkBonkLayer scene];
    id layer = [scene getChildByTag:1];
    [layer userSettings];
    [super viewWillAppear:animated];
}

The commented out line //CCSene *scene... was another failed attempt at getting the layer object from the scene so that I could call the userSettings method where the game layer then can assimilate it into the game.

Upvotes: 1

Views: 2000

Answers (3)

user1459524
user1459524

Reputation: 3603

I had similar errors in my app when implementing Cocos2D via CCGLView.

The solution that worked for me was to call

[[CCDirector sharedDirector] popScene]

when presenting the Interface Builder Viewcontroller.

Upvotes: 0

hayashi_leo
hayashi_leo

Reputation: 41

I had a similar problem. I've integrated cocos2d with UIKit. I added adMob. The problem shows up when user clicks on Ads that presents the google BrowserView. If you dismiss the View using the Done button, the App works fine. However, if user press the Home button when in Browser View, and resume the App, I got the same exception.

OpenGL error 0x0506 in -[EAGLView swapBuffers]

UIKit buttons and the Ads are shown, but it does not render the cocos2d layer.

I got the solution from https://github.com/cocos2d/cocos2d-iphone/pull/198, but I did not change the cocos2d source. Instead, I added a boolean ivar called isAnimating in AppDelegate.m, and expose the property to the Layers.

To solve this, I stop animation on CCDirector before entering google Browser View. and start animation once resume to the App. isAnimating ivar is used to check that start animation is not called twice.

Hope it helps,

Upvotes: 1

Billbris
Billbris

Reputation: 703

OK, so I've found something that alleviates my issue.

If anyone knows anything about this, please let me know. I will continue to use this fix unless I hear a reason from someone more knowledgable than myself (and that's not that difficult).

The solution is found in the comment by "psionic" at the end of the following discussion: http://www.cocos2d-iphone.org/forum/topic/7068.

Basically, I created a static bool in the EAGLView class (EAGLView.m) that surrounds the call to _resizeFromLayer in the layoutSubViews member function. The call to _resizeFromLayer is only called the first time through, and then never again.

Please read the above discussion and let me know what you like/dislike about this solution, other than the obvious... it's a hack.

A hack,that works. I think.

Upvotes: 1

Related Questions