Skip to content

Commit

Permalink
Reland "Fix crash from alt-tab'ing just after startup" (#103093)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkwingsmt authored May 6, 2022
1 parent 543cc60 commit 55881f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/flutter/lib/src/rendering/mouse_tracker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ class MouseTracker extends ChangeNotifier {
// so that [mouseIsConnected], which is decided by `_mouseStates`, is
// correct during the callbacks.
if (existingState == null) {
assert(event is! PointerRemovedEvent);
if (event is PointerRemovedEvent)
return;
_mouseStates[device] = _MouseState(initialEvent: event);
} else {
assert(event is! PointerAddedEvent);
Expand Down
10 changes: 10 additions & 0 deletions packages/flutter/test/rendering/mouse_tracker_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ void main() {
listenerLogs.clear();
});

// Regression test for https://github.com/flutter/flutter/issues/90838
test('should not crash if the first event is a Removed event', () {
final List<PointerEvent> events = <PointerEvent>[];
setUpWithOneAnnotation(logEvents: events);
ui.window.onPointerDataPacket!(ui.PointerDataPacket(data: <ui.PointerData>[
_pointerData(PointerChange.remove, Offset.zero),
]));
events.clear();
});

test('should correctly handle multiple devices', () {
final List<PointerEvent> events = <PointerEvent>[];
setUpWithOneAnnotation(logEvents: events);
Expand Down

0 comments on commit 55881f7

Please sign in to comment.