Bug 45521 - UIRefreshControl crash when with await+async animation on iOS xamarin.forms.
Summary: UIRefreshControl crash when with await+async animation on iOS xamarin.forms.
Status: CONFIRMED
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 2.3.3
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-10-15 07:21 UTC by Bright Lee
Modified: 2016-11-18 04:45 UTC (History)
4 users (show)

Tags: iOS ac
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 for Bug 45521 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Bright Lee 2016-10-15 07:21:11 UTC
I'm making app with Xamarin.forms pcl.

If I use UIRefreshControl with Scrollview on iOS and animation same time. It crash!
Is this bug of UIRefreshControl?
I provide reproduce sample code here. 

<Reproduce sample>
https://github.com/myallb/test_pulltorefresh.git

Sample code is very simple. Is there any mistake??

Thanks.





Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSGenericException Reason: *** Collection <__NSSetM: 0x1919ffb0> was mutated while being enumerated.
Native stack trace:
	0   CoreFoundation                      0x2334db23 <redacted> + 150
	1   libobjc.A.dylib                     0x22b0adff objc_exception_throw + 38
	2   CoreFoundation                      0x2334d58d <redacted> + 0
	3   UIKit                               0x27b82987 <redacted> + 170
	4   CoreFoundation                      0x23264001 <redacted> + 92
	5   CoreFoundation                      0x23263f11 <redacted> + 160
	6   UIKit                               0x27b827f7 <redacted> + 386
	7   UIKit                               0x27b8265f <redacted> + 358
	8   UIKit                               0x281f6dd1 <redacted> + 172
	9   UIKit                               0x27963a4d <redacted> + 548
	10  UIKit                               0x27b8239d <redacted> + 152
	11  UIKit                               0x281f6d1b <redacted> + 122
	12  UIKit                               0x281f6c6d <redacted> + 204
	13  UIKit                               0x27b7baff <redacted> + 114
	14  UIKit                               0x27aa50b5 <redacted> + 320
	15  UIKit                               0x27aa3de5 <redacted> + 80
	16  UIKit                               0x27aa38c1 <redacted> + 292
	17  UIKit                               0x27c48bd5 <redacted> + 196
	18  UIKit                               0x32863895 <redacted> + 40
	19  UIKit                               0x27949bdf <redacted> + 610
	20  UIKit                               0x27ae1491 <redacted> + 2464
	21  UIKit                               0x27e9581b <redacted> + 142
	22  UIKit                               0x27acda53 <redacted> + 170
	23  UIKit                               0x2795de95 <redacted> + 1004
	24  UIKit                               0x27e96b7f <redacted> + 62
	25  UIKit                               0x2791e6d7 <redacted> + 298
	26  UIKit                               0x2791ac49 <redacted> + 2920
	27  UIKit                               0x2795bd81 <redacted> + 904
	28  UIKit                               0x2795b533 <redacted> + 622
	29  UIKit                               0x2792bdd5 <redacted> + 204
	30  UIKit                               0x3284351b <redacted> + 62
	31  UIKit                               0x2792a379 <redacted> + 5016
	32  CoreFoundation                      0x2330f9e7 <redacted> + 14
	33  CoreFoundation                      0x2330f5d7 <redacted> + 454
	34  CoreFoundation                      0x2330d93f <redacted> + 806
	35  CoreFoundation                      0x2325c1c9 CFRunLoopRunSpecific + 516
	36  CoreFoundation                      0x2325bfbd CFRunLoopRunInMode + 108
	37  GraphicsServices                    0x24878af9 GSEventRunModal + 160
	38  UIKit                               0x27994435 UIApplicationMain + 144
	39  libXamarin.iOS.dll.dylib            0x005bbb14 wrapper_managed_to_native_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 272
	40  libXamarin.iOS.dll.dylib            0x00574f98 UIKit_UIApplication_Main_string___intptr_intptr + 52
	41  libXamarin.iOS.dll.dylib            0x00574f58 UIKit_UIApplication_Main_string___string_string + 204
	42  libtest.iOS.exe.dylib               0x0050277c test_iOS_Application_Main_string__ + 188
	43  libmscorlib.dll.dylib               0x009ef4c4 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 256
	44  libmonosgen-2.0.dylib               0x00252f21 mono_jit_runtime_invoke + 1544
	45  libmonosgen-2.0.dylib               0x002aa40f do_runtime_invoke + 78
	46  libmonosgen-2.0.dylib               0x002abfdd mono_runtime_exec_main + 612
	47  libmonosgen-2.0.dylib               0x002abcc7 mono_runtime_run_main + 630
	48  libmonosgen-2.0.dylib               0x0023d5c9 mono_jit_exec + 162
	49  libxamarin-debug.dylib              0x004c940c xamarin_main + 2508
	50  test.iOS                            0x00099b5f main + 112
	51  libdyld.dylib                       0x22f08873 <redacted> + 2

  at at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/data/lanes/3818/ad1cd42d/source/xamarin-macios/src/UIKit/UIApplication.cs:79
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/3818/ad1cd42d/source/xamarin-macios/src/UIKit/UIApplication.cs:63
  at test.iOS.Application.Main (System.String[] args) [0x00008] in /Users/bright/Devlibs/project/__Test/test_pulltorefresh/iOS/Main.cs:17
Comment 1 Bright Lee 2016-10-15 07:21:43 UTC
<Full source code>

public partial class testPage : ContentPage
    {
        public PullToRefreshLayout RefreshView = null;
        AbsoluteLayout layout;

        public testPage()
        {
            InitializeComponent();

            layout = new AbsoluteLayout()
            {
                BackgroundColor = Color.Purple,
            };

            ScrollView scrollview = new ScrollView()
            {
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Content = layout
            };

            RefreshView = new PullToRefreshLayout
            {
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Content = scrollview,
                RefreshColor = Color.Red,
                RefreshCommand = new Command(RefreshStart)
            };
            RefreshView.IsPullToRefreshEnabled = true;

            Content = RefreshView;

            Device.StartTimer(new TimeSpan(0, 0, 1), ani);
        }


        bool ani()
        {
            Label z = new Label()
            {
                Text = "Z",
                TextColor = Color.White,
                FontAttributes = FontAttributes.Bold,
                FontSize = new Random().Next(22, 35)
            };

            AbsoluteLayout.SetLayoutBounds(z, new Rectangle(0.67 + new Random().Next(0, 10) / 100.0, 0.13 + new Random().Next(0, 10) / 100.0, 40, 40));
            AbsoluteLayout.SetLayoutFlags(z, AbsoluteLayoutFlags.PositionProportional);
            layout.Children.Add(z);

            Device.BeginInvokeOnMainThread(async () =>
            {
                Task t1 = z.FadeTo(0, 3500);
                Task t2 = z.TranslateTo(0, -70, 3500, Easing.SinInOut);

                await Task.WhenAll(t1, t2);
                layout.Children.Remove(z);
            });

            return true;
        }

        void RefreshStart()
        {
            Debug.WriteLine("RefreshStart");

            if (RefreshView != null)
                RefreshView.IsRefreshing = true;

            Device.BeginInvokeOnMainThread(async () =>
            {
                await Task.Delay(20);

                Debug.WriteLine("RefreshEnd");
                RefreshView.IsRefreshing = false;
            });
        }
    }
Comment 2 Bright Lee 2016-10-24 16:51:13 UTC
Please try to refresh many time. 
It's very rare.
Comment 3 adrianknight89 2016-11-18 04:45:39 UTC
Are you aware that XF ListView has a built in refresh control? Not sure if that library is needed unless you, of course, need to use ScrollView.