Skip to content

OneSequenceGestureRecognizer.startTrackingPointer contains erroneous assert #117356

@goderbauer

Description

@goderbauer

The assert in the following method is incorrect:

void startTrackingPointer(int pointer, [Matrix4? transform]) {
GestureBinding.instance.pointerRouter.addRoute(pointer, handleEvent, transform);
_trackedPointers.add(pointer);
assert(!_entries.containsValue(pointer));
_entries[pointer] = _addPointerToArena(pointer);
}

It must of course be containsKey instead of containsValue. The bug was introduced over half a decade ago in #3552. Correcting the assert now fails hundreds of tests. Having the correct assert there is definitely the right thing as we don't want to accidentally overwrite existing entries in _entries. However, it seems like that a lot of our existing recognizers are not properly cleaning up their entries when they don't need them anymore. We need to fix that first before we can enable the assert.

From an initial analysis, it appears that we only clean up the entries when a OneSequenceGestureRecognizer decides to accept or reject a gesture by calling resolve or resolvePointer on itself. However, if the recognizer is told by the GestureArena that it must accept or reject the gesture by calling acceptGesture/rejectGesture on the recognizer, we fail to properly clean up the entries in _entries for some recognizers. Subsequent gestures involving the same pointers then trigger the corrected assert mentioned above.

The problem can easily be reproduced by correcting the assert and then running the test/gestures/tap_test.dart tests, some of which will then fail with that assertion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: crashStack traces logged to the consolef: gesturesflutter/packages/flutter/gestures repository.frameworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions