Using the delegate version of VisualTree.HitTest crashes Unity
Code: Select all
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;
The non-delegate version of this method worked without any crashes.
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Using the delegate version of VisualTree.HitTest crashes Unity
Hi, I was able to reproduce the crash, could you please report it in our bugtracker?
We will solve it for the next release.
We will solve it for the next release.
- ai_enabled
- Posts: 231
- Joined:
- Contact:
Re: Using the delegate version of VisualTree.HitTest crashes Unity
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]
Regards!
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]
Code: Select all
<removed, the original is actually fine>
Last edited by ai_enabled on 30 Aug 2019, 19:35, edited 1 time in total.
AtomicTorch Studio Pte. Ltd. http://atomictorch.com
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Using the delegate version of VisualTree.HitTest crashes Unity
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?
Am I missing anything?
- ai_enabled
- Posts: 231
- Joined:
- Contact:
Re: Using the delegate version of VisualTree.HitTest crashes Unity
@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!
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
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Using the delegate version of VisualTree.HitTest crashes Unity
That fix affects both C# and Unity, they share the managed SDK.
- ai_enabled
- Posts: 231
- Joined:
- Contact:
Re: Using the delegate version of VisualTree.HitTest crashes Unity
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!
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