You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When enabling and focusing a EditText UI element using IsSelectionActive = true, the error Object reference not set to an instance of an object is thrown. However, the EditText element seems to be responsive and accepts input anyway.
Log and callstacks [EditTextSample.UiScript]: Error: Object reference not set to an instance of an object. [EditTextSample.UiScript]: Error: at Stride.Core.ServiceRegistryExtensions.GetSafeServiceAs[T](IServiceRegistry registry) in C:\BuildAgent\work\b5f46e3c4829a09e\sources\core\Stride.Core\ServiceRegistryExtensions.cs:line 22 at Stride.UI.Controls.EditText.ActivateEditTextImpl() in C:\BuildAgent\work\b5f46e3c4829a09e\sources\engine\Stride.UI\Controls\EditText.Direct.cs:line 125 at Stride.UI.Controls.EditText.set_IsSelectionActive(Boolean value) in C:\BuildAgent\work\b5f46e3c4829a09e\sources\engine\Stride.UI\Controls\EditText.cs:line 160
The text was updated successfully, but these errors were encountered:
Providing some research I did for whom ever picks this up.
Problem
I think this exception is happening when UIComponent is enabled and IsSelectionActive = true happens in the same frame.
Work Around
Wait another frame before running UIComponentIsSelectionActive = true
Enable UIComponent from the start and avoid the problem entirely.
Problem Explanation
This happens due to the EditText not having a Services set until the update run. This seems to be a unique problem to EditText.Direct (not that I tested it) due to UIElementServices.Services.GetSafeServiceAs<InputManager>(); being in EditText type Direct, but other UIElements may require it too.
The nullServices is a IServiceRegistry and they all get set by their parent during run time by the UIElement.Update, where the parent passes their Services (aka registry) to the child. This is why running IsSelectionActive = true on the next frame after UIComponent is enabled, works.
I believe the UIRenderFeatureDrawInternal that kicks off this process by setting a Page's rootElement which passes down Services to the children through Update.
Two suggestion for solutions
Try to pass in the Services on the UIElement SetParent, Which may also mean before the UIRenderFeatureDrawInternal as well.
Find a different way for the code to handle ActivateEditTextImpl without needing to accessing Services early. DeactivateEditTextImpl most likely wont need to change, but it could help just in case some tries to call it on the same frame.
This UIElementServices.Services.GetSafeServiceAs<InputManager>(); appears to only be called by EditText Direct from searching the entire solution
Release Type: Official Release
Version: 4.2.0.2282
Platform(s): Windows
Describe the bug
When enabling and focusing a EditText UI element using
IsSelectionActive = true
, the errorObject reference not set to an instance of an object
is thrown. However, the EditText element seems to be responsive and accepts input anyway.To Reproduce
Repro project: https://github.com/BlackCurtainStudio/Stride-EditTextSample
Expected behavior
No errors should occur.
Screenshots
Log and callstacks
[EditTextSample.UiScript]: Error: Object reference not set to an instance of an object. [EditTextSample.UiScript]: Error: at Stride.Core.ServiceRegistryExtensions.GetSafeServiceAs[T](IServiceRegistry registry) in C:\BuildAgent\work\b5f46e3c4829a09e\sources\core\Stride.Core\ServiceRegistryExtensions.cs:line 22 at Stride.UI.Controls.EditText.ActivateEditTextImpl() in C:\BuildAgent\work\b5f46e3c4829a09e\sources\engine\Stride.UI\Controls\EditText.Direct.cs:line 125 at Stride.UI.Controls.EditText.set_IsSelectionActive(Boolean value) in C:\BuildAgent\work\b5f46e3c4829a09e\sources\engine\Stride.UI\Controls\EditText.cs:line 160
The text was updated successfully, but these errors were encountered: