OpenGL错误0x0506在 - [CCSprite draw] 530中运行cocos2d中的divice项目?

时间:2014-01-06 12:14:55

标签: ios cocos2d-iphone

我在模拟器上运行我的cocos2d程序。它工作正常,但当我在设备上运行时,它会抛出错误OpenGL错误0x0506 - [CCSprite draw] 530和[CCGLView swapBuffers] 283.在我的程序中我想将一个场景推送到另一个场景。那时它显示错误和下一个场景的黑屏。请帮我解决一下。我也试着谷歌。

注意:我的应用程序没有崩溃,但绘制精灵的问题。

我的代码如下:

首先加载LoadingLayer,如下所示。

-(void) directorDidReshapeProjection:(CCDirector*)director
{

        if ([[director runningScene] isRunning])
        {

            [[CCDirector sharedDirector] replaceScene:[HelloWorldLayer scene]];
        }
        else
        {
            [[CCDirector sharedDirector] runWithScene:[LoadingLayer scene]];
        }

}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    // Create the main window
    window_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];


    [self.window setBackgroundColor:[UIColor whiteColor]];


    glView = [CCGLView viewWithFrame:[window_ bounds]
                                   pixelFormat:kEAGLColorFormatRGB565
                                   depthFormat:0
                            preserveBackbuffer:NO
                                    sharegroup:nil
                                 multiSampling:NO
                               numberOfSamples:0];

    director_ = (CCDirectorIOS*) [CCDirector sharedDirector];

    director_.wantsFullScreenLayout = YES;

    // Display FSP and SPF
    [director_ setDisplayStats:NO];

    // set FPS at 60
    [director_ setAnimationInterval:1.0/60];

    // attach the openglView to the director
    [director_ setView:glView];

    // 2D projection
    [director_ setProjection:kCCDirectorProjection2D];

    //  [director setProjection:kCCDirectorProjection3D];

    // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
    if( ! [director_ enableRetinaDisplay:YES] )
        CCLOG(@"Retina Display Not supported");

    // Default texture format for PNG/BMP/TIFF/JPEG/GIF images
    // It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
    // You can change this setting at any time.
    [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];

        CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
    [sharedFileUtils setEnableFallbackSuffixes:NO];             // Default: NO. No fallback suffixes are going to be used
    [sharedFileUtils setiPhoneRetinaDisplaySuffix:@"-hd"];      // Default on iPhone RetinaDisplay is "-hd"
    [sharedFileUtils setiPadSuffix:@"-ipad"];                   // Default on iPad is "ipad"
    [sharedFileUtils setiPadRetinaDisplaySuffix:@"-ipadhd"];    // Default on iPad RetinaDisplay is "-ipadhd"

    // Assume that PVR images have premultiplied alpha
    [CCTexture2D PVRImagesHavePremultipliedAlpha:YES];

    // Create a Navigation Controller with the Director
    navController_ = [[MyNavigationController alloc]    initWithRootViewController:director_];
    navController_.navigationBarHidden = YES;


    // for rotation and other messages
    [director_ setDelegate:navController_];

    // set the Navigation Controller as the root view controller
    [window_ setRootViewController:navController_];

    // make main window visible
    [window_ makeKeyAndVisible];

    return YES;
}

在LoadingLayer之后,它推送到viewcontroller.it点击按钮转到HelloWorldLayer。

-(void)Button
{
        director_ = (CCDirectorIOS*) [CCDirector sharedDirector];
        [director_ replaceScene:[HelloWorldLayer scene]];
        [self.navigationController pushViewController:director_ animated:YES];
}

作为场景流到viewcontroller到场景。

应用不会崩溃,但会出现错误,如下所示

enter image description here

在模拟器上运行良好,但CPU使用率达到95%到100%。

enter image description here

2 个答案:

答案 0 :(得分:5)

这只是一个cocos2d应用程序,而不是UIKit混合应用程序吗?在这种情况下,当你只是简单地切换场景(CCScene)时,为什么要调用pushViewController?尝试删除:

[self.navigationController pushViewController:director_ animated:YES];

你没有理由推动导演,它已经存在了。当您切换CCScene时,您没有创建新的视图控制器。

答案 1 :(得分:0)

  

但是那个场景我去了viewcontroller

如果您想同时使用UIKit和Cocos2d for iPhone,我强烈建议您阅读attachDemo以实现目标。

https://github.com/cocos2d/cocos2d-iphone/tree/master-v2/tests/attachDemo