marcojak / MTAdmob

Admob plugin for Xamarin Android and iOS
https://www.xamarinexpert.it/admob-made-easy/
160 stars 26 forks source link

iOS Crach after back to previous view #120

Open PrzemekZA opened 1 year ago

PrzemekZA commented 1 year ago

Describe the bug App crash when back to previous view from view where banner is.

{System.NullReferenceException: Object reference not set to an instance of an object
  at MarcTron.Plugin.Renderers.AdViewRenderer.OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs'1[TElement] e) [0x00075] in <518e4ffda48f4eb1896acaa8d2c1eb18>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer'1[TElement].SetElement (TElement element) [0x0017a] in <95d1c404699e420c91deaf9742b39577>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer'1[TElement].Dispose (System.Boolean disposing) [0x0008c] in <95d1c404699e420c91deaf9742b39577>:0 
  at Xamarin.Forms.Platform.iOS.ViewRenderer'2[TView,TNativeView].Dispose (System.Boolean disposing) [0x0005c] in <95d1c404699e420c91deaf9742b39577>:0 
  at Foundation.NSObject.Dispose () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.0.0.72/src/Xamarin.iOS/Foundation/NSObject2.cs:227 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.Dispose (System.Boolean disposing) [0x0003f] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:91 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.Dispose () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:41 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer'1[TElement].Dispose (System.Boolean disposing) [0x00058] in <95d1c404699e420c91deaf9742b39577>:0 
  at Foundation.NSObject.Dispose () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.0.0.72/src/Xamarin.iOS/Foundation/NSObject2.cs:227 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.Dispose (System.Boolean disposing) [0x0003f] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:91 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.Dispose () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:41 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer'1[TElement].Dispose (System.Boolean disposing) [0x00058] in <95d1c404699e420c91deaf9742b39577>:0 
  at Foundation.NSObject.Dispose () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.0.0.72/src/Xamarin.iOS/Foundation/NSObject2.cs:227 
  at Xamarin.Forms.Platform.iOS.DisposeHelpers.DisposeModalAndChildRenderers (Xamarin.Forms.Element view) [0x00042] in D:\a\1\s\Xamarin.Forms.Platform.iOS\DisposeHelpers.cs:23 
  at Xamarin.Forms.Platform.iOS.Platform.HandleChildRemoved (System.Object sender, Xamarin.Forms.ElementEventArgs e) [0x00006] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:371 
  at Xamarin.Forms.Element.OnDescendantRemoved (Xamarin.Forms.Element child) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:593 
  at Xamarin.Forms.Element.OnDescendantRemoved (Xamarin.Forms.Element child) [0x00018] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:594 
  at Xamarin.Forms.Element.OnChildRemoved (Xamarin.Forms.Element child, System.Int32 oldLogicalIndex) [0x00027] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:348 
  at Xamarin.Forms.VisualElement.OnChildRemoved (Xamarin.Forms.Element child, System.Int32 oldLogicalIndex) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:850 
  at Xamarin.Forms.Page.InternalChildrenOnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x0003b] in D:\a\1\s\Xamarin.Forms.Core\Page.cs:498 
  at System.Collections.ObjectModel.ObservableCollection'1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00018] in <504c0d7e7072450ba814667235f35ffa>:0 
  at System.Collections.ObjectModel.ObservableCollection'1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedAction action, System.Object item, System.Int32 index) [0x00009] in <504c0d7e7072450ba814667235f35ffa>:0 
  at System.Collections.ObjectModel.ObservableCollection'1[T].RemoveItem (System.Int32 index) [0x00021] in <504c0d7e7072450ba814667235f35ffa>:0 
  at System.Collections.ObjectModel.Collection'1[T].Remove (T item) [0x00027] in <f816f9a78b7342b49735899bb960e7b6>:0 
  at Xamarin.Forms.NavigationPage.Xamarin.Forms.INavigationPageController.RemoveAsyncInner (Xamarin.Forms.Page page, System.Boolean animated, System.Boolean fast) [0x000e7] in D:\a\1\s\Xamarin.Forms.Core\NavigationPage.cs:362 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.UpdateFormsInnerNavigation (Xamarin.Forms.Page pageBeingRemoved) [0x00072] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:844 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer+ParentingViewController.DidMoveToParentViewController (UIKit.UIViewController parent) [0x0003a] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:1504 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021 
  at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.0.0.72/src/Xamarin.iOS/Foundation/NSAction.cs:178 
  at (wrapper managed-to-native) UIKit.UIApplication.xamarin_UIApplicationMain(int,string[],intptr,intptr,intptr&)
  at UIKit.UIApplication.UIApplicationMain (System.Int32 argc, System.String[] argv, System.IntPtr principalClassName, System.IntPtr delegateClassName) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.0.0.72/src/Xamarin.iOS/UIKit/UIApplication.cs:57 
  at UIKit.UIApplication.Main (System.String[] args, System.Type principalClass, System.Type delegateClass) [0x0003b] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.0.0.72/src/Xamarin.iOS/UIKit/UIApplication.cs:92

To Reproduce Steps to reproduce the behavior:

  1. Go to view where banner is visable.
  2. Click Back
  3. App crash

Expected behavior App will not crash

Smartphone (please complete the following information):

Additional context Issue is on plugin version 1.9.0.2 In previous versions of the plugin it was fine

PrzemekZA commented 1 year ago

App is crashing when NavigationPage is used. Sample: https://github.com/PrzemekZA/AdMobTest

PrzemekZA commented 1 year ago

Solution: create ViewRender with code

protected override void OnElementChanged(ElementChangedEventArgs<MTAdView> e)
        {
            if (e.NewElement == null)
                return;

            base.OnElementChanged(e);
        }
marcojak commented 1 year ago

Thank you. I've found the issue with the code and I'll release a new version that will fix it.

ice-lenor commented 1 year ago

Hello @marcojak! I wonder if you managed to take a look at this bug yet? No pressure, holidays and all, just wondering :). Please let me know if you need any help testing. Thank you for the wonderful plugin and Happy Holidays!