Does UrhoSharp actually work with Xamarin.Forms multi-page app?

roesterroester USUniversity ✭✭

I was very excited when I found out about UrhoSharp and read that it was compatible with Xamarin.Forms. The recent 1.3.0 release looks great, and the road map listing stability and better Forms support in an upcoming 1.4 is good to see.

That said, I'm seeing the same blocking crashing bug reported by multiple users, even using the Forms (Charts) sample provided by Xamarin. The sample works as a single page demo. The moment you add/switch to any other page and return to the original Urho page which calls Urho.Application.Show() when appearing, the scene (which worked flawlessly the first time you visit the page) no longer looks right and guaranteed to crash a few seconds later.

After hours looking for a workaround, it makes me ask:
Does UrhoSharp actually work with Xamarin.Forms on an iOS device? Or is it going to crash in any multi-page Forms app, until a future update?

Is anyone using UrhoSharp successfully in a multi-page Xamarin.Forms app today?

If so, what is the proper/working way to setup the Urho.Application in the page constructor, and initialize (connect the Urho.Application to the UrhoSurface) in the OnAppearing event, and clean up in the OnDisappearing event to support returning to that same page?

Thank you.

Posts

  • EgorBoEgorBo BYXamarin Team ✭✭✭

    @roester Sorry to hear you faced with this issue - as I said, in 1.4 I am going to fix such kind of issues and improve the XForms support.

  • roesterroester USUniversity ✭✭

    Thank you for the response @EgorBo. Is it possible to work around the Xamarin.Forms crashing issue with a Custom Renderer and lower level access to UrhoSharp initialization and cleanup?

  • MousseMousse USMember
    edited April 14

    I've put a bool _isInit in my content page, and I used it like this.

    protected override async void OnAppearing()
    {
    if (!_isInit)
    {
    _isInit = true;
    View3D = await surface.Show(new Urho.ApplicationOptions(assetsFolder: null)
    {
    Orientation = Urho.ApplicationOptions.OrientationType.LandscapeAndPortrait
    });
    }
    else
    {
    UrhoSurface.OnResume();
    }
    }

    protected override async void OnDisappearing()
    {
    UrhoSurface.OnPause();
    base.OnDisappearing();
    }

    You don't need to destroy the surface every time you switch between pages, so this will create a new instance first time you open the page and will just put it on pause later.

    It works on IOS Simulator, I think it will work on iPhone or iPad as well.

  • roesterroester USUniversity ✭✭

    @Mousse that did stop the crashing when re-entering the page. So I'm one step closer. Thank you!

    However, the scene is missing when returning to the page. The background of the UrhoSurface is black regardless of what the viewport SetClearColor is set to and none of the nodes are visible. Same on simulator and actual iPhone device. Is there a step missing to enable displaying the scene after OnResume is called?

  • MousseMousse USMember
    edited April 15

    I guess you create a new page when returning to the page? With Pause/Resume, you have to store them as parameters in App.cs. I used NavigationPage, here is an example:

    In App.cs: put 2 content pages
    PageA a;
    PageB b;

    In constructor of App.cs :
    a = new PageA();
    b = new PageB();
    MainPage = new NavigationPage(a);

    So you will start with page "a". Use PushAsync to go to page "b" : Navigation.PushAsync(App.b);
    And use PopAsync() if you have a personalized button, or else it will return to the first page automatically :)

  • roesterroester USUniversity ✭✭

    Thank you @Mousse for the response. Sorry I wasn't clearer. I'm new to Urho, not new to Xam. I am not creating new pages every time. I am already caching the page instances in App. I've confirmed in the debugger when returning to the page with the UrhoSurface that all of the instance members are still there. Are you getting the Forms sample bar chart to show up when returning to the page with UrhoSurface.OnResume? It sounds like you've tried it on a simulator.

    I've found a list of forum posts going back a year with the same issue as this post trying to re-enter the page in Xamarin's only Forms sample.

    Back to my original question: Is anyone using UrhoSharp successfully in a multi-page Xamarin.Forms app today?

  • MousseMousse USMember
    edited April 16

    I didn't use the Form sample with bar charts, I only have some 3D animated models.

    I'm new to Urho too, but I've worked on similar 3D&form softwares for some time.

    As my models show correctly while returning to the page, it's more like that your chart bars haven't been updated properly.
    Have you look at documentations ? Are there some functions relatif to OnPause/OnResume must be implemented in the Bar class? Like onUpdate, onAppearing, event to subscribe/unsubscribe...

    Sorry, I can't help you further X(

  • roesterroester USUniversity ✭✭

    That does help @Mousse. Thank you!

    Knowing it works for you is enough for me to keep digging. I just didn't want to bang my head against the wall if nobody had a multi-page forms app working with it. I think my next step is to simply abandon trying to use Xamarin's Forms sample as a starting point. It clearly has more than one bug blocking it from being used with more than a single page.

  • DMcLennanDMcLennan GBMember ✭✭

    @Mousse Do you have a sample project of this pause/resume workaround? I'm having the same problem as roester that the Urho surface seems to be gone when navigating back to the page.

    Urho seems great for what I need to do, especially now that CocosSharp is dead, but this navigation snag really kills things for me. For me, just following the forms sample (and testing on Android), the issue is that when you navigate from the Urho page back to the first page sometimes it will hang, then eventually crash.

  • EgorBoEgorBo BYXamarin Team ✭✭✭

    Navigation issue has been fixed in master for iOS.
    I'll release an update once I fix Android UrhoSurface.

  • roesterroester USUniversity ✭✭

    Excellent. I'm looking forward to trying it when released. Thank you!

  • roesterroester USUniversity ✭✭

    @EgorBo : I noticed UrhoSharp.Forms v1.4.18 in the Nuget update list. I tried it and my original question/issue about crashing while returning to Forms pages with an Urho surface is fixed.

    The fix works when calling UrhoSurface.OnDestroy in the OnDisappearing method, then re-initializing when returning to the page in OnAppearing.

    Thank you!

  • DMcLennanDMcLennan GBMember ✭✭

    That's great news and I hope Android is to follow :)

  • NeilJNeilJ GBMember

    @EgorBo Hey I noticed a few updates have been posted recently but the Android issue is still ongoing -- experiencing crashes after switching between a few pages. Any news on how this is going?

    Thanks, man

  • DMcLennanDMcLennan GBMember ✭✭

    Hi, I noticed in the UrhoSharp.Forms NuGet for 1.4.47 "Fixed crash in UrhoSurface for Android (CreateSurface now returns UrhoSurfacePlaceholder with the same API)".

    Unfortunately I'm still having the same navigation hang/crash issue I described. I could send my project if it would help?

  • Abhijeet_SuryaAbhijeet_Surya USMember ✭✭✭
    edited September 27

    @EgorBo

    I am facing one issue in iOS

    UrhoSurface is not getting iniatialized & getting stuck on this line urhoSurface.Show.

    I have face this issue with Android as well & the fix was to to call show when view is visible, but same is not working with IOS

    I have some other sample where I am able to run Urho.Show on iOS, so the problem is with my code only - but same code works for UWP, Android & fails on iOS.

    I want to know the steps for digonising the issue on iOS.

Sign In or Register to comment.