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

Kir*_*odi 1 cocos2d-iphone ios

我在模拟器上运行我的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;
}
Run Code Online (Sandbox Code Playgroud)

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

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

作为场景流到viewcontroller到场景.

应用程序没有崩溃,但它有如下错误

在此输入图像描述

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

在此输入图像描述

All*_*n S 5

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

[self.navigationController pushViewController:director_ animated:YES];
Run Code Online (Sandbox Code Playgroud)

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

  • 我知道它现在的场景.但是那个场景我去了viewcontroller,之后我想去viewcontroller到scene.so我想推特别的场景 (2认同)
  • 哦好,所以你切换到另一个基于UIKit的视图控制器,然后用cocos2d导向器切换回上一个?你可以尝试的一件事是在你离开它之前结束导演,然后在你回去之后重新启动它.导演有一个结束方法,但是为了重新启动它,你必须完成设置cocos2d的app委托中的所有代码.您可以将该代码移动到单独的方法中,以便您可以随时调用它. (2认同)