2016-05-06

Crashed cocos2d 2.1 on Xcode 7.3

cocos2d 2.1with Xcode 7.3 means getting crash!

Environment

cocos2d for iPhone 2.1
Xcode 7.3

What's happened.

Build app with cocos2d 2.1 and then run that. Xcode will show you this below.
cocos2d: ERROR: Failed to compile shader
cocos2d: ERROR: 0:12: '' : syntax error: #extension must always be before any non-preprocessor tokens

What should I do?

Edit CCGLProgram.m to add some codes (BOOL)compileShader method.
  1. - (BOOL)compileShader:(GLuint *)shader type:(GLenum)type byteArray:(const GLchar *)source
  2. {
  3. GLint status;
  4.  
  5. if (!source)
  6. return NO;
  7. // ADD Start
  8. BOOL hasExtension = NO;
  9. NSString *sourceStr = [NSString stringWithUTF8String:source];
  10. if([sourceStr rangeOfString:g_extensionStr].location != NSNotFound) {
  11. hasExtension = YES;
  12. NSArray *strs = [sourceStr componentsSeparatedByString:g_extensionStr];
  13. assert(strs.count == 2);
  14. sourceStr = [strs componentsJoinedByString:@"\n"];
  15. source = (GLchar *)[sourceStr UTF8String];
  16. }
  17. // ADD End
  18. const GLchar *sources[] = {
  19. // ADD Start
  20. (hasExtension ? EXTENSION_STRING "\n" : ""),
  21. // ADD End
  22. #ifdef __CC_PLATFORM_IOS

Ref link

https://stackoverflow.com/questions/30864055