-
Notifications
You must be signed in to change notification settings - Fork 810
Description
Current behavior π
Visual.skia.cs
file: When running in Debug builds we have a Debug.Assert that compares canvas.TotalMatrix to an expected SKMatrix. The code uses exact equality (==) on SKMatrix instances and causes intermittent assertion failures when rootTransform is present. The values differ by tiny floating-point rounding errors (e.g. due to matrix multiplications), so the assertion fails even though the matrices are effectively equal for rendering purposes.
Code location: https://github.com/unoplatform/uno/blob/master/src/Uno.UI.Composition/Composition/Visual.skia.cs#L612
Expected behavior π―
The Debug.Assert should compare matrices with a small epsilon tolerance (an element-wise "almost equal") rather than strict equality, to avoid flaky assertion failures caused by floating-point rounding.
How to reproduce it (as minimally and precisely as possible) π¬
The assertion triggers when rootTransform is defined and TotalMatrix has been multiplied with it (TotalMatrix * rootTransform); small rounding differences across platforms or calculation order make the exact-equality check fail.
Workaround π οΈ
The workaround right now is to comment the Debug.Assert()
line to prevent application from crashing.
Proposed fix
Use an element-wise approximate comparison (with a configurable epsilon) instead of ==
. Do this in the Debug.Assert (or compute the matrices beforehand and assert using a helper method). Also avoid expensive matrix conversions inside asserts by computing expected/actual once and reusing them.
The epsilon value can be tuned; around 1e-4 is typical for SKMatrix single-precision comparisons. You should use the CompositionMathHelpers.IsCloseReal()
to check the values.
Renderer π¨
- Skia
- Native
Affected platforms π±π»π₯οΈ
Desktop (Windows)
Uno.Sdk version (and other relevant versions) π¦
No response
IDE version π§βπ»
No response
Anything else we need to know? π¬
No response