Bug 13858 - Got a SIGSEGV while executing native code
Summary: Got a SIGSEGV while executing native code
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 4.8.x
Hardware: PC Windows
: High normal
Target Milestone: ---
Assignee: Rodrigo Kumpera
URL:
: 14188 ()
Depends on: 14011 14013 14017 14019 14042 14043 14045 14050
Blocks:
  Show dependency tree
 
Reported: 2013-08-08 11:59 UTC by Allie Miller
Modified: 2015-09-08 05:48 UTC (History)
7 users (show)

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

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 FIXED

Description Allie Miller 2013-08-08 11:59:47 UTC
In a project with 2 activities, one activity calls the other one. In the second activity, a list is created with bitmaps. (normaly this is used in a ListView, with paging and dynamic calls to get these bitmaps)
When leaving the second activity, there is a  cleanup of the bitmaps. Then the Recycle() function is used and before  recycling, a test is run if its not already recycled.

When you come back in the first activity onRestart(), attempt GC.Collect() or a GC.Collect(GC.MaxGeneration) to help the garbage collector to cleanup the used bitmaps. Then it crashes. When removing the GC.Collect() it doesn’t crash. This crash did not occur in mono-android-4.6.08007 and does not throw the below error. However, after the update to 4.8.1., the following error occurs:


08-08 15:03:35.743: E/mono-rt(1600): Stacktrace:
08-08 15:03:35.743: E/mono-rt(1600): at <unknown> <0xffffffff>
08-08 15:03:35.743: E/mono-rt(1600): at (wrapper managed-to-native) object.wrapper_native_0x8233c760 (intptr,intptr,intptr) <IL 0x00025, 0xffffffff>
08-08 15:03:35.743: E/mono-rt(1600): at Android.Runtime.JNIEnv.CallVoidMethod (intptr,intptr) [0x00005] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.0-branch/b76e8ec4/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:352
08-08 15:03:35.743: E/mono-rt(1600): at Android.Graphics.Bitmap.Recycle () [0x0002d] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.0-branch/b76e8ec4/source/monodroid/src/Mono.Android/platforms/android-10/src/generated/Android.Graphics.Bitmap.cs:682
08-08 15:03:35.743: E/mono-rt(1600): at bugImageViewRecycle.SecondActivity.clearCache () [0x00063] in c:\Users\IDUPPEN\Documents\Visual Studio 2012\Projects\bugImageViewRecycle\bugImageViewRecycle\SecondActivity.cs:69
08-08 15:03:35.743: E/mono-rt(1600): at bugImageViewRecycle.SecondActivity.OnDestroy () [0x00008] in c:\Users\IDUPPEN\Documents\Visual Studio 2012\Projects\bugImageViewRecycle\bugImageViewRecycle\SecondActivity.cs:56
08-08 15:03:35.743: E/mono-rt(1600): at Android.App.Activity.n_OnDestroy (intptr,intptr) [0x00008] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.0-branch/b76e8ec4/source/monodroid/src/Mono.Android/platforms/android-10/src/generated/Android.App.Activity.cs:1895
08-08 15:03:35.743: E/mono-rt(1600): at (wrapper dynamic-method) object.729d43ff-8c5e-4c81-a789-2a05b3a5f97b (intptr,intptr) <IL 0x00011, 0x0001b>
08-08 15:03:35.743: E/mono-rt(1600): at (wrapper native-to-managed) object.729d43ff-8c5e-4c81-a789-2a05b3a5f97b (intptr,intptr) <IL 0x00022, 0xffffffff>
08-08 15:03:35.743: E/mono-rt(1600): =================================================================
08-08 15:03:35.743: E/mono-rt(1600): Got a SIGSEGV while executing native code. This usually indicates
08-08 15:03:35.743: E/mono-rt(1600): a fatal error in the mono runtime or one of the native libraries
08-08 15:03:35.743: E/mono-rt(1600): used by your application.
08-08 15:03:35.743: E/mono-rt(1600): =================================================================


To reproduce this issue, please use the following test case:
https://www.dropbox.com/s/y8npqozldj68m7l/bugImageViewRecycle.zip

Steps to reproduce:
Startup activity, click on the button to go to the second activity, click on the button go back to the startup activity and it crashes.

Versioning information:
Microsoft Visual Studio Professional 2012
Version 11.0.60610.01 Update 3
Microsoft .NET Framework
Version 4.5.50709

Installed Version: Professional

LightSwitch for Visual Studio 2012 04938-004-0033001-02595
Microsoft LightSwitch for Visual Studio 2012

Office Developer Tools 04938-004-0033001-02595
Microsoft Office Developer Tools

Team Explorer for Visual Studio 2012 04938-004-0033001-02595
Microsoft Team Explorer for Visual Studio 2012

Visual Basic 2012 04938-004-0033001-02595
Microsoft Visual Basic 2012

Visual C# 2012 04938-004-0033001-02595
Microsoft Visual C# 2012

Visual C++ 2012 04938-004-0033001-02595
Microsoft Visual C++ 2012

Visual F# 2012 04938-004-0033001-02595
Microsoft Visual F# 2012

Visual Studio 2012 Code Analysis Spell Checker 04938-004-0033001-02595
Microsoft® Visual Studio® 2012 Code Analysis Spell Checker

Portions of International CorrectSpell™ spelling correction system © 1993 by Lernout & Hauspie Speech Products N.V. All rights reserved.

The American Heritage® Dictionary of the English Language, Third Edition Copyright © 1992 Houghton Mifflin Company. Electronic version licensed from Lernout & Hauspie Speech Products N.V. All rights reserved.

Visual Studio 2012 SharePoint Developer Tools 04938-004-0033001-02595
Microsoft Visual Studio 2012 SharePoint Developer Tools

AlignAssignments 1.0
Command for aligning assignments.

AutoBraceComplete 1.0
auto brace complete

Color Theme Designer 1.0
Designer for creating new color themes

CustomDocWell 1.0
Provides configurable behavior for the document well in Visual Studio 2012.

NuGet Package Manager 2.2.40116.9051
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

OptionsPageImpl 1.0
Information about my package

PowerCommands for Visual Studio 2010 1.0
A set of power commands for Visual Studio 2010

PreEmptive Analytics Visualizer 1.0
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

Quick Launch Tasks 1.0
Microsoft Quick LaunchTasks package adds accessibility and settings tasks to the Quick Launch tool.

SQL Server Data Tools 11.1.20905.0
Microsoft SQL Server Data Tools

Web Developer Tools 1.2.40308.0
Microsoft Web Developer Tools contains the following components:
Page Inspector: Tool that offers an efficient way to decompose Web Applications and diagnose front-end issues.
Web Publishing: Extensions required for Web Publishing for both hosted servers as well as on premises.
Web Form Templates: Includes the default templates for Web Form Applications.
Editor Extensions: Includes HTML, CSS, and JS editor extensions that greatly enhance the development experience.

Windows Azure Tools October 2012
Windows Azure Tools for Microsoft Visual Studio 2012 - October 2012 v1.8.51019.1603

Xamarin.Android 4.8.01013 (b76e8ec4)
Visual Studio plugin to enable development for Xamarin.Android.
Comment 2 Jonathan Pryor 2013-08-13 13:59:22 UTC
Kumpera: this appears to be a GC bug.

The cause for the crash is that within SecondActivity.clearCache(), `kvp.Value.Handle` is IntPtr.Zero, i.e. the Bitmap has been collected. This doesn't make sense to me, as (via additional logging) SecondActivity.Dispose(bool) isn't invoked and SecondActivity.Handle is not IntPtr.Zero, so I don't understand why the GC collected the Bitmap instances.

Changing SecondActivity.MemoryCache from a List<KeyValuePair<string, Bitmap>> to a List<Bitmap>has no effect (Bitmap.Handle is still IntPtr.Zero when clearCache() executes).
Comment 3 Jonathan Pryor 2013-08-13 14:05:28 UTC
Workaround: check the value of `kvp.Value.Handle` before invoking bm.IsRecycled:

  foreach (KeyValuePair<String, Bitmap> kvp in MemoryCache) {
      if (kvp.Value.Handle == IntPtr.Zero)
          continue;
      ...
  }
Comment 5 Brendan Zagaeski (Xamarin Team, assistant) 2013-09-17 18:19:15 UTC
Two more users have run into this:

1. Another case involving Bitmaps.

2. A case involving Views in MvvmCross/CrossUI.
Comment 10 Jonathan Pryor 2013-09-27 21:51:56 UTC
*** Bug 14188 has been marked as a duplicate of this bug. ***