简体   繁体   中英

Xamarin/Tizen: Executing Navigation.PopAsync() crashes the app

I have a navigation page that sets up three pages. The first page loads, the user has to pick an option from a listview and then it loads the second page with PushAsync() . At this point the user can now navigate between the three pages by turning the clock face. If I call PopToRootAsync() on the second page it works fine. If the rotary clock face is turned clockwise it loads a third page via PushAsync() .

The problem is if I call PopAsync() on that third page OR I change the PopToRootAsync() on the second page to a PopAsync() , the app crashes. I have no way to determine what the error is either as I just get segmentation fault and nothing is written to the Tizen log that is seemingly indicative of why it crashed.

Is there some reason that a PopAsync() would cause this? I know I saw some other articles this could occur if the MainPage is not loaded into a NavigationPage but I'm doing that. I've been looking through stuff and writing debug logs for days but have nothing to show for it. Any help would be more than appreciated. Thank you!

App.cs

public App()
{
     MainPage = new NavigationPage(new ServerSelectionPage());    
}

ServerSelection.cs

private void ServerSelection_OnItemTapped(object sender, ItemTappedEventArgs args)
{
    App.SERVER = (Server)args.Item;
    Navigation.PushAsync(new ArrowsPage());
}

PageBase.cs

public async void Rotate(RotaryEventArgs args)
{
    Page _currentPage = Page.REMOTE_BUTTONS;

    if (this.GetType() == typeof(ButtonsPage))
        _currentPage = Page.REMOTE_BUTTONS;
    else if (this.GetType() == typeof(ArrowsPage))
        _currentPage = Page.REMOTE_ARROWS;
    else
        _currentPage = Page.SERVER_SELECTION;

    // When rotating (previous rotation is ongoing, do nothing)
    if (_rotating)
    {
        return;
    }

    _rotating = true;

    if (!(App.SERVER is null))
    {
        if (_currentPage == Page.SERVER_SELECTION)
        {
            if (args.IsClockwise)
                await Navigation.PushAsync(new ArrowsPage());
        }
        else if (_currentPage == Page.REMOTE_DIRECTIONAL)
        {
            if (args.IsClockwise)
                await Navigation.PushAsync(new ButtonsPage());
            else
                await Navigation.PopToRootAsync();
        }
        else
        {
            try
            {
                if (!args.IsClockwise)
                    await Navigation.PopAsync(); // This will crash the app
            }
            catch(Exception ex)
            {
                Log.Debug(ex.Message);
            }
        }
    }

    _rotating = false;
}

After reading the comment by @vin about checking if the Navigation object is null I suddenly had the thought that it may not be the Navigation page but the RotaryFocusObject. So I changed

 if (!args.IsClockwise)
    await Navigation.PopAsync();

to

 if (!args.IsClockwise)
 {
   RotaryFocusObject = null;
   await Task.Delay(300);
   await Navigation.PopAsync();
 }

and it no longer crashes. The delay is necessary as if you call PopAsync right after setting the object to null it can still sometimes crash.

So apparently if you pop the current page it causes an error as the focus of the rotary dial is still set to the current navigation page. Why this error does not seemingly occur if you use the Navigation.PopToRootAsync() makes no sense to me.

Navigation.PopToRootAsync() and Navigation.PopToRootAsync() are causing destroy of Page renderer, and the Rotate handler is belong to Page Renderer, If Page renderer was deleted before completion of Rotate Native Callback that is belong to Page renderer, it will be crashed.

await Task.Delay() let to returning native callback.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM