Skip to content

Commit 513babf

Browse files
author
natural-law
committed
fixed #27
fix some bugs of node and director
1 parent 512f5d2 commit 513babf

File tree

1 file changed

+58
-52
lines changed

1 file changed

+58
-52
lines changed

cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp

Lines changed: 58 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -261,43 +261,46 @@ void CCTouchDispatcher::touches(NSSet *pTouches, UIEvent *pEvent, unsigned int u
261261
{
262262
pHandler = static_cast<CCTargetedTouchHandler *>(*arrayIter);
263263

264-
bool bClaimed = false;
265-
if (uIndex == ccTouchBegan)
266-
{
267-
bClaimed = static_cast<CCTargetedTouchDelegate*>(pHandler->getDelegate())->ccTouchBegan(pTouch, pEvent);
268-
if (bClaimed)
269-
{
270-
pHandler->getClaimedTouches()->addObject(pTouch);
271-
}
272-
} else
273-
if (pHandler->getClaimedTouches()->containsObject(pTouch))
274-
{
275-
// moved ended cancelled
276-
bClaimed = true;
277-
278-
switch (sHelper.m_type)
279-
{
280-
case ccTouchMoved:
281-
static_cast<CCTargetedTouchDelegate*>(pHandler->getDelegate())->ccTouchMoved(pTouch, pEvent);
282-
break;
283-
case ccTouchEnded:
284-
static_cast<CCTargetedTouchDelegate*>(pHandler->getDelegate())->ccTouchEnded(pTouch, pEvent);
285-
break;
286-
case ccTouchCancelled:
287-
static_cast<CCTargetedTouchDelegate*>(pHandler->getDelegate())->ccTouchCancelled(pTouch, pEvent);
288-
break;
289-
}
290-
}
291-
292-
if (bClaimed && pHandler->isSwallowsTouches())
293-
{
294-
if (bNeedsMutableSet)
295-
{
296-
pMutableTouches->removeObject(pTouch);
297-
}
298-
299-
break;
300-
}
264+
if (pHandler)
265+
{
266+
bool bClaimed = false;
267+
if (uIndex == ccTouchBegan)
268+
{
269+
bClaimed = static_cast<CCTargetedTouchDelegate*>(pHandler->getDelegate())->ccTouchBegan(pTouch, pEvent);
270+
if (bClaimed)
271+
{
272+
pHandler->getClaimedTouches()->addObject(pTouch);
273+
}
274+
} else
275+
if (pHandler->getClaimedTouches()->containsObject(pTouch))
276+
{
277+
// moved ended cancelled
278+
bClaimed = true;
279+
280+
switch (sHelper.m_type)
281+
{
282+
case ccTouchMoved:
283+
static_cast<CCTargetedTouchDelegate*>(pHandler->getDelegate())->ccTouchMoved(pTouch, pEvent);
284+
break;
285+
case ccTouchEnded:
286+
static_cast<CCTargetedTouchDelegate*>(pHandler->getDelegate())->ccTouchEnded(pTouch, pEvent);
287+
break;
288+
case ccTouchCancelled:
289+
static_cast<CCTargetedTouchDelegate*>(pHandler->getDelegate())->ccTouchCancelled(pTouch, pEvent);
290+
break;
291+
}
292+
}
293+
294+
if (bClaimed && pHandler->isSwallowsTouches())
295+
{
296+
if (bNeedsMutableSet)
297+
{
298+
pMutableTouches->removeObject(pTouch);
299+
}
300+
301+
break;
302+
}
303+
}
301304
}
302305
}
303306
}
@@ -313,21 +316,24 @@ void CCTouchDispatcher::touches(NSSet *pTouches, UIEvent *pEvent, unsigned int u
313316
{
314317
pHandler = static_cast<CCStandardTouchHandler*>(*iter);
315318

316-
switch (sHelper.m_type)
317-
{
318-
case ccTouchBegan:
319-
(static_cast<CCStandardTouchDelegate*>(pHandler->getDelegate()))->ccTouchesBegan(pMutableTouches, pEvent);
320-
break;
321-
case ccTouchMoved:
322-
(static_cast<CCStandardTouchDelegate*>(pHandler->getDelegate()))->ccTouchesMoved(pMutableTouches, pEvent);
323-
break;
324-
case ccTouchEnded:
325-
(static_cast<CCStandardTouchDelegate*>(pHandler->getDelegate()))->ccTouchesEnded(pMutableTouches, pEvent);
326-
break;
327-
case ccTouchCancelled:
328-
(static_cast<CCStandardTouchDelegate*>(pHandler->getDelegate()))->ccTouchesCancelled(pMutableTouches, pEvent);
329-
break;
330-
}
319+
if (pHandler)
320+
{
321+
switch (sHelper.m_type)
322+
{
323+
case ccTouchBegan:
324+
(static_cast<CCStandardTouchDelegate*>(pHandler->getDelegate()))->ccTouchesBegan(pMutableTouches, pEvent);
325+
break;
326+
case ccTouchMoved:
327+
(static_cast<CCStandardTouchDelegate*>(pHandler->getDelegate()))->ccTouchesMoved(pMutableTouches, pEvent);
328+
break;
329+
case ccTouchEnded:
330+
(static_cast<CCStandardTouchDelegate*>(pHandler->getDelegate()))->ccTouchesEnded(pMutableTouches, pEvent);
331+
break;
332+
case ccTouchCancelled:
333+
(static_cast<CCStandardTouchDelegate*>(pHandler->getDelegate()))->ccTouchesCancelled(pMutableTouches, pEvent);
334+
break;
335+
}
336+
}
331337
}
332338
}
333339

0 commit comments

Comments
 (0)