Bug 29320 - Easily cause SIGABRT by generating java garbage using BitmapFactory.DecodeByteArray
Summary: Easily cause SIGABRT by generating java garbage using BitmapFactory.DecodeByt...
Status: RESOLVED INVALID
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 5.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2015-04-22 13:16 UTC by Robin Eidissen
Modified: 2017-09-12 18:46 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Archive containing a project which reproduces the error, and a log from one occurrence (92.97 KB, application/x-zip-compressed)
2015-04-22 13:16 UTC, Robin Eidissen
Details
Emulator settings (17.40 KB, image/png)
2015-04-23 02:52 UTC, Robin Eidissen
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description Robin Eidissen 2015-04-22 13:16:49 UTC
Created attachment 10868 [details]
Archive containing a project which reproduces the error, and a log from one occurrence

I created a standard Android project (Blank App template) in Visual Studio.
I then added some code to load some bitmaps in parallel in a loop.

What usually ends up happening is that BitmapFactory.DecodeByteArray throws an OutOfMemoryError.

If I catch this error and let the app continue, then after a short while it segfaults.

This is the message that accompanies the crash:
"JNI DETECTED ERROR IN APPLICATION: JNI SetByteArrayRegion called with pending exception 'java.lang.OutOfMemoryError' thrown in unknown throw location"
Comment 1 Robin Eidissen 2015-04-22 13:54:47 UTC
The crash in the log was from running in the emulator (x64 on windows). On a nexus 9 I get: "JNI DETECTED ERROR IN APPLICATION: JNI NewString called with pending exception 'java.lang.OutOfMemoryError' thrown in unknown throw location"
Comment 2 Jonathan Pryor 2015-04-22 18:16:45 UTC
What device are you seeing this on?

Can you please try with the Xamarin.Android 5.1 beta?

I'm not able to reproduce the crash on a Nexus 5.
Comment 3 Robin Eidissen 2015-04-23 02:51:46 UTC
Edited the title to reflect the fact that it died from a SIGABRT, rather than SIGSEGV.

This happens on the Nexus 9, as I said (with Android 5.0.1). And using the newest stable Xamarin.Android.
Also in the emulator using the settings in the now attached image.
Comment 4 Robin Eidissen 2015-04-23 02:52:16 UTC
Created attachment 10878 [details]
Emulator settings
Comment 5 Robin Eidissen 2015-04-23 05:02:20 UTC
I also got the error using Xamarin.Android 5.1 on the Nexus 9 (with Android 5.0.1). SIGABRT after "JNI DETECTED ERROR IN APPLICATION: JNI SetByteArrayRegion called with pending exception 'java.lang.OutOfMemoryError' thrown in unknown throw location"
Comment 6 Robin Eidissen 2015-04-24 05:30:23 UTC
If I dispose the Bitmap objects or force a Mono GC then the crash disappears. So the question is, should one expect a process abort as a consequence of OutOfMemoryErrors in the JVM (if memory cannot be reclaimed, due to Mono GREFs or other reasons)?
Comment 7 Jon Douglas [MSFT] 2017-09-12 18:46:29 UTC
Thank you for taking the time to submit this report. After reviewing the description of this bug, we believe it no longer affects the current version of Xamarin.Android. If you are still experiencing the issue after updating your packages, please reopen this report with an attached reproduction.

I had tested this on a Nexus 5 using Lollipop on Xamarin.Android 7.4, in which I did run into an OOM error:

09-12 15:38:41.111 E/mono    ( 7331): Unhandled Exception:
09-12 15:38:41.111 E/mono    ( 7331): Java.Lang.OutOfMemoryError: Failed to allocate a 24 byte allocation with 0 free bytes and 3GB until OOM
09-12 15:38:41.111 E/mono    ( 7331):   --- End of managed Java.Lang.OutOfMemoryError stack trace ---
09-12 15:38:41.111 E/mono    ( 7331): java.lang.OutOfMemoryError: Failed to allocate a 24 byte allocation with 0 free bytes and 3GB until OOM
09-12 15:38:41.111 E/mono    ( 7331): 
09-12 15:38:41.111 E/mono-rt ( 7331): [ERROR] FATAL UNHANDLED EXCEPTION: Java.Lang.OutOfMemoryError: Failed to allocate a 24 byte allocation with 0 free bytes and 3GB until OOM
09-12 15:38:41.111 E/mono-rt ( 7331):   --- End of managed Java.Lang.OutOfMemoryError stack trace ---
09-12 15:38:41.111 E/mono-rt ( 7331): java.lang.OutOfMemoryError: Failed to allocate a 24 byte allocation with 0 free bytes and 3GB until OOM

However I believe this is related to a memory leak in the sample rather than demonstrating the behavior of the SIGABRT. Feel free to reopen if this is still a problem with the latest Xamarin.Android.