From a9f61d5df9bd2a9fec365ba7110e5ec09148cf1a Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Mon, 5 Sep 2011 14:20:31 -0400 Subject: Jump: Fixed zero-width ledge bug While this had no affect on the player, the game would sometimes randomly generate zero-width ledges when spawning ledges, which caused a whole ton of problems with the graphic generation and CCTexture2D and was the reason that the console was spammed with so many error messages when nothing bad seemed to be happening. The game would output the errors, drop the zero-width ledge and continue on as if nothing had happened. Fixes #217 --- Classes/JumpGameMode.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Classes/JumpGameMode.m b/Classes/JumpGameMode.m index 13294c3..93e05ea 100644 --- a/Classes/JumpGameMode.m +++ b/Classes/JumpGameMode.m @@ -129,7 +129,8 @@ if (rightmost <= 480) { - CCTexture2D* texture = [[CCTexture2D alloc] initWithImage:[factory createLedgeWithWidth:(arc4random() % 10) height:2]]; + int ledgeWidth = arc4random() % 9 + 1; + CCTexture2D* texture = [[CCTexture2D alloc] initWithImage:[factory createLedgeWithWidth:ledgeWidth height:2]]; CCSprite* ledge = [CCSprite spriteWithTexture:texture]; ledge.position = ccp(rightmost + rightwidth + ledge.boundingBox.size.width/2+64, 32); [self addChild:ledge]; @@ -463,6 +464,9 @@ - (UIImage*)createLedgeWithWidth:(int)width height:(int)height { + NSAssert(width > 0, @"Ledge width must be greater than 0"); + NSAssert(height > 0, @"Ledge height must be greater than 0"); + UIGraphicsBeginImageContext(CGSizeMake(width*32, height*32)); for (int y=0; y