Commit 3c14e41b authored by Adam Barth's avatar Adam Barth

Sporadic crash from invalid touch event

When embedded by the view_manager, sometimes we receive pointerup or
pointercancel events without having received a cooresponding pointerdown event.
The underlying issue is that the view_manager doesn't capture on pointerdown
and instead performs a new hit test for every pointer event. We should fix that
in view_manager, but, in the meantime, this patch makes us not crash in this
scenario.

Fixes #339
parent 67f6cab2
...@@ -102,27 +102,23 @@ class SkyBinding { ...@@ -102,27 +102,23 @@ class SkyBinding {
return state; return state;
} }
PointerState _getOrCreateStateForPointer(event, position) {
PointerState state = _stateForPointer[event.pointer];
if (state == null)
state = _createStateForPointer(event, position);
return state;
}
void _handlePointerEvent(sky.PointerEvent event) { void _handlePointerEvent(sky.PointerEvent event) {
Point position = new Point(event.x, event.y); Point position = new Point(event.x, event.y);
PointerState state; PointerState state = _getOrCreateStateForPointer(event, position);
switch(event.type) {
case 'pointerdown': if (event.type == 'pointerup' || event.type == 'pointercancel') {
state = _createStateForPointer(event, position); if (_hammingWeight(event.buttons) <= 1)
break; _stateForPointer.remove(event.pointer);
case 'pointerup':
case 'pointercancel':
state = _stateForPointer[event.pointer];
if (_hammingWeight(event.buttons) <= 1)
_stateForPointer.remove(event.pointer);
break;
case 'pointermove':
state = _stateForPointer[event.pointer];
// In the case of mouse hover we won't already have a cached down.
if (state == null)
state = _createStateForPointer(event, position);
break;
} }
event.dx = position.x - state.lastPosition.x; event.dx = position.x - state.lastPosition.x;
event.dy = position.y - state.lastPosition.y; event.dy = position.y - state.lastPosition.y;
state.lastPosition = position; state.lastPosition = position;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment