asusralis
Topic Author
Posts: 142
Joined: 30 Jul 2018, 05:03

Using the delegate version of VisualTree.HitTest crashes Unity

29 Jul 2019, 17:30

Noesis.Visual root = (Noesis.Visual)Noesis.VisualTreeHelper.GetRoot(view.Content);

            Noesis.HitTestResult result = null;

            Noesis.VisualTreeHelper.HitTest(root,
                (target) =>
                {
                    var element = target as Noesis.UIElement;

                    if ((element != null) && (!element.IsHitTestVisible || !element.IsVisible))
                    {
                        return Noesis.HitTestFilterBehavior.ContinueSkipSelfAndChildren;
                    }
                    else
                    {
                        return Noesis.HitTestFilterBehavior.Continue;
                    }
                },
               (target) =>
               {
                   result = target;

                   return Noesis.HitTestResultBehavior.Stop;
               }, new Noesis.PointHitTestParameters(new Noesis.Point(Input.mousePosition.x, Screen.height - Input.mousePosition.y)));

            return result?.VisualHit != null;
When I click play in Unity this 'fix' works, but after I exit play and play again Unity will crash without warning. Oddly enough, when I have my debugger attached to Unity it will never crash and I am free to start/end play as many times as I want. However, as soon as I detach visual studio and play again it will crash.

The non-delegate version of this method worked without any crashes.
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: Using the delegate version of VisualTree.HitTest crashes Unity

01 Aug 2019, 17:51

Hi, I was able to reproduce the crash, could you please report it in our bugtracker?
We will solve it for the next release.
 
 
User avatar
ai_enabled
Posts: 231
Joined: 18 Jul 2013, 05:28
Contact:

Re: Using the delegate version of VisualTree.HitTest crashes Unity

29 Aug 2019, 22:25

I'm curious whether this issue is also affecting non-Unity version?

I've just found about about the new VisualTree.HitTest delegate version (I've missed it in the changelog when it was introduced only in 2.2.0b6). Exciting! I was finally able to remove weird piece of hit testing check and write reliable implementation to detect whether the click was actually suppressed by UI library.

[s]However, I've noticed that snippet provided by @asusralis doesn't actually work for my case. As hit testing goes from top-most controls to back (in visual tree hierarchy), first hit-testing candidates might actually be inside parents which have IsHitTestEnabled/IsVisible==False. So I've added an extract check to determine whether this is the case and ignore such hit test results.[/s]
<removed, the original is actually fine>
Regards!
Last edited by ai_enabled on 30 Aug 2019, 19:35, edited 1 time in total.
AtomicTorch Studio Pte. Ltd. http://atomictorch.com
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: Using the delegate version of VisualTree.HitTest crashes Unity

30 Aug 2019, 17:14

Filter callback is being called from root to descendants, so if you are already filtering out UIElements with IsHitTestVisible="false", I don't get why you need to traverse up the tree again on the result callback to look for parents with IsHitTestVisible="false", you shouldn't find any.

Am I missing anything?
 
User avatar
ai_enabled
Posts: 231
Joined: 18 Jul 2013, 05:28
Contact:

Re: Using the delegate version of VisualTree.HitTest crashes Unity

30 Aug 2019, 19:34

@sfernandez, you're right. It's me who is writing wrong code :-) probably need a vacation...
Thank you. For some reason, I've incorrectly changed || to && in the IsHitTestVisible || IsVisible check.
The original code works perfectly. Thanks!

BTW, I'm curious if the update to latest NoesisGUI version required (as it contains fix [Unity] Using the delegate version of VisualTree.HitTest crashes Unity (#1527)) or it's only a fix for Unity version and C# SDK itself is not affected?
Regards!
AtomicTorch Studio Pte. Ltd. http://atomictorch.com
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: Using the delegate version of VisualTree.HitTest crashes Unity

30 Aug 2019, 20:18

That fix affects both C# and Unity, they share the managed SDK.
 
User avatar
ai_enabled
Posts: 231
Joined: 18 Jul 2013, 05:28
Contact:

Re: Using the delegate version of VisualTree.HitTest crashes Unity

30 Aug 2019, 20:25

Thanks!
I would prefer if you mark such as C#/Unity in the release notes as it's really important for all of us who're not using Unity but using C# SDK.
Regards!
AtomicTorch Studio Pte. Ltd. http://atomictorch.com

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 9 guests