Enabling debug draw on CCPhysicsNode causes crash

164 Views Asked by At

Versions: Cocos2D V3.4, Xcode 7.2.1, SpriteBuilder 1.4.9.

You can download my project here. It was created with SpriteBuilder.

Enabling debug draw on CCPhysicsNode causes a crash:

CCPhysicsNode *_physicsWorld;


_physicsWorld = [CCPhysicsNode node];
_physicsWorld.gravity = ccp(0,0);
_physicsWorld.debugDraw = YES;//if debugDraw set to NO, crash will not occur, it happens only when its set to YES
_physicsWorld.collisionDelegate = self;
[_scene addChild:_physicsWorld];

Error:

Assertion failure in -[CCRenderStateGL initWithBlendMode:shader:shaderUniforms:copyUniforms:]

My code to add physics body to the CCSprite:

  _PlayerSprite.physicsBody = [CCPhysicsBody bodyWithRect:(CGRect){CGPointZero, _PlayerSprite.contentSize} cornerRadius:0]; // 1 

  _PlayerSprite.physicsBody.collisionGroup = @"playerGroup"; // 2

  [_PhysicsWorld addChild:lobjPlayerSprite
                        z:Z_ORDER_PLAYERS];

Then code crashes at CCRendererBasicTypes initWithBlendMode:

-(instancetype)initWithBlendMode:(CCBlendMode *)blendMode shader:(CCShader *)shader shaderUniforms:(NSDictionary *)shaderUniforms copyUniforms:(BOOL)copyUniforms

crashes here:-
NSAssert(shader, @"CCRenderState: Shader is nil");
1

There are 1 best solutions below

0
Dion Larson On

Your project was created with SpriteBuilder which has not been updated since April 2015. The version of Cocos2D that SpriteBuilder ships with was released before Xcode 7 and does not include a few necessary fixes for Xcode 7 and iOS 9. You can read more about this here.

To fix this, you need to manually update Cocos2D. Follow the steps on the previous link or use this as a reference (it's more visual).