Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Slider put in Canvas NaN Exception #2604

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sources/engine/Stride.UI/Controls/Slider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ protected override Vector3 MeasureOverride(Vector3 availableSizeWithoutMargins)
var idealSize = trackBackgroundSprite.SizeInPixels.Y;
var desiredSize = new Vector3(idealSize, idealSize, 0)
{
[(int)Orientation] = availableSizeWithoutMargins[(int)Orientation]
[(int)Orientation] = float.IsInfinity(availableSizeWithoutMargins[(int)Orientation]) ? float.MaxValue : availableSizeWithoutMargins[(int)Orientation]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry I can't accept this change as is, this is a workaround, you're using MaxValue here because it doesn't cause an issue, not because it makes sense with the rest of the logic.
availableSizeWithoutMargins is positive infinity here I'm guessing, if that's the case you should fix this higher up the call stack. Measure() could be used to replace infinities with the actual maximum size the element can take inside the container it is in for example

Copy link
Contributor Author

@TranquilAbyss TranquilAbyss Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put a Slider into a Canvas.
In Measure we use the Canvas OverrideMeasure to

// compute the desired size for the children
var childrenDesiredSize = MeasureOverride(availableSizeWithoutMargins);

This is what happens in Canvas OverrideMeasure
image
Due to this this section of the code
image

It is the Canvas MeasureOverride that calls the Slider's Messure. With the following value
image

How can I use the Canvas's Measure size value when its still trying to calculate the measure of the children (Slider) to be use to get the parents initial measurement? Kind of a what comes first problem (Chicken or Egg)?

In regards to using containers (Canvas?) actual maximum size I am not sure where to get that either within the Canvas MeasureOverride or the Child.Measure? This a first frame kind of problem.

My guess was Canvas was suppose to provide infinity size so handle it within the Slider, since a Slider is the only UI Element with the issue.

};

return desiredSize;
Expand Down