cocos2d / cocos2d-objc

Cocos2d for iOS and OS X, built using Objective-C
http://www.cocos2d-objc.org
Other
4.07k stars 1.16k forks source link

presentViewController on CCDirector results in error after completion #1017

Open mobiletoly opened 9 years ago

mobiletoly commented 9 years ago

So I have a game that works in landscape mode and want to add share dialog functionality via UIActivityViewController. Here is a code:

-(void)share
{
    NSMutableArray* sharingItems = [NSMutableArray new];
    [sharingItems addObject:@"Test message"];
    UIActivityViewController* activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];

    CCDirector* director = [CCDirector sharedDirector];
    [director presentViewController:activityController animated:YES completion:nil];
}

Run my app, choose Share, select Messages to share info via text message. Messages dialog remains in landscape mode and when I close a dialog (to get back to my app) - everything works fine. If I rotate Messages to portrait mode and then close it - I start seeing these errors:

OpenGL error GL_INVALID_FRAMEBUFFER_OPERATION detected at -[CCRenderer flush] 653 OpenGL error GL_INVALID_OPERATION detected at -[CCGLView swapBuffers] 286

and screen becomes unresponsive (also I see GL_INVALID_FRAMEBUFFER_OPERATION / GL_INVALID_OPERATION every time when I touch a screen).

The only workaround I found so far is to create an additional UIViewControler to add its view to CCDirector's view:

-(void)share
{
    ...
    CCDirector* director = [CCDirector sharedDirector];
    UIViewController* tempVC = [[UIViewController alloc] init];
    [[director view] addSubview:tempVC.view];
    [tempVC presentViewController:activityController animated:YES completion:nil];
}

then it works fine (well, I still have to remove that tempVC.view at some point, that I can do with setting completionHandler for UIActivityViewController).

I might be wrong but this issue looks like a bug to me.

anka commented 9 years ago

Have a look at http://forum.cocos2d-swift.org/t/presenting-skstoreproductviewcontroller-in-game-causes-troubles/15186. Maybe stopping the animation and resuming it afterwards fixes your problem for the moment.