https://kotlinlang.org logo
Title
v

vide

03/23/2023, 3:28 PM
It seems there is yet another focus regression in compose-ui:1.4 😰
E  java.lang.IllegalStateException: Check failed.
    [Full trace in thread]
   	at androidx.compose.ui.focus.FocusOwnerImpl.moveFocus-3ESFkO8(FocusOwnerImpl.kt:150)
   	at androidx.compose.ui.platform.AndroidComposeView$keyInputModifier$1.invoke-ZmokQxo(AndroidComposeView.android.kt:212)
Full trace:
E  java.lang.IllegalStateException: Check failed.
   	at androidx.compose.ui.focus.FocusTargetModifierNode.fetchFocusProperties$ui_release(FocusTargetModifierNode.kt:141)
   	at androidx.compose.ui.focus.TwoDimensionalFocusSearchKt.collectAccessibleChildren(TwoDimensionalFocusSearch.kt:216)
   	at androidx.compose.ui.focus.TwoDimensionalFocusSearchKt.findChildCorrespondingToFocusEnter--OM-vw8(TwoDimensionalFocusSearch.kt:121)
   	at androidx.compose.ui.focus.TwoDimensionalFocusSearchKt.twoDimensionalFocusSearch--OM-vw8(TwoDimensionalFocusSearch.kt:96)
   	at androidx.compose.ui.focus.FocusTraversalKt.focusSearch-sMXa3k8(FocusTraversal.kt:105)
   	at androidx.compose.ui.focus.FocusOwnerImpl.moveFocus-3ESFkO8(FocusOwnerImpl.kt:150)
   	at androidx.compose.ui.platform.AndroidComposeView$keyInputModifier$1.invoke-ZmokQxo(AndroidComposeView.android.kt:212)
I'll try to investigate this...
The specific check that fails is this:
@ExperimentalComposeUiApi
internal inline fun DelegatableNode.visitAncestors(mask: Int, block: (Modifier.Node) -> Unit) {
    // TODO(lmr): we might want to add some safety wheels to prevent this from being called
    //  while one of the chains is being diffed / updated. Although that might only be
    //  necessary for visiting subtree.
    check(node.isAttached)
I haven't found out a reliable way to reproduce it which makes me think it's probably a race condition somewhere as the node is not attached anymore when running focus search 🤷 This is a really big problem though for using 1.4.0
I have 2 stack traces of this and it seems like both involve
findChildCorrespondingToFocusEnter
, which might be a lead
j

jw

03/23/2023, 4:58 PM
File an issue on the issue tracker
v

vide

03/23/2023, 5:12 PM
I definitely will. I'm just hoping that gathering as much detail as possible would help the devs to narrow down the cause more effectively :blob-smile:
Also I don't think the description in the issue tracker is editable which might lead to some incoherent text if I notice something just after posting it 😅
Both traces seem to have
twoDimensionalFocusSearch
in the stack only once, which to my understanding would indicate the focus search is beginning from the root of the hierarchy. I am not yet familiar with the Modifier Node architecture, but this would seem to indicate that the root node is for some reason detached from the layout 🤔
j

jw

03/23/2023, 5:18 PM
There's no limit to follow-up comments though. Trust me, over communication is never a bad thing when chasing down bugs
v

vide

03/23/2023, 5:19 PM
Update: I managed to create a reliable demo of the focus crash and some edge conditions: https://issuetracker.google.com/issues/274897776#comment2. It seems to be related to several other bugs I have filed previously. Most importantly it seems to be directly connected to the addition/removal of nodes in focus modifier trees and the resetting of nodes in lazy layouts. I am wondering if anyone has ideas for workarounds? I'm balancing between having to downgrade back to 1.3.x and backporting other relevant fixes from 1.4.0 as I can't roll to production with this 😒ad-panda: