2d-inc / Flare-Flutter

Load and get full control of your Rive files in a Flutter project using this library.
https://rive.app/
MIT License
2.55k stars 469 forks source link

When the flare is in the list, the app crashes. #60

Closed asjqkkkk closed 5 years ago

asjqkkkk commented 5 years ago

When I put a lot of small size FlareActor animations into a list and scroll, the app is very easy to crash.whether it's on the virtual machine pixel 2 XL (debug) or on my other real device. (release), it is easier to crash on my real device.

Also, when the FlareActor widget is in the list, it is very easy for the image to be misaligned.

My English is not very good, all of the above are translated by google

log message

`Build fingerprint: 'google/sdk_google_phone_x86/generic_x86:7.0/NYC/4729343:userdebug/dev-keys' Revision: '0' ABI: 'x86' pid: 28078, tid: 28095, name: 1.gpu >>> com.example.flutterrdiary <<< signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x4400f464 eax 00000000 ebx 8c1d7d20 ecx 00000000 edx 84d03780 esi 6da68f60 edi 4400f430 xcs 00000073 xds 0000007b xes 0000007b xfs 0000003b xss 0000007b eip 8ba3e6b8 ebp 8b07e038 esp 8b07e010 flags 00010206 backtrace:

00 pc 007c26b8 /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)

#01 pc 007c23e3  /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)
#02 pc 007c2bc4  /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)
#03 pc 007be157  /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)
#04 pc 007ca96c  /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)
#05 pc 007cac9a  /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)
#06 pc 00725ff3  /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)
#07 pc 007269a7  /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)
#08 pc 0073c04c  /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)
#09 pc 007b379c  /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)
#10 pc 007b3749  /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)
#11 pc 006372d9  /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)
#12 pc 0090e2a5  /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)
#13 pc 00613a51  /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)
#14 pc 0061939a  /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)
#15 pc 00619796  /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)
#16 pc 00619a72  /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)
#17 pc 0061966e  /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)
#18 pc 00619952  /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)
#19 pc 005e41ff  /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)
#20 pc 005e415e  /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)
#21 pc 005e643e  /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)
#22 pc 00018350  /system/lib/libutils.so (_ZN7android20SimpleLooperCallback11handleEventEiiPv+48)
#23 pc 000192f7  /system/lib/libutils.so (_ZN7android6Looper9pollInnerEi+1207)
#24 pc 00018d74  /system/lib/libutils.so (_ZN7android6Looper8pollOnceEiPiS1_PPv+68)
#25 pc 0000f77c  /system/lib/libandroid.so (ALooper_pollOnce+108)
#26 pc 005e6541  /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)
#27 pc 005e2b06  /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)
#28 pc 005e4804  /data/app/com.example.flutterrdiary-1/lib/x86/libflutter.so (offset 0x59c000)
#29 pc 00074fb2  /system/lib/libc.so (_ZL15__pthread_startPv+210)
#30 pc 0002026e  /system/lib/libc.so (__start_thread+30)
#31 pc 0001e046  /system/lib/libc.so (__bionic_clone+70)

Lost connection to device. `

pubspec.yaml

dependencies: flutter: sdk: flutter

dio: ^2.0.22 json_serializable: ^2.0.2 json_annotation: ^2.0.0 build_runner: ^1.0.0 sqflite: ^1.1.1 path_provider: any shared_preferences: ^0.5.1+1 image_picker: ^0.5.0+3 provide: ^1.0.2 flutter_svg: ^0.12.0 flare_flutter: ^1.3.4 encrypt: ^2.0.0 cached_network_image: ^0.7.0 flutter_webview_plugin: ^0.3.0+2 flutter_bugly: ^0.1.9

flutter doctor

Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, v1.2.1, on Microsoft Windows [Version 10.0.17134.648], locale zh-CN) [√] Android toolchain - develop for Android devices (Android SDK version 28.0.3) [√] Android Studio (version 3.3) [√] IntelliJ IDEA Ultimate Edition (version 2018.2) [√] Connected device (1 available)

• No issues found! Process finished with exit code 0

asjqkkkk commented 5 years ago

After I changed flr to png, the problem has been solved.

The problem mentioned above should be related to the GPU. I guess it should be that a large number of FlareActors are consuming the performance of the GPU. Can any experts help explain this?

luigi-rosso commented 5 years ago

Thanks for filing. Could you provide an example/source? Are you using ListView.builder?

asjqkkkk commented 5 years ago

@luigi-rosso Thanks for your reply. I am using ListView.Builder,

Here is the code that was shortened by me.

ListView.builder

return ListView.builder(
        key: PageStorageKey("vertical"),
        controller: event.verticalController,
        itemCount: event.diarys.length,
        itemBuilder: (BuildContext context, int position) {
          return VerticalDiary(position, event.diarys[position], event);
        },
        scrollDirection: Axis.vertical,
      );

Item (I omitted a lot of code)

class VerticalDiary extends StatelessWidget {

  final int index;
  final Diary diary;
  final RefreshListEvent refreshListEvent;

  VerticalDiary(this.index, this.diary, this.refreshListEvent);

  @override
  Widget build(BuildContext context) {
    return Row(
      children: <Widget>[
        Expanded(
          flex: 1,
          child: Container(
            margin: EdgeInsets.only(left: 20),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                Container(
                  width: 5,
                  height: 80,
                  color: Theme.of(context).primaryColor,
                ),
                Container(
                    width: 50,
                    height: 50,
                  child: Hero(tag: HeroTags.diaryType + "${diary.id}",
                      child: FlareActor("images_diary_type/" + diary.diaryImage + ".flr",
                        fit: BoxFit.contain,
                        animation: DiaryUtil.getWeatherName(diary.weather),
                        isPaused: true,
                      ),
                  ),
                ),
                Container(
                  width: 5,
                  height: 80,
                  color: Theme.of(context).primaryColor,
                )
              ],
            ),
          ),
        ),
        Expanded(
          flex: 5,
          child: GestureDetector(
            child: Container(
              constraints: BoxConstraints(minHeight: 150),
              padding: EdgeInsets.all(10),
              margin: EdgeInsets.all(20),
              decoration: BoxDecoration(
                  gradient: RadialGradient(
                      colors: [Theme.of(context).primaryColor, Colors.white],
                      center: Alignment.topRight,
                      radius: .98
                  ),
                  boxShadow: [ 
                    BoxShadow(
                        color: Colors.black54,
                        offset: Offset(2.0, 2.0),
                        blurRadius: 4.0
                    )
                  ],
              color: Theme.of(context).primaryColorLight,
                shape: BoxShape.rectangle,
                  borderRadius: BorderRadius.circular(20)
              ),
              child: Row(
                children: <Widget>[
                  Container(
                    width: 50,
                    height: 50,
                    margin: EdgeInsets.all(10),
                    child: Hero(
                      tag: HeroTags.weather + "${diary.id}",
                      child: FlareActor("images_weather/" + DiaryUtil.getWeatherName(diary.weather) + ".flr",
                        fit: BoxFit.contain,
                        animation: DiaryUtil.getWeatherName(diary.weather),
                        isPaused: true,
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
      ],
    );
  }
}

Preview image (I don't know if you can see it)

Vertical

image

Horizontal

image

The horizontal layout has a lower crash rate than the vertical layout.

I guess because the horizontal layout loads the FlareActor less than the vertical layout.

luigi-rosso commented 5 years ago

That's strange, I'll setup a test here with something similar and give it a try. Approximately how many different Flare files are you using?

Do you see the crash on both the emulator and a device?

asjqkkkk commented 5 years ago

There are a total of twelve flr files on the left and six on the right.

It's easier to crash on a real device (release apk), especially if my phone with weak performance has a lower frequency on the emulator.

Below is the crash record collected by the crash collection tool I used. It has probably crashed more than thirty times.


1 #00 pc 00017934 /system/lib/libc.so (memcpy+80) [armeabi-v7a]
--
2 #01 pc 00274519 /data/app/com.example.flutterrdiary-1/lib/arm/libflutter.so [armeabi-v7a]
3 #02 pc 00270081 /data/app/com.example.flutterrdiary-1/lib/arm/libflutter.so [armeabi-v7a]
4 #03 pc 0027866d /data/app/com.example.flutterrdiary-1/lib/arm/libflutter.so [armeabi-v7a]
5 #04 pc 0020af9d /data/app/com.example.flutterrdiary-1/lib/arm/libflutter.so [armeabi-v7a]
6 #05 pc 0020b633 /data/app/com.example.flutterrdiary-1/lib/arm/libflutter.so [armeabi-v7a]
7 #06 pc 002197a7 /data/app/com.example.flutterrdiary-1/lib/arm/libflutter.so [armeabi-v7a]
8 #07 pc 0033cc8d /data/app/com.example.flutterrdiary-1/lib/arm/libflutter.so [armeabi-v7a]
9 #08 pc 0015c6df /data/app/com.example.flutterrdiary-1/lib/arm/libflutter.so [armeabi-v7a]
10 #09 pc 001570c9 /data/app/com.example.flutterrdiary-1/lib/arm/libflutter.so [armeabi-v7a]
11 #10 pc 0015737d /data/app/com.example.flutterrdiary-1/lib/arm/libflutter.so [armeabi-v7a]
12 #11 pc 00157509 /data/app/com.example.flutterrdiary-1/lib/arm/libflutter.so [armeabi-v7a]
13 #12 pc 0015729d /data/app/com.example.flutterrdiary-1/lib/arm/libflutter.so [armeabi-v7a]
14 #13 pc 0015744d /data/app/com.example.flutterrdiary-1/lib/arm/libflutter.so [armeabi-v7a]
15 #14 pc 001356d5 /data/app/com.example.flutterrdiary-1/lib/arm/libflutter.so [armeabi-v7a]
16 #15 pc 00136a5d /data/app/com.example.flutterrdiary-1/lib/arm/libflutter.so [armeabi-v7a]
17 #16 pc 0001243d /system/lib/libutils.so (android::Looper::pollInner(int)+656) [armeabi-v7a]
18 #17 pc 0001211f /system/lib/libutils.so (android::Looper::pollOnce(int, int*, int*, void**)+26) [armeabi-v7a]
19 #18 pc 0000a987 /system/lib/libandroid.so (ALooper_pollOnce+50) [armeabi-v7a]
20 #19 pc 00136af7 /data/app/com.example.flutterrdiary-1/lib/arm/libflutter.so [armeabi-v7a]
21 #20 pc 00134877 /data/app/com.example.flutterrdiary-1/lib/arm/libflutter.so [armeabi-v7a]
22 #21 pc 00135a89 /data/app/com.example.flutterrdiary-1/lib/arm/libflutter.so [armeabi-v7a]
23 #22 pc 00047823 /system/lib/libc.so (__pthread_start(void*)+22) [armeabi-v7a]
24 #23 pc 00019ec1 /system/lib/libc.so (__start_thread+6) [armeabi-v7a]
25 java:
26 [Failed to get Java stack]
luigi-rosso commented 5 years ago

Looks like it might be memory related. We will make an example and share it with you. I'll keep you updated here as we investigate.

asjqkkkk commented 5 years ago

Thank you very much, I will wait for your results.