Permalink
Browse files

defensive code

When the viewport is translated and the touch is outside of the visible
viewport then the multi-touch code triggers an index key error. this
commit fixes that.
  • Loading branch information...
1 parent 948f131 commit f11da03f8e2f8711f872e5490c419662d33ffe8d @totallyevil totallyevil committed Aug 7, 2012
Showing with 16 additions and 7 deletions.
  1. +16 −7 cocos2d-xna/platform/CCApplication.cs
@@ -206,16 +206,25 @@ private void ProcessTouch()
break;
case TouchLocationState.Moved:
- movedTouches.Add(m_pTouchMap[touch.Id].Value);
- m_pTouchMap[touch.Id].Value.SetTouchInfo(touch.Id,
- touch.Position.X - m_rcViewPort.Left / m_fScreenScaleFactor,
- touch.Position.Y - m_rcViewPort.Top / m_fScreenScaleFactor);
+
+ if (m_pTouchMap.ContainsKey(touch.Id))
+ {
+ movedTouches.Add(m_pTouchMap[touch.Id].Value);
+ m_pTouchMap[touch.Id].Value.SetTouchInfo(touch.Id,
+ touch.Position.X - m_rcViewPort.Left / m_fScreenScaleFactor,
+ touch.Position.Y - m_rcViewPort.Top / m_fScreenScaleFactor);
+ }
break;
+
case TouchLocationState.Released:
- endedTouches.Add(m_pTouchMap[touch.Id].Value);
- m_pTouches.Remove(m_pTouchMap[touch.Id]);
- m_pTouchMap.Remove(touch.Id);
+
+ if (m_pTouchMap.ContainsKey(touch.Id))
+ {
+ endedTouches.Add(m_pTouchMap[touch.Id].Value);
+ m_pTouches.Remove(m_pTouchMap[touch.Id]);
+ m_pTouchMap.Remove(touch.Id);
+ }
break;
default:

0 comments on commit f11da03

Please sign in to comment.