airbnb / lottie-android

Render After Effects animations natively on Android and iOS, Web, and React Native
http://airbnb.io/lottie/
Apache License 2.0
35.02k stars 5.42k forks source link

Segfault when running lottie animations in an Android Emulator on Linux using software graphics rendering #2550

Open saucetom opened 2 months ago

saucetom commented 2 months ago

Lottie is supported and developed on nights and weekends. Issues from Lottie sponsors will be prioritized.

Checklist

  1. Fork this repository into your account. ✅
  2. Reproduce your issue in the issue-repro module. Issues without a repro in the issue-repro module may be auto-closed. ✅

Link to fork with a repro in the issue-repro module https://github.com/saucetom/lottie-android

Describe the bug Android emulators on Linux machines using software graphics rendering crash when rendering Lottie Animations. This happens when trying to render multiple animations at once or when rendering a large animation. We've confirmed this behavior on various machines running Linux.

If we set renderMode = RenderMode.SOFTWARE in the LottieAnimation calls the crash doesn't happen. The crash also doesn't happen if we set android:hardwareAccelerated="false" in the AndroidManifest.xml file. I wonder if the logic in the useSoftwareRendering method should detect that the emulator is not using hardware acceleration and default to RenderMode.SOFTWARE? https://github.com/saucetom/lottie-android/blob/master/lottie/src/main/java/com/airbnb/lottie/RenderMode.java#L16

Steps To Reproduce Steps to reproduce the behavior:

  1. Launch an emulator on a Linux machine using the -gpu swiftshader_indirect flag
  2. Run the issue-repro-compose module from the fork linked above

Please let me know if there's any more information I can provide that would help facilitate resolving this bug. Thanks!

gpeal commented 1 month ago

I don't regularly work on a linux machine. Would you be open to taking a look and putting up a PR?

Which API levels have you seen this on?

I just tried this on a mac with -gpu swiftshader_indirect and forced RenderMode to hardware and it seemed to render fine

image

saucetom commented 1 month ago

With the latest version of lottie-android I'm seeing this on all API levels >= 26, but yes it only happens on Linux machines.

It seems like it would make sense to default to Software Rendering if GPU hardware acceleration is not enabled, I'll take a look and see if that would be straightforward to implement.

saucetom commented 1 month ago

@gpeal I don't think I'm able to detect from the code whether the test is running on an emulator using software graphics emulation. However I was able to trace the crash to this specific call to drawLayer. If I comment out that line the emulator doesn't hit the segfault.

I'm not familiar enough with the code to make any guesses about why that is, is there anything about this block of code or that specific drawLayer call that sticks out to you?

I will keep digging but any help or direction you could offer would be very appreciated.

gpeal commented 1 month ago

@saucetom That's basically the root method that'll draw everything in your animation so it doesn't narrow it down much.

What I like to do in cases like this is to progressively remove parts of the original animation to narrow down which part of it is crashing.

Lottie is definitely frequently used on Linux with software rendering so there has to be something specific to your linux distro, emulator, or animation that is triggering this.

For what it's worth, Lottie's CI snapshots run on linux and snapshot >2k animations using both software and hardware rendering without any issue.