I am getting a weird behavior in iOS with cmp vers...
# compose-ios
p
I am getting a weird behavior in iOS with cmp version 1.5.0-dev1114. App freezes all of the sudden. Apparently in memory demanding parts of the App like a slide-in/slide-out animation or alpha 1 to 0 animation. I Wish I could get some logs but the log doesn’t print anything new after the freeze. Maybe is my code but Android, Desktop and the Browser are working fine. I will try to debug and come back with more information.
Copy code
#Versions
kotlin.version=1.8.21
agp.version=7.4.2
compose.version=1.5.0-dev1114
Sometimes I see this message as the last printed in the logs: "Message from debugger: Terminated due to signal 9", I confirm this is myself killing the App manually. The logger goes muted. The freeze is only happening with a real device, cannot reproduce it with emulators, only reproducible on a real device, see bellow
Copy code
model: iPhone 13 mini
iOS version: 16.5.1
More in thread, seems that I have a culprit UPDATE: It ended up being the Xcode version, After updating it, issue is gone UPDATE-2: The problem still persist, my bad for the false Xcode update report. I did not realized that I had left the code causing the issue commented out. I continue to workaround it, capture some thread logs, see thread for the logs.
👀 1
👍 2
If I commented out the following code, the problem is gone:
Copy code
AnimatedContent(
   targetState = childComponent,
   transitionSpec = { getTransitionByAnimationType(animationType) }
) {
     it.Content(Modifier)
}

where:
@OptIn(ExperimentalAnimationApi::class)
private fun getTransitionByAnimationType(animationType: AnimationType): ContentTransform {
    return when (animationType) {
        AnimationType.Direct -> {
            slideInHorizontally(
                initialOffsetX = { fullWidth ->
                    fullWidth
                },
                animationSpec = tween(
                    durationMillis = 300,
                    delayMillis = 0
                )
            ) with
                    slideOutHorizontally(
                        targetOffsetX = { fullWidth ->
                            -fullWidth
                        },
                        animationSpec = tween(
                            durationMillis = 300,
                            delayMillis = 0
                        )
                    )
        }

        AnimationType.Reverse -> {
            slideInHorizontally(
                initialOffsetX = { fullWidth ->
                    -fullWidth
                },
                animationSpec = tween()
            ) with
                    slideOutHorizontally(
                        targetOffsetX = { fullWidth ->
                            fullWidth
                        },
                        animationSpec = tween()
                    )
        }

        AnimationType.Exit,
        AnimationType.Enter -> {
            fadeIn(
                animationSpec = tween()
            ) with fadeOut(
                animationSpec = tween()
            )
        }
    }
}
but then I noticed that
with
has been deprecated.
The problem was introduce in 1.5.0-dev1104, 1.5.0-dev1103 is good. Seems that something mess up with animated content and the different transitions above.
i
Will forcing the previous version of Skiko help?
Copy code
implementation("org.jetbrains.skiko:skiko") {
        version {
            strictly("0.7.68")
        }
    }
If I commented out the following code, the problem is gone:
Is it possible to create a compilable reproducer from this code? We will appreciate it, it will help to fix the issue faster.
p
Sure, I will update.
e
Copy code
val types = listOf(AnimationType.Direct, AnimationType.Enter, AnimationType.Exit, AnimationType.Reverse)

var index by remember { mutableStateOf(0) }

Column(Modifier.fillMaxSize(), verticalArrangement = Arrangement.Center) {
    var targetState by remember { mutableStateOf(5f) }
    Button(onClick = {
        index = (index + 1) % types.size
        targetState += 5f
    }) {
        Text("Click")
    }

    AnimatedContent(
        targetState = targetState,
        transitionSpec = { getTransitionByAnimationType(types[index]) }
    ) {
        Box(Modifier.size(it.dp, it.dp).background(Color.Black)) {

        }
    }
}
Hey, I couldn’t quite figure out the specific reproduction path in your code, so I kinda derived it from its content and came up with the code above inside
setContent
There is nothing weird happening.
p
This is the App in perspective. Not sure if is something with my device in specific. In the video, the last time I tap on the back arrow in the top bar, then it stops there. Feels like the main thread locks up. No touch event, no painting. The logger doesn’t say anything either. I really have to improve my debugging skill in iOS. I will try to link a separate small project later
e
That would be helpful! Can you launch the app from Xcode and press ctrl+command+Y when this freeze happens? That would pause the app and show call stacks for all threads (something awkward might be seen in main thread, I guess)
p
Sure, waiting for xCode to update ⏱️
e
Just in case, you can use https://xcodereleases.com to avoid troubles related to App Store updates
🙌 1
p
Let me confirm but after updating xCode I can’t reproduce it anymore 🤷
Yeah confirmed, did a full cleanup and fresh install and is working great.
Xcode Version 14.3.1 (14E300c)
works good. You guys should probably start including the
Xcode version/versions
used when tested the releases and other iOS stuff like `MacOS version`in the release notes too. Apple stuff aren't the greatest at keeping back compatibility and come really bundled up. Anything outside that combo will break
Hey @Elijah Semyonov, sorry for my back and forth. The problem still persist after the Xcode update. I did not realized I had the offending code commented out. Soon as I saw that I was like 🤦‍♂️ . I did ctrl+cmd+y and this is the capture. Attached is a text file with the threads stacks
This is the main thread only. The top of the stack says
#0	0x00000001cde83c00 in semaphore_wait_trap ()
Which sounds suspicious
@Igor Demin When trying that I get the following when building the project:
Copy code
Cannot find a version of 'org.jetbrains.skiko:skiko' that satisfies the version constraints:
Seems due to a transitive version conflict Then tried:
Copy code
configurations.all {
        resolutionStrategy.force("org.jetbrains.skiko:skiko:0.7.68")
    }
but doesn’t seems to take effect. Same error message.
In a simple example using AnimatedContent with the specific transitions I couldn't reproduce. I keep investigating what could be the problem.
e
It should be fixed on next beta, but if it’s still broken, please ping me in this thread. It’s unrelated to your particular code and is cause by internal data race related to scene invalidation and redrawing logic.
p
Ah cool to know. I actually was checking my code and I have a potential memory leak. Hopefully both issues(my leak and your finding) get fixed 🤞. Great, looking forward to that beta version, I'll let you know
e
Working on memory leaks currently
👍 1
p
Just pass by to say that issue is fixed in 1.5.0-dev1128. It feels rock solid now Thanks!
👍 1
👍🏾 1