Skip to content

Commit

Permalink
Fixes cocos2d#108
Browse files Browse the repository at this point in the history
  • Loading branch information
fishcake committed Apr 28, 2012
1 parent 40d6130 commit ea37911
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Extensions/CCLayerPanZoom/CCLayerPanZoom.m
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ - (id) init
self.rubberEffectRecoveryTime = 0.2f;
_rubberEffectRecovering = NO;
_rubberEffectZooming = NO;

_isTouchBeganCalled = NO;
}
return self;
}
Expand All @@ -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
Expand All @@ -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)
{
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ea37911

Please sign in to comment.