Forum Libraries, Components, and Plugins
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

UrhoSharp and threads on UWP

I have a Xamarin Forms app that is supposed to run on iOS , Android and Windows (UWP). It uses UrhoSharp for some 3D visualizations. It is working fine on iOS and Android and I have just started with the Windows project.

The Urho3D canvas gets created but none of my nodes appear. I think the canvas is being drawn because I can change the fog color of the zone and it displays the new color correctly.

It is not clear how to debug my problem of why my nodes don't appear. However, if I click a button that creates a new node, the app will generally crash in a way that implies a threading problem. I think the event thread the button click happens on and the Urho update thread needs some sort of synchronization. Possibly that is also the issue with none of my initial nodes appearing.

However, if I lock the Urho OnUpdate() code and the button click code, the app seems to deadlock for 120 seconds.

Does anyone have any thoughts about how to handle threading here for the UWP target?

Best Answer

  • btschumybtschumy Member ✭✭
    Accepted Answer

    Well, after a good day and a half of debugging, I finally figured out the problem. Here is my code that stars up the UrhoApp

        public async void StartUrhoApp()
        {
            if (UrhoApp == null)
            {
                var options = new ApplicationOptions("UrhoData")
                {
                    Orientation = ApplicationOptions.OrientationType.LandscapeAndPortrait,
                    Multisampling = 8,
                    LimitFps = false
                };
                UrhoApp = await galaxySurface.Show<UrhoApp>(options);
            }
        }
    

    Turns out that the problem is setting Multisampling = 8 in the ApplicationOptions. I no longer remember where I found the suggestion to set it to 8, but it could have been in this thread:

    https://github.com/xamarin/urho/issues/200

    Basically I was trying to lessen the aliasing of lines and that seemed to help on iOS. It looks like on UWP, anything greater than 1 causes the Urho app to fail to draw.

    I have been unable to find any documentation on the Multisampling option other than that 1 means "no multisampling".

    It would be nice if some exception was thrown or log message written if there is an invalid parameter.

    Can someone tell me the best way to antialias lines in Urho? I already set LineAntiAlias to tru in the material. Is that the best I can do?

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    Here is a sample for UrhoSharp in Forms:
    https://github.com/xamarin/urho-samples/tree/f1bcec78cf8b08c19f5bf29ddfd44181c9e47295
    Have you tried this?
    I found this might be a little out of date so I created a simple one using the latest Forms version.
    You could refer to it for the specific code.

  • btschumybtschumy Member ✭✭

    I have run that on iOS but not Windows. I tried it on Windows and initially the Urho graphics were partly offscreen (see attached image). There were a number of NuGet packages that had updates available and after updating, the graphics were centered as expected!

    That makes me wonder if my graphics are not appearing on UWP because they are offscreen. Not sure why that would be or how to know if that is the problem.

    The Forms Sample app doesn't create nodes after the app launches so I can see there are problems doing that.

    As I mentioned, I would think that adding synchronization locks for the Urho update thread and the event thread would fix some of my problems, but there seems to be a mysterious deadlock (that does expire after 120 seconds). Not sure what that is about.

  • btschumybtschumy Member ✭✭

    Oops, here is the screenshot.

  • btschumybtschumy Member ✭✭

    LandLu,

    I actually used the FormsSample as a template for creating my app. The main difference is that I create the Urho view during app startup whereas the FormsSample creates in in response to clicking a button. I wonder if that could be responsible.

    I can try delaying the creation of the Urho app until after startup to see if that makes a difference.

  • LandLuLandLu Member, Xamarin Team Xamurai

    If you still can't run it on your side, please share your sample here.

  • btschumybtschumy Member ✭✭
    Accepted Answer

    Well, after a good day and a half of debugging, I finally figured out the problem. Here is my code that stars up the UrhoApp

        public async void StartUrhoApp()
        {
            if (UrhoApp == null)
            {
                var options = new ApplicationOptions("UrhoData")
                {
                    Orientation = ApplicationOptions.OrientationType.LandscapeAndPortrait,
                    Multisampling = 8,
                    LimitFps = false
                };
                UrhoApp = await galaxySurface.Show<UrhoApp>(options);
            }
        }
    

    Turns out that the problem is setting Multisampling = 8 in the ApplicationOptions. I no longer remember where I found the suggestion to set it to 8, but it could have been in this thread:

    https://github.com/xamarin/urho/issues/200

    Basically I was trying to lessen the aliasing of lines and that seemed to help on iOS. It looks like on UWP, anything greater than 1 causes the Urho app to fail to draw.

    I have been unable to find any documentation on the Multisampling option other than that 1 means "no multisampling".

    It would be nice if some exception was thrown or log message written if there is an invalid parameter.

    Can someone tell me the best way to antialias lines in Urho? I already set LineAntiAlias to tru in the material. Is that the best I can do?

  • jddjdd USMember ✭✭✭

    @btschumy said:
    Can someone tell me the best way to antialias lines in Urho? I already set LineAntiAlias to tru in the material. Is that the best I can do?

    I meet the same issue: on android the image is smooth and on UWP it is aliased.
    I have been told to add:

    viewport.RenderPath.Append(CoreAssets.PostProcess.FXAA2);
    

    But whatever PostProcess I add, I get a blank page on UWP. Could you try and tell me what you get?

  • btschumybtschumy Member ✭✭

    @jdd said:

    @btschumy said:
    Can someone tell me the best way to antialias lines in Urho? I already set LineAntiAlias to tru in the material. Is that the best I can do?

    I meet the same issue: on android the image is smooth and on UWP it is aliased.
    I have been told to add:

    viewport.RenderPath.Append(CoreAssets.PostProcess.FXAA2);
    

    But whatever PostProcess I add, I get a blank page on UWP. Could you try and tell me what you get?

    I also get a blank screen if I append to the RenderPath. I tired a variety of PostProcess types and all yielded a blank screen.

Sign In or Register to comment.