rive-flutter
rive-flutter copied to clipboard
Text rendering on (certain) Android devices will crash application due to `OutOfMemoryError`
Description
Text rendering on (certain) Android devices will crash application due to OutOfMemoryError
Steps To Reproduce
Steps to reproduce the behavior:
- Create a very simple rive animation that just contains a text element with a single run
- Show rive animation on device (e.g.
RiveAnimation.asset
) - App will crash due to
OutOfMemoryError
Source
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.
+1
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.
I deleted the Text element from my animation and it works on the emulator too. This pinpoints the culprit, I guess.
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
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.
We are seeing this in our logs as well. This should not be something that requires a workaround imo
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.
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?
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?
@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?):
I tried with both 0.11.7 and our latest internal dev version.
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.
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.
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
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
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;
}
}
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!
This is a great catch @zach-parker-aofl. We're going to get this fix in today!
Give version 0.13.1 a go!
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?
Closing this issue as it's been fixed with 0.13.1