Coco2d 2.1 and Xcode 7 iOS 9 crash ccShader

前端 未结 4 1111
离开以前
离开以前 2020-12-25 15:23

I tested Xcode 7 with but my cocos2d 2.1 games crash on simulator or on devices:

ccShader_PositionColorLenghtTexture_frag.h

2015-06-15 22:36:13.319 N         


        
4条回答
  •  醉话见心
    2020-12-25 15:25

    The accepted answer did not work for me, but this did.

    Go to the file named CCGLProgram.m

    Replace the entire method named - (BOOL)compileShader:(CLuint *)shader type(GLenum)typebyteArray:(const GLchar *)source

    with this method

    #define _IPHONE9_0 [[[UIDevice currentDevice] systemVersion] floatValue] == 9.000
    
    #define EXTENSION_STRING "#extension GL_OES_standard_derivatives : enable"
    static NSString * g_extensionStr = @EXTENSION_STRING;
    
    
    - (BOOL)compileShader:(GLuint *)shader type:(GLenum)type byteArray:(const GLchar *)source
    {
    GLint status;
    if (!source)
        return NO;
    
    
    #ifdef _IPHONE9_0
    
    NSLog(@"USING IOS9 shaders");
    // BEGIN workaround for Xcode 7 ios9----
    BOOL hasExtension = NO;
    NSString *sourceStr = [NSString stringWithUTF8String:source];
    if([sourceStr containsString:g_extensionStr]) {
        hasExtension = YES;
        NSArray *strs = [sourceStr componentsSeparatedByString:g_extensionStr];
        assert(strs.count == 2);
        sourceStr = [strs componentsJoinedByString:@"\n"];
        source = (GLchar *)[sourceStr UTF8String];
    }
    
    const GLchar *sources[] = {
        (hasExtension ? EXTENSION_STRING "\n" : ""),
    #ifdef __CC_PLATFORM_IOS
        (type == GL_VERTEX_SHADER ? "precision highp float;\n" : "precision mediump float;\n"),
     #endif
        "uniform mat4 CC_PMatrix;\n"
        "uniform mat4 CC_MVMatrix;\n"
        "uniform mat4 CC_MVPMatrix;\n"
        "uniform vec4 CC_Time;\n"
        "uniform vec4 CC_SinTime;\n"
        "uniform vec4 CC_CosTime;\n"
        "uniform vec4 CC_Random01;\n"
        "//CC INCLUDES END\n\n",
        source,
    };
    #else
    
    NSLog(@"USING IOS8 shaders");
    
    const GLchar *sources[] = {
    #ifdef __CC_PLATFORM_IOS
        (type == GL_VERTEX_SHADER ? "precision highp float;\n" : "precision mediump float;\n"),
    #endif
        "uniform mat4 CC_PMatrix;\n"
        "uniform mat4 CC_MVMatrix;\n"
        "uniform mat4 CC_MVPMatrix;\n"
        "uniform vec4 CC_Time;\n"
        "uniform vec4 CC_SinTime;\n"
        "uniform vec4 CC_CosTime;\n"
        "uniform vec4 CC_Random01;\n"
        "//CC INCLUDES END\n\n",
        source,
    };
    
    #endif
    
    
    *shader = glCreateShader(type);
    glShaderSource(*shader, sizeof(sources)/sizeof(*sources), sources, NULL);
    glCompileShader(*shader);
    
    glGetShaderiv(*shader, GL_COMPILE_STATUS, &status);
    
    if( ! status ) {
        GLsizei length;
        glGetShaderiv(*shader, GL_SHADER_SOURCE_LENGTH, &length);
        GLchar src[length];
    
        glGetShaderSource(*shader, length, NULL, src);
        CCLOG(@"cocos2d: ERROR: Failed to compile shader:\n%s", src);
    
        if( type == GL_VERTEX_SHADER )
            CCLOG(@"cocos2d: %@", [self vertexShaderLog] );
        else
            CCLOG(@"cocos2d: %@", [self fragmentShaderLog] );
    
        abort();
    }
    return ( status == GL_TRUE );
    }
    

提交回复
热议问题