-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
crash: JsonUtf8Reader.nextInt #2552
Comments
That animation is parsing fine for me and the stack trace you provided doesn't seem to line up with the code in Lottie 6.5.0 As a result, it isn't clear to me which property you have that has decimals that is currently parsed as an int. Can you provide more information? CleanShot.2024-09-28.at.23.02.57.mp4 |
@gpeal I made a mistake, here is the bad json. I gave you the correccted, chat gpt json, that your website spitted out. If you look at the top layer of the crash, this ( com.airbnb.lottie.parser.moshi.JsonUtf8Reader.nextInt(JsonUtf8Reader.java:815)) occurs here https://github.com/airbnb/lottie-android/blob/v6.5.0/lottie/src/main/java/com/airbnb/lottie/parser/LayerParser.java#L242 and that which seems like it doesn't like doubles? If you review the json i attached, its full of doubles in there. Does that makes sense |
Hi @gpeal have you been able to look into this? |
@MKelman Not yet! I support Lottie on nights and weekends but will do my best to find some time for this. Feel free to take a look yourself and put up a PR if you'd like though. |
Sounds good, appreciate it! Wasn't sure if the "needs more info" flag was the reason you didn't see this yet. If I get a chance, I'll try to look myself as well :) But let me be clear, I dont believe the issue may be on android, I believe it may be part of the web tool that spits out decimal place results. But I'll see what else I can find If i have the time |
@MKelman The second animation you attached also parses fine. I'm trying reverse engineer what your issue is and it still isn't clear:
Can you provide more info? |
I encountered a similar issue, and after investigating, I believe the reason is as follows: The root cause of the intermittent exceptions when parsing a double value like 796.05 in the nextInt() method likely stems from floating-point precision errors. In Java (and Android), floating-point numbers are not always stored with exact precision, especially for values with decimal places. As a result, 796.05 might be stored internally as something slightly different, such as 796.0499999... or 796.0500001..., which can lead to inconsistencies during parsing. Here’s how these precision issues can lead to intermittent behavior: Floating-Point Precision Variability Inconsistent Comparison Results These floating-point precision limitations seem to be the underlying cause of the intermittent exceptions. |
Hello @gpeal, I’ve analyzed the issue and would like to share my findings below. If the fractional part of It appears that this condition was added under the assumption that Lottie JSON files would not contain numbers with decimal points (this is my personal assumption). Differences of 1 pixel in values like width or height are almost imperceptible to the eye. Therefore, we chose to ignore such minor precision issues and commented out the condition. Below is the actual code we commented out: // JsonUtf8Reader.java
@Override public int nextInt() throws IOException {
int p = peeked;
if (p == PEEKED_NONE) {
p = doPeek();
}
int result;
// ... (omitted)
peeked = PEEKED_BUFFERED;
double asDouble;
try {
asDouble = Double.parseDouble(peekedString);
} catch (NumberFormatException e) {
throw new JsonDataException("Expected an int but was " + peekedString
+ " at path " + getPath());
}
result = (int) asDouble;
/*
if (result != asDouble) { // Make sure no precision was lost casting to 'int'.
throw new JsonDataException("Expected an int but was " + peekedString
+ " at path " + getPath());
}
*/
peekedString = null;
peeked = PEEKED_NONE;
pathIndices[stackSize - 1]++;
return result;
} Could you modify the library to ensure it does not throw an exception when Lottie JSON files include numbers with decimal points? |
@MiJey That makes sense, the issue is more around which properties are being exported as doubles. The original implementation here was written when After Effects was the only platform and it always exported whole numbers and width/height. Now that there are other exporters, it looks like some of them behave differently. I can update layer width/height to be a double (that looks like the property with the issue here. |
Describe the bug
I am receiving this crash (full crash log attached)
Fatal Exception: java.lang.IllegalStateException: Unable to parse composition
at com.airbnb.lottie.LottieAnimationView.lambda$static$0(LottieAnimationView.java:72)
at com.airbnb.lottie.LottieAnimationView$1.onResult(LottieAnimationView.java:84)
at com.airbnb.lottie.LottieAnimationView$1.onResult(LottieAnimationView.java:77)
What version of Lottie did you test this on?
6.5.0
What version of Android did you test this on?
occurring on all android versions
Steps To Reproduce
Steps to reproduce the behavior:
stacktrace
com.adfone.aditup_issue_9ca65e77d3c3d036d7f1f31e48bb3ef8_crash_session_66F2F4BD0327000166560C71E2CFFAE2_DNE_0_v2_stacktrace.txt
example lottie file downloaded
blue_progress_bar_corrected.json
The text was updated successfully, but these errors were encountered: