Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: iOS App hangs very frequently when using Compottie #15

Open
1 task done
Vaibhav2002 opened this issue Aug 5, 2024 · 28 comments
Open
1 task done

[Bug]: iOS App hangs very frequently when using Compottie #15

Vaibhav2002 opened this issue Aug 5, 2024 · 28 comments
Assignees

Comments

@Vaibhav2002
Copy link

What happened?

iOS App hangs very frequently when scrolling lists, swiping pager, selecting bottom nav items if there are lottie animations in the UI
Like in every 2-3min while just scrolling a vertical lazy list or switching pager, iOS App completely hangs and user has to close the app and re-open it

Reason why I feel its due to Compottie

I replaced every lottie animation in app with a blank Box composable and even after hours of scrolling, swiping pages, doing all kind of interactions, app did not hang at all

Tested this for 2 days, and there has not been a single hang
While as soon as i uncomment the Compottie code, the frequent app hangs starts again

This is degrading User Experience a lot.

This is only happening on iOS, Android works pretty good with no such hangs

Composable code

@Composable
fun Lottie(
    animationPath: String,
    modifier: Modifier = Modifier,
    isPlaying: Boolean = true,
    isInfinite: Boolean = true,
    contentScale: ContentScale = ContentScale.Fit,
    speed: Float = 1f,
    dynamicProperties: LottieDynamicProperties? = null,
    onComplete: (() -> Unit)? = null,
) {
    val composition by rememberLottieComposition {
        LottieCompositionSpec.JsonString(Res.readBytes(animationPath).decodeToString())
    }

    val progress by animateLottieCompositionAsState(composition)

    LaunchedEffect(progress) {
        if (progress == 1f) onComplete?.invoke()
    }

    val painter = rememberLottiePainter(
        composition = composition,
        isPlaying = isPlaying,
        iterations = if (isInfinite) Compottie.IterateForever else 1,
        speed = speed,
        dynamicProperties = dynamicProperties
    )

    Image(
        painter = painter,
        modifier = modifier,
        contentDescription = null,
        contentScale = contentScale
    )
}

Unsupported features

  • My animation doesn't use unsupported features

What Compottie version do you experience the bug on?

2.0.0-beta02

What platforms are you seeing the problem on?

iOS

Does Compottie log anythyng to the stdout / your logger set with Compottie.logger?

No
@alexzhirkevich
Copy link
Owner

Any animation example / xcode profiling info? What is causing the ANR? Memory? Cpu?
Do you have multiple animations from the same json file on screen at the same time?
Have you tested the release build?
Can you try the sample app? There is also a lazy grid of various animations and nothing hangs for me

@alexzhirkevich
Copy link
Owner

Android works pretty good with no such hangs

The code is 99% shared so it can be a Compose issue

@Vaibhav2002
Copy link
Author

Vaibhav2002 commented Aug 5, 2024

Yes, i have multiple animations from same json running in the same screen
Some lazy column items have the same animation

This is only happening in release build, I never encountered this when running app on debug builds or in simulator
I am using this on production, and its hanging in a lot of devices

Few animations which i am using:

@alexzhirkevich
Copy link
Owner

Try to disable composition cache with rememberLottieComposition(key = null)

@alexzhirkevich
Copy link
Owner

It's hard to tell anything concrete without a reproducer.
Are there specific devices it hangs on? Old low-memory iphones?
Is you app open source?

@Vaibhav2002
Copy link
Author

Making a reproducer is difficult, as it just happens even with a simple lazy column
It hangs even on latest iPhone 15, 14 devices

App is not open source.

The composable i shared above, is how i use it everywhere.

I'll try with disabling composition cache and update here

@Vaibhav2002
Copy link
Author

@alexzhirkevich It still crashes
Even after disabling composition cache

@Vaibhav2002
Copy link
Author

I managed to get some Crash logs, maybe that might help
Medial-2024-08-05-171516.txt
Medial-2024-08-05-171238.txt
Medial-2024-08-05-171430.txt

@LaatonWalaBhoot
Copy link

@alexzhirkevich Any update on this? Facing the same issue

@alexzhirkevich
Copy link
Owner

Do you have a reproducer?

@LaatonWalaBhoot
Copy link

Its completely random. I am using it as in the Read me

@alexzhirkevich
Copy link
Owner

Any relevant stacktrace? Profiling info? Memory dump?

@LaatonWalaBhoot
Copy link

It's the same crash logs as @Vaibhav2002

@alexzhirkevich
Copy link
Owner

This logs only says that the app was terminated due to exceeding the backround work quota.
What compose and kotlin version do you use?

@LaatonWalaBhoot
Copy link

Compose 1.6.11
Kotlin 2.0.0

@alexzhirkevich
Copy link
Owner

Any special usages? Maybe this happen when you use lotties with images or with dynamic properties?

@LaatonWalaBhoot
Copy link

Yes dynamic properties are used for light and dark switch
Yes we use lottie with images but it works fine in Android
Also the animation is in cells of lazy column

@alexzhirkevich
Copy link
Owner

Can you try it without dynamic properties and then without images? It will help to find the root cause

@alexzhirkevich
Copy link
Owner

May be improved in 2.0.0-rc01

@LaatonWalaBhoot
Copy link

@alexzhirkevich What was the cause?
Sorry we had to revert since on production iOS users were reporting a lot of crashes

@alexzhirkevich
Copy link
Owner

There just was some refactoring in terms of synchronisation and simultaneous composition running. I can't be sure it is fixed completely since there is no reproducer. You can try it in non-prod env

@sahilbajaj
Copy link

@Vaibhav2002 @LaatonWalaBhoot Is the issue fixed for you on iOS with latest versions?

@LaatonWalaBhoot
Copy link

@sahilbajaj Seems like the issues have subsided for now. But unfortunately this observation is purely anecdotal
Would need some more time to be more objective

@sahilbajaj
Copy link

Thanks @LaatonWalaBhoot

@vickyleu
Copy link

@alexzhirkevich
I just experienced a crash here as well. Repeatedly displaying and then closing the Lottie animation causes a crash.
The crash occurs in the class io/github/alexzhirkevich/compottie/internal/shapes/TransformShape.kt.
Could this issue be due to deep copying?
TransformShape.kt Line 86

Crash Details:

SIGSEGV

SEGV_ACCERR

0   libobjc.A.dylib                     _objc_release_x8 + 16
5   AVFCore                             0x00000001b3c04000 + 43256
6   优课UOOC                              __cxa_throw + 23215540
7   优课UOOC                              __cxa_throw + 23312100
8   优课UOOC                              __cxa_throw + 8076556
9   优课UOOC                              __cxa_throw + 8065980
10  优课UOOC                              __cxa_throw + 9556604
11  优课UOOC                              __cxa_throw + 9699200
12  优课UOOC                              __cxa_throw + 57555400
13  libdispatch.dylib                    __dispatch_call_block_and_release + 32
23  UIKitCore                            _block_destroy_helper.23 + 10212
24  优课UOOC                              0x00000001024a4000 + 33648
25  dyld                                 0x00000001c7855000 + 212276

Address Calculation:

python3 -c "print(hex(0x00000001024a4000 + 33648))"
# Result: 0x1024ac370

Symbolicated Output:

vickyleu@vickydeMac-mini dSYMs % atos -o "优课UOOC.app.dSYM/Contents/Resources/DWARF/优课UOOC" -arch arm64 0x1024ac370
# Result: kfun:io.github.alexzhirkevich.compottie.internal.shapes.annotationImpl$kotlinx_serialization_json_JsonClassDiscriminator$0.equals#internal.958 (in 优课UOOC) (TransformShape.kt:1)

@alexzhirkevich
Copy link
Owner

@vickyleu Thanks for detailed crash log.
Seems like the issue is somewhere in generated serializer descriptor. Does it happen for all animations or for some specific? And does it always happen in the TransformShape? Is only the iOS version affected?
Maybe you can share the animation? If you want you can mail it to me

@vickyleu
Copy link

We're currently using only one Lottie animation, and the crash is triggered very rarely. I clicked for an entire afternoon and it only happened once. Out of approximately 400 phased-release users, about 7 to 10, only ios, compottie rc-02

@vickyleu
Copy link

@alexzhirkevich I have sent the email attachment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants