rive-flutter icon indicating copy to clipboard operation
rive-flutter copied to clipboard

Text rendering on (certain) Android devices will crash application due to `OutOfMemoryError`

Open mwernsen opened this issue 1 year ago • 19 comments

Description

Text rendering on (certain) Android devices will crash application due to OutOfMemoryError

Steps To Reproduce

Steps to reproduce the behavior:

  1. Create a very simple rive animation that just contains a text element with a single run
  2. Show rive animation on device (e.g. RiveAnimation.asset)
  3. App will crash due to OutOfMemoryError

Source

riv.zip

Expected behavior

Show the asset without crashing

Device & Versions (please complete the following information)

  • Device: Samsung Galaxy A13 & Android Emulator Pixel 2
  • OS: Android SDK API Level 30
  • Rive version: 0.11.7
  • Flutter Version:
Flutter 3.10.4 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 682aa387cf (4 months ago) • 2023-06-05 18:04:56 -0500
Engine • revision 2a3401c9bb
Tools • Dart 3.0.3 • DevTools 2.23.1

Additional context

It appears something is going wrong in the text FFI part of the rive code. Debugging the issues shows that an invalid SimpleParagraphArray has been constructed with a unrealistic size (e.g. -182882203098359238 or 83859123492394293). When constructing the TextShapeResultFFI at rive_common-0.2.6/lib/src/rive_text_ffi.dart:807 toList is called on this invalid SimpleParagraphArray resulting in the outOfMemory exception and crashing/hanging of the application. I have only seen this behavior on certain (older) android devices. The animation runs fine on e.g. OnePlus Nord 2.

Have not tested this behavior on IOS.

mwernsen avatar Sep 26 '23 07:09 mwernsen

+1

NashIlli avatar Oct 18 '23 21:10 NashIlli

I'm having the same issue with Android Studio's emulator (Pixel 5 API 30). The same build is OK on a physical Android device.

rive_crash.log

maurovanetti avatar Nov 09 '23 16:11 maurovanetti

I deleted the Text element from my animation and it works on the emulator too. This pinpoints the culprit, I guess.

maurovanetti avatar Nov 09 '23 17:11 maurovanetti

Any updates on this issue? Also happening on physical devices: Samsung Galaxy A13 and TCL Tab 10L. It seems to happen during loading of the font asset

bernardo-rocha avatar Feb 14 '24 21:02 bernardo-rocha

Any updates on this issue? Also happening on physical devices: Samsung Galaxy A13 and TCL Tab 10L. It seems to happen during loading of the font asset

By removing the text from the 'animation.riv' file and replacing it with an svg or png file I was able to solve the problem, that's what I did to avoid that error.

silexcorp avatar Feb 14 '24 21:02 silexcorp

We are seeing this in our logs as well. This should not be something that requires a workaround imo

kupresk14 avatar Feb 28 '24 17:02 kupresk14

Adding some extra info:

We've seen this on Android 9, 10, 11, 12 and 13 in a few thousand instances. Not all of the devices are crazy old.

Devices we've seen affected: SM-A136U SM-A115U1 moto g pure SM-J737T1 B131DL moto g play - 2023

And many others..

It is entirely Android specific it seems unless anyone has seen otherwise.

kupresk14 avatar Feb 28 '24 20:02 kupresk14

This sounds very scary, we are about to release a series of apps using Rive on a large array of diverse Android devices and it would really look bad if they crash on some models. Can we expect a fix or at least a compatibility survey?

maurovanetti avatar Feb 29 '24 00:02 maurovanetti

Is this reproducible on those devices (and emulator) or random?

I think your crash (from the provided logs) looks slightly different @maurovanetti. It seems like a null pointer dereference when generating render styles while the original crash is a paragraph array with corrupt size. Looks like two different issues, both related to FFI. Can you share the .riv for your file @maurovanetti?

luigi-rosso avatar Feb 29 '24 00:02 luigi-rosso

@mwernsen I tried the provided file on a Pixel 2 Emulator with API 30. I couldn't reproduce the crash, do I have to do anything to cause the crash (like change the text in the run?): CleanShot 2024-02-28 at 17 47 06@2x

I tried with both 0.11.7 and our latest internal dev version.

luigi-rosso avatar Feb 29 '24 01:02 luigi-rosso

Is this reproducible on those devices (and emulator) or random?

I think your crash (from the provided logs) looks slightly different @maurovanetti. It seems like a null pointer dereference when generating render styles while the original crash is a paragraph array with corrupt size. Looks like two different issues, both related to FFI. Can you share the .riv for your file @maurovanetti?

For us I’m just going off of our production error logs. Many of the devices show up more than once so I’m assuming it’s replicable.

I will definitely try to test some more. Hopefully emulators trigger it fairly regularly so it can be tracked down.

kupresk14 avatar Feb 29 '24 04:02 kupresk14

Sure @luigi-rosso, this is the Rive file that triggers the crash in my emulator under some conditions. We never detected a crash on physical devices, but the amount of models covered is not as large as it should become with the next releases. Thanks for your help.

tutorial_clicks.zip

maurovanetti avatar Feb 29 '24 09:02 maurovanetti

Here's a direct stackTrace of the error we are seeing on Physical devices. We have someone internally with a Moto G Play 2023 that is consistently having crashing issues.

We actually did try removing all text elements too

We are on rive 0.12.4 and Flutter 3.19.0

I've been trying to trigger this on emulators but have had absolutely no luck so far. Unsure if this is the same as OP was seeing or not

Screenshot 2024-03-04 at 9 58 45 AM

kupresk14 avatar Mar 04 '24 15:03 kupresk14

We fixed our problem by removing text elements. Also check the size of your Rive files / memory usage if you are someone having issues! One of our files was much larger than the others and was spiking our mem usage by about 1.2GB. The file itself was broken.

Bought one of those Moto G Play phones where the crash was occurring and managed to track it down

kupresk14 avatar Mar 05 '24 17:03 kupresk14

We recently ran into this issue as well, and through some debugging we found that it appears to be caused when attempting to run on certain devices that run the arm7 version of the app instead of the arm64.

In the rive_common package, in lib/src/rive_text_ffi.dart there are some ffi SimpleArray structs that include a size field. It's currently annotated with a Uint64, but in the C++ library that same SimpleArray struct is using a size_t. When compiling for arm7, that size_t is 32-bit instead of 64-bit, so when trying to grab a SimpleParagraphArray, where each entry also stores a SimpleGlyphRunArray, the mismatch in sizes makes it get the wrong value.

Changing the Uint64 annotations to a Size annotation in my local pub.cache seemed to fix local arm7 builds. I would love to publish a pull request for it, but I don't know where the rive_common package repo is.

Old:

class SimpleParagraphArray extends Struct {
  external Pointer<ParagraphNative> data;
  @Uint64()
  external int size;

  List<Paragraph> toList() {
    var list = <Paragraph>[];
    for (int i = 0; i < size; i++) {
      list.add(ParagraphFFI(data.elementAt(i).ref));
    }
    return list;
  }
}

New:

class SimpleParagraphArray extends Struct {
  external Pointer<ParagraphNative> data;
  @Size()
  external int size;

  List<Paragraph> toList() {
    var list = <Paragraph>[];
    for (int i = 0; i < size; i++) {
      list.add(ParagraphFFI(data.elementAt(i).ref));
    }
    return list;
  }
}

zach-parker-aofl avatar Mar 05 '24 19:03 zach-parker-aofl

We have the exact same issue that we were able to reproduce on two physical devices, Samsung Galaxy Tab A 10.1 (2016) and Samsung Galaxy A02s(2021). There are probably a lot more, these are just devices we had on hand.

In any case we tried @zach-parker-aofl fix and it totally worked. I also don't know where the repo is but if somebody can publish a pull request on this issue, that would be awesome!

kennydead avatar Mar 07 '24 10:03 kennydead

This is a great catch @zach-parker-aofl. We're going to get this fix in today!

luigi-rosso avatar Mar 15 '24 23:03 luigi-rosso

Give version 0.13.1 a go!

luigi-rosso avatar Mar 16 '24 00:03 luigi-rosso

Hi, I have the same problem. I am using flame_rive latest version ^1.10.1. flame_rive ^1.10.1 which depends on rive ^0.12.3 How do I update and fix the problem?

Skullos avatar May 20 '24 20:05 Skullos

Closing this issue as it's been fixed with 0.13.1

HayesGordon avatar Aug 12 '24 14:08 HayesGordon