From 40d6130b2c14183c0e704fa9631c61e304f53a86 Mon Sep 17 00:00:00 2001 From: fishcake Date: Sat, 28 Apr 2012 16:06:18 +0800 Subject: [PATCH 1/4] Update Extensions/CCLayerPanZoom/CCLayerPanZoom.h --- Extensions/CCLayerPanZoom/CCLayerPanZoom.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Extensions/CCLayerPanZoom/CCLayerPanZoom.h b/Extensions/CCLayerPanZoom/CCLayerPanZoom.h index e9287ca..1f5ef86 100644 --- a/Extensions/CCLayerPanZoom/CCLayerPanZoom.h +++ b/Extensions/CCLayerPanZoom/CCLayerPanZoom.h @@ -99,6 +99,8 @@ typedef enum CGFloat _rubberEffectRatio; BOOL _rubberEffectRecovering; BOOL _rubberEffectZooming; + + BOOL _isTouchBeganCalled; } #pragma mark Zoom Options From ea37911ad6097a189bd25a0f85ace54fefc45813 Mon Sep 17 00:00:00 2001 From: fishcake Date: Sat, 28 Apr 2012 16:12:48 +0800 Subject: [PATCH 2/4] Fixes #108 --- Extensions/CCLayerPanZoom/CCLayerPanZoom.m | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Extensions/CCLayerPanZoom/CCLayerPanZoom.m b/Extensions/CCLayerPanZoom/CCLayerPanZoom.m index d2c2fe2..1e55102 100644 --- a/Extensions/CCLayerPanZoom/CCLayerPanZoom.m +++ b/Extensions/CCLayerPanZoom/CCLayerPanZoom.m @@ -211,6 +211,8 @@ - (id) init self.rubberEffectRecoveryTime = 0.2f; _rubberEffectRecovering = NO; _rubberEffectZooming = NO; + + _isTouchBeganCalled = NO; } return self; } @@ -219,7 +221,9 @@ - (id) init - (void) ccTouchesBegan: (NSSet *) touches withEvent: (UIEvent *) event -{ +{ + _isTouchBeganCalled = YES; + for (UITouch *touch in [touches allObjects]) { // Add new touche to the array with current touches @@ -238,6 +242,13 @@ - (void) ccTouchesBegan: (NSSet *) touches - (void) ccTouchesMoved: (NSSet *) touches withEvent: (UIEvent *) event { + // Fixes issue #108: + // ccTouchesMoved should never be called if ccTouchesBegan is not called first. + // However, when the scene is transitioning in, ccTouchesBegan is not called, + // causing self.touches to be empty, thus crashing the app due to an attempt + // to access an empty array. + if (!_isTouchBeganCalled) return; + BOOL multitouch = [self.touches count] > 1; if (multitouch) { @@ -317,6 +328,8 @@ - (void) ccTouchesMoved: (NSSet *) touches - (void) ccTouchesEnded: (NSSet *) touches withEvent: (UIEvent *) event { + _isTouchBeganCalled = NO; + _singleTouchTimestamp = INFINITY; // Process click event in single touch. @@ -349,6 +362,8 @@ - (void) ccTouchesEnded: (NSSet *) touches - (void) ccTouchesCancelled: (NSSet *) touches withEvent: (UIEvent *) event { + _isTouchBeganCalled = NO; + for (UITouch *touch in [touches allObjects]) { // Remove touche from the array with current touches From 06713fdba1caaea46238e9ffc551f6060adc13bf Mon Sep 17 00:00:00 2001 From: fishcake Date: Sat, 28 Apr 2012 22:34:41 +0800 Subject: [PATCH 3/4] Update Extensions/CCLayerPanZoom/CCLayerPanZoom.h --- Extensions/CCLayerPanZoom/CCLayerPanZoom.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/Extensions/CCLayerPanZoom/CCLayerPanZoom.h b/Extensions/CCLayerPanZoom/CCLayerPanZoom.h index 1f5ef86..e9287ca 100644 --- a/Extensions/CCLayerPanZoom/CCLayerPanZoom.h +++ b/Extensions/CCLayerPanZoom/CCLayerPanZoom.h @@ -99,8 +99,6 @@ typedef enum CGFloat _rubberEffectRatio; BOOL _rubberEffectRecovering; BOOL _rubberEffectZooming; - - BOOL _isTouchBeganCalled; } #pragma mark Zoom Options From 256639cfa81612de587874e428269b41aaf85513 Mon Sep 17 00:00:00 2001 From: fishcake Date: Sat, 28 Apr 2012 22:36:04 +0800 Subject: [PATCH 4/4] Update Extensions/CCLayerPanZoom/CCLayerPanZoom.m --- Extensions/CCLayerPanZoom/CCLayerPanZoom.m | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Extensions/CCLayerPanZoom/CCLayerPanZoom.m b/Extensions/CCLayerPanZoom/CCLayerPanZoom.m index 1e55102..ee910b7 100644 --- a/Extensions/CCLayerPanZoom/CCLayerPanZoom.m +++ b/Extensions/CCLayerPanZoom/CCLayerPanZoom.m @@ -211,8 +211,6 @@ - (id) init self.rubberEffectRecoveryTime = 0.2f; _rubberEffectRecovering = NO; _rubberEffectZooming = NO; - - _isTouchBeganCalled = NO; } return self; } @@ -222,8 +220,6 @@ - (id) init - (void) ccTouchesBegan: (NSSet *) touches withEvent: (UIEvent *) event { - _isTouchBeganCalled = YES; - for (UITouch *touch in [touches allObjects]) { // Add new touche to the array with current touches @@ -247,7 +243,7 @@ - (void) ccTouchesMoved: (NSSet *) touches // However, when the scene is transitioning in, ccTouchesBegan is not called, // causing self.touches to be empty, thus crashing the app due to an attempt // to access an empty array. - if (!_isTouchBeganCalled) return; + if ([self.touches count] == 0) return; BOOL multitouch = [self.touches count] > 1; if (multitouch) @@ -328,8 +324,6 @@ - (void) ccTouchesMoved: (NSSet *) touches - (void) ccTouchesEnded: (NSSet *) touches withEvent: (UIEvent *) event { - _isTouchBeganCalled = NO; - _singleTouchTimestamp = INFINITY; // Process click event in single touch. @@ -362,8 +356,6 @@ - (void) ccTouchesEnded: (NSSet *) touches - (void) ccTouchesCancelled: (NSSet *) touches withEvent: (UIEvent *) event { - _isTouchBeganCalled = NO; - for (UITouch *touch in [touches allObjects]) { // Remove touche from the array with current touches