Coco2d 2.1 and Xcode 7 iOS 9 crash ccShader

前端 未结 4 1102
离开以前
离开以前 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条回答
  •  萌比男神i
    2020-12-25 15:49

    Using the accepted answer above, but for newer versions of cocos2d:

    In CCShader.m replace the lines

    static GLint
    CompileShaderSources(GLenum type, NSArray *sources)
    {
    

    with

    #define EXTENSION_STRING "#extension GL_OES_standard_derivatives : enable"
    static NSString * g_extensionStr = @EXTENSION_STRING;
    
    static NSArray * PrependExtensionIfNeeded(NSArray *sources)
    {
        NSMutableArray *mutableSources = [NSMutableArray array];
    
        BOOL hasExtension = NO;
    
        for (NSString *source in sources)
        {
            NSString *newSource = [source copy];
            if([source rangeOfString:g_extensionStr].location != NSNotFound)
            {
                hasExtension = YES;
                NSArray *strs = [source componentsSeparatedByString:g_extensionStr];
                newSource = [strs componentsJoinedByString:@"\n"];
            }
    
            [mutableSources addObject:newSource];
        }
    
        if (hasExtension)
        {
            NSMutableString *firstSource = [NSMutableString stringWithString:[mutableSources firstObject]];
            [firstSource insertString:[NSString stringWithFormat:@"%@\n", g_extensionStr] atIndex:0];
            [mutableSources replaceObjectAtIndex:0 withObject:firstSource];
        }
    
        return mutableSources;
    }
    
    static GLint
    CompileShaderSources(GLenum type, NSArray *sources)
    {
        sources = PrependExtensionIfNeeded(sources);
    

提交回复
热议问题