Skip to content

Conversation

@jeremyschlatter
Copy link
Contributor

@jeremyschlatter jeremyschlatter commented Apr 24, 2022

There is a common failure on desktop platforms that I and other developers have experienced. If you do the following sequence of actions, your app will start logging endless "assertion failed" messages and stop responding to mouse events:

- start the app with 'flutter run'
- position your mouse above where the app window will load
- when the app loads, alt-tab away from it, then alt-tab back

This is a sequence I have done unintentionally many times, and -- judging by these issue reports -- so have others:

It looks like the problem is that when you do that series of actions, the first mouse event that the app sees is a Removed event. The author(s) of mouse_tracker.dart assumed that such a thing could not happen, and even (helpfully) put in an assertion to that effect.

I don't have a deep understanding of the mouse tracker, but it appears that a reasonable response to receiving an initial Removed event is to simply ignore the event and wait for the next one. Doing this fixes the
crash, and the mouse continues to work afterward.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

There is a common failure on desktop platforms that I and other
developers have experienced. If you do the following sequence of
actions, your app will start logging endless "assertion failed" messages
and stop responding to mouse events:

    - start the app with 'flutter run'
    - position your mouse above where the app window will load
    - when the app loads, alt-tab away from it, then alt-tab back

This is a sequence I have done unintentionally many times, and --
judging by these isse reports -- so have others:

  - Fixes #76325
  - Fixes #80867
  - Fixes #90838
  - Fixes #98262
  - Fixes #99761
  - Fixes #100659
  - #70375 (comment)
  - Possibly #70375 ?
  - Possibly #93233 ?
  - Possibly #96364 ?

It looks like the problem is that when you do that series of actions,
the first mouse event that the app sees is a Removed event. The
author(s) of mouse_tracker.dart assumed that such a thing could not
happen, and even (helpfully) put in an assertion to that effect.

I don't have a deep understanding of the mouse tracker, but it appears
that a reasonable response to receiving an initial Removed event is to
simply ignore the event and wait for the next one. Doing this fixes the
crash, and the mouse continues to work afterward.
@flutter-dashboard flutter-dashboard bot added the framework flutter/packages/flutter repository. See also f: labels. label Apr 24, 2022
@goderbauer goderbauer requested a review from dkwingsmt April 27, 2022 21:45
Copy link
Contributor

@dkwingsmt dkwingsmt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the investigation!

@jeremyschlatter jeremyschlatter requested a review from dkwingsmt May 2, 2022 04:33
@dkwingsmt dkwingsmt requested a review from gspencergoog May 2, 2022 04:46
@dkwingsmt
Copy link
Contributor

I'm requesting a second review.

Copy link
Contributor

@gspencergoog gspencergoog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

32384589-a60f0e74-c078-11e7-9bc1-e5b5287aea9d

@darrenaustin
Copy link
Contributor

This appears to have broken the build:

https://ci.chromium.org/ui/p/flutter/builders/prod/Linux%20analyze/7051/overview

▌18:29:36▐ RUNNING: cd .; bin/flutter analyze --flutter-repo
Analyzing 3 items...                                            

   info • Avoid method calls or property accesses on a "dynamic" target • packages/flutter/test/rendering/mouse_tracker_test.dart:139:5 • avoid_dynamic_calls
  error • The function '_setUpWithOneAnnotation' isn't defined • packages/flutter/test/rendering/mouse_tracker_test.dart:139:5 • undefined_function

Not sure how this wasn't caught by the pre-commit checks. Unless there is a quick fix for this, I will revert this shortly to get the tree green again.

darrenaustin added a commit that referenced this pull request May 4, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 4, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request May 4, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 4, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 4, 2022
@jason-simmons
Copy link
Member

I looked into at why this assertion was happening in Linux desktop apps (see #100659)

There is a race between Linux embedder startup and framework startup which can cause the first pointer add event to be sent by the FlView before the framework has set up the pointer event handler. The framework then sees the remove event and triggers an assert about a remove with no matching add.

One option would be fixing this by buffering the pointer events in the engine. But it's probably simpler to relax the requirements for the embedder's event stream and just ignore the mismatched event as is done in this PR.

@dkwingsmt
Copy link
Contributor

dkwingsmt commented May 4, 2022

I was suspecting the same. Keyboard events used to face the same problem and we switched to the messenger, which supports message buffering flutter/engine#29795.

However this is not enough. The message buffering only supports one message, and at least for keyboard it's not hard to build a scenario that overflows (see #89748). We can resize the buffer, but to how much? Any size is an arbitrary size.

So I think the ultimate goal is for the framework to initiate a "startup request" and the engine replies with an initial state.

Despite this, I still approved this PR since we'd like a more immediate fix.

dkwingsmt added a commit that referenced this pull request May 4, 2022
@dkwingsmt
Copy link
Contributor

I have described this issue at #103094.

egramond pushed a commit to egramond/flutter that referenced this pull request May 5, 2022
egramond pushed a commit to egramond/flutter that referenced this pull request May 5, 2022
@jeremyschlatter jeremyschlatter deleted the mouse_tracker_crash branch July 12, 2024 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment