Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CompileShader crash with XCode7 on iOS 9 #7

Open
wants to merge 1 commit into
base: v2.2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions cocos2d/CCGLProgram.m
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ - (NSString*) description
return [NSString stringWithFormat:@"<%@ = %p | Program = %i, VertexShader = %i, FragmentShader = %i>", [self class], self, _program, _vertShader, _fragShader];
}

#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
{
Expand All @@ -148,20 +150,33 @@ - (BOOL)compileShader:(GLuint *)shader type:(GLenum)type byteArray:(const GLchar
if (!source)
return NO;

const GLchar *sources[] = {
// BEGIN workaround for Xcode 7 bug
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"),
(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,
};
"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,
};
// END workaround for Xcode 7 bug

*shader = glCreateShader(type);
glShaderSource(*shader, sizeof(sources)/sizeof(*sources), sources, NULL);
Expand Down