更换场景时cocos2d Mac OpenGL错误

时间:2013-02-27 19:17:20

标签: macos opengl cocos2d-iphone

我有一个cocos2d Mac应用程序,它使用Core Data存储一些用户可以编辑的数据。用户可以单击“选项”按钮关闭全屏cocos2d视图并转到标准Cocoa窗口,以编辑数据。我想在Cocoa窗口上有一个“保存并恢复”按钮,以便用户可以跳回到全屏cocos2d驱动的视图。在cocos2d视图中,我捕获屏幕并将应用程序置于“Kiosk”模式per the Apple docs

这在某些时候有用。不幸的是,有时屏幕变黑并锁定。查看控制台(Console.app),当屏幕锁定时,我看到以下NVidia错误:

enter image description here

如上所述,这只会在某些时候发生。我已经尝试了1000种不同的方法来追查这个错误,但是我能够根除它的唯一方法是将“保存并恢复”按钮更改为“退出”按钮并让用户重新启动应用程序。虽然这不是一件大事,但这会带来不便。

我的应用程序中的大多数cocos2d逻辑是通过我调用的场景TypingLayer.当我最初启动时,以下AppDelegate代码将用户带入TypingLayer

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{

    // Initial cocos2d setup
    director = (CCDirectorMac*) [CCDirector sharedDirector];
    [director setDisplayStats:NO];
    [director setView:glView_];

    [CCTexture2D PVRImagesHavePremultipliedAlpha:YES];
    [director setResizeMode:kCCDirectorResize_NoScale];
    [cocos2dWindow_ setAcceptsMouseMovedEvents:NO];

    [_window setReleasedWhenClosed:NO];
    [_window orderOut:self];

    // Double check for defaults -- in the event that the user deleted them
    [self checkDefaults];

    [self proceedWithApplicationLaunch:aNotification];
}

当用户单击“选项”按钮时,将触发以下代码:

- (void) takeUserToOptions:(NSNotification *)aNotification
{
    [glView_ exitFullScreenModeWithOptions:nil];
    [_window makeKeyAndOrderFront:self];
    [glView_ setHidden:YES];

    // Drops the typing layer and pushes a blank scene
    [director replaceScene:[CCScene node]];

}

这一切似乎都运作良好。当用户单击“保存并恢复”时,会发生以下情况:

- (IBAction)resume:(id)sender
{
    [_window orderOut:self];
    [glView_ setHidden:NO];

    [self checkDefaults];

    [self saveAction:self];

    // Call with slight delay
    [self performSelector:@selector(proceedWithApplicationLaunch:) withObject:nil afterDelay:0.5f];
}

最后,这个方法在初始启动和恢复时都被称为:

- (void) proceedWithApplicationLaunch:(NSNotification *)aNotification
{
    [self createOrSetPreferenceRecord];

    [_window center];

    // Kiosk Mode stuff... 
    NSApplicationPresentationOptions options = NSApplicationPresentationHideDock +
    NSApplicationPresentationDisableProcessSwitching +
    NSApplicationPresentationHideMenuBar;

    NSNumber *presentationOptions = [NSNumber numberWithUnsignedLong:options];

    NSArray *keys   = [NSArray arrayWithObjects:NSFullScreenModeAllScreens, NSFullScreenModeApplicationPresentationOptions,nil];
    NSArray *values = [NSArray arrayWithObjects:[NSNumber numberWithBool:YES], presentationOptions, nil];
    NSDictionary *fullScreenOptions = [[NSDictionary alloc] initWithObjects:values forKeys:keys];

    [glView_ enterFullScreenMode:[NSScreen mainScreen] withOptions:fullScreenOptions];

    if (firstLaunch) {
        [director runWithScene:[TypingLayer scene]];
        firstLaunch = NO;
    } else {
        [director resume]; // In case director is paused...

        // Clear caches to remove artifacts
        [director purgeCachedData];
        [CCSpriteFrameCache purgeSharedSpriteFrameCache];
        [[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
        [[CCTextureCache sharedTextureCache] removeUnusedTextures];

        [director replaceScene:[TypingLayer scene]];
    }
}

我怀疑OpenGL问题来自一些未正确解除分配的缓存资产。在TypingLayer中,我非常小心地在'-onExit'方法中单独删除和清除所有子sprite。但是,有些东西导致OpenGL错误,我无法弄清楚它是什么。据推测,它位于-resume:-proceedWithApplicationLaunch:方法中。

与此同时,我发现a thread on the Apple Support forums似乎表明这是NVidia驱动程序的问题。问题出现在2009年的13“Macbook Pro,2010年15”MBP(运行10.8)和2010年11“MBA(运行10.7)上。

如何正确地将用户带到设置然后返回到cocos2d OpenGL视图而不会遇到这些奇怪的OpenGL错误?

0 个答案:

没有答案
相关问题