forked from androidx/androidx
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix TapGestureDetector mutex is not locked error on Touchscreen (#824)
Fixes JetBrains/compose-multiplatform#3655 The issue is introduced after migration to `awaitPointerEventScope`, this code is indeed has a race condition, as it was assumed in the TODO. When we send Press/Release without any moves - we go via this path: ``` // awaitPointerEventScope isn't called until it receives the first event awaitPointerEventScope { // in the beginning of the method we have 2 events already in the queue launch { pressScope.reset() } // launch async, reset isn't called val down = awaitPress // don't suspend here, because we already have Press awaitReleaseOrCancelled() // don't suspend here, because we already have Release pressScope.release() // crash, because `pressScope.reset()` isn't called yet } ``` To avoid races, we should always access `pressScope` in `launch` (this way the calls maintain order). The same approach is used in the original `TapGestureDetector.kt` (the change in commit 32de9dd) Also, the rest of the code doesn't have races with `pressScope` calls. ## Testing - haven't reproduced with mouse - reproduced with a simple test (added to OnClickTest)
- Loading branch information
1 parent
cdc5b8e
commit 13a0944
Showing
2 changed files
with
41 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters