Xamarin.Forms.GoogleMaps: Crash when using BitmapDescriptorFactory.FromView for custom Pin.
VERSIONS
- Xamarin.Forms.GoogleMaps - 2.3.0
- Xamarin.Forms - 3.0.0.550147
PLATFORMS
- Android
- [] iOS
- UWP
ACTUAL BEHAVIOR
Android 7.0 When I using custom Pin view with the local resource, sometimes it make a crash.
ACTUAL SCREENSHOTS/STACKTRACE
AppCenterCrashes] Unhandled Exception from source=AndroidEnvironment
[AppCenterCrashes] System.NullReferenceException: Object reference not set to an instance of an object.
[AppCenterCrashes] at System.Collections.Generic.LinkedList`1[T].InternalInsertNodeBefore (System.Collections.Generic.LinkedListNode`1[T] node, System.Collections.Generic.LinkedListNode`1[T] newNode) [0x00013] in <5a97d41d36694fb19855c17429527b10>:0
[AppCenterCrashes] at System.Collections.Generic.LinkedList`1[T].AddLast (T value) [0x00019] in <5a97d41d36694fb19855c17429527b10>:0
[AppCenterCrashes] at Xamarin.Forms.GoogleMaps.Android.Utils+<>c__DisplayClass6_0.<ConvertViewToBitmapDescriptor>b__0 () [0x000e6] in <2708054b9c524524949e63a8d8895424>:0
[AppCenterCrashes] at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
[AppCenterCrashes] at System.Threading.Tasks.Task.Execute () [0x00010] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
[AppCenterCrashes] --- End of stack trace from previous location where exception was thrown ---
[AppCenterCrashes] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
[AppCenterCrashes] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
[AppCenterCrashes] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
[AppCenterCrashes] at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
[AppCenterCrashes] at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
[AppCenterCrashes] at Xamarin.Forms.GoogleMaps.Logics.Android.PinLogic+<TransformXamarinViewToAndroidBitmap>d__29.MoveNext () [0x001e3] in <2708054b9c524524949e63a8d8895424>:0
[AppCenterCrashes] --- End of stack trace from previous location where exception was thrown ---
[AppCenterCrashes] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
[AppCenterCrashes] at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
[AppCenterCrashes] at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <f9b96d3a30e44b50a15b67d62391cfda>:0
[AppCenterCrashes] at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <f9b96d3a30e44b50a15b67d62391cfda>:0
[AppCenterCrashes] at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <f9b96d3a30e44b50a15b67d62391cfda>:0
[AppCenterCrashes] at (wrapper dynamic-method) System.Object.60b093c8-a10f-4fc4-a0c3-a7ee9f1e4fa1(intptr,intptr)
EXPECTED BEHAVIOR
Is anyway to fix it ?
HOW TO REPRODUCE
It’s not 100% reproduce, just happen randomly when I try to add multi-marker by using for loop as the code below
foreach(Market m in _marketList) {
var pin = new Pin()
{
Type = PinType.Generic,
Address = m.id.ToString(),
Label = m.id.ToString(),
Flat = true,
Position = new Position(m.location.Latitude, m.location.Longitude),
Icon = BitmapDescriptorFactory.FromView(new PinView(m.resouce);
};
myMap.Pins.Add(pin);
}
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 16 (4 by maintainers)
Commits related to this issue
- to fix #524, Crash when using BitmapDescriptorFactory.FromView — committed to jerryhuang-net/Xamarin.Forms.GoogleMaps by deleted user 5 years ago
- Merge pull request #642 from jerryhuang-net/master to fix #524, Crash when using BitmapDescriptorFactory.FromView — committed to amay077/Xamarin.Forms.GoogleMaps by amay077 5 years ago
Hi all i have solved the issue, error occurred on below method which is found in Xamarin.Forms.GoogleMaps.Android.Util.cs classs.
public static Task<ViewGroup> ConvertFormsToNative(View view, Rectangle size, IVisualElementRenderer vRenderer) { return Task.Run(() => { var viewGroup = vRenderer.ViewGroup; vRenderer.Tracker.UpdateLayout(); var layoutParams = new ViewGroup.LayoutParams((int)size.Width, (int)size.Height); viewGroup.LayoutParameters = layoutParams; view.Layout(size); viewGroup.Layout(0, 0, (int)view.WidthRequest, (int)view.HeightRequest); //await FixImageSourceOfImageViews(viewGroup as ViewGroup); // Not sure why this was being done in original return viewGroup; }); }
in the line “var viewGroup = vRenderer.ViewGroup;” it is giving a warning “ViewGroup is obsolete as of version 2.3.5. Please use View instead.”.on the runtime , its getting null. so i have fixed it by implementing the suggestion that is given in the warning, here is the fix
public static Taskglobal::Android.Views.View ConvertFormsToNative(View view, Rectangle size, IVisualElementRenderer vRenderer) { return Task.Run(() => { var viewGroup = vRenderer.View; vRenderer.Tracker.UpdateLayout(); var layoutParams = new ViewGroup.LayoutParams((int)size.Width, (int)size.Height); viewGroup.LayoutParameters = layoutParams; view.Layout(size); viewGroup.Layout(0, 0, (int)view.WidthRequest, (int)view.HeightRequest); //await FixImageSourceOfImageViews(viewGroup as ViewGroup); // Not sure why this was being done in original return viewGroup; }); }
i am new in github don’t know how to commit this code.
Same here
I released v3.2.1 that includes fix this.
Look like I fixed this bug, that I do not see crash log anymore for couple weeks.
In my case, this happen because of synchronized thread running at the same time, for an example, call add pin while the map is clearing the pins.
So i make it await, try to handle it not called to add, clear pins at the same time and it good to go.
I got the same issue but its not easy to reproduce. Sometime the app crashs when rendering custom pin from view.
@amay077 CachingNativeBitmapDescriptorFactory look cannot resolve the problem, I will continuous investigate it and report the root cause later
@amay077 Thank for your quick reply. I will try to implement it and report here if it happens again.