-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix SolidColorBrush.Equals to compare Color values instead of references #32956
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
Conversation
Fixes #27281 The issue was that SolidColorBrush.Equals used '==' to compare Color objects, which compares references instead of values. This caused infinite loops when using DynamicResource with OnPlatform<Color> because OnPlatform creates new Color instances each time, and the equality check would always return false even for identical color values. Changed to use Equals() which properly compares Color values via Color.Equals().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes an infinite loop issue (#27281) in SolidColorBrush.Equals by changing from reference comparison (==) to value comparison (Equals()) for Color objects. The problem occurred when DynamicResource was used with OnPlatform<Color>, which creates new Color instances each time, causing the reference comparison to always fail even for identical color values.
Key Changes
- Fixed
SolidColorBrush.Equalsto compare Color values instead of references - Added comprehensive unit test to prevent regression
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Controls/src/Core/SolidColorBrush.cs | Changed Color comparison from == to Equals(Color, dest.Color) for proper value comparison |
| src/Controls/tests/Core.UnitTests/SolidColorBrushTests.cs | Added test SolidColorBrushEqualsComparesColorValues to verify Colors with identical RGBA values are considered equal even with different object references |
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [Microsoft.Maui.Controls](https://github.com/dotnet/maui) | nuget | patch | `10.0.11` -> `10.0.20` | --- ### Release Notes <details> <summary>dotnet/maui (Microsoft.Maui.Controls)</summary> ### [`v10.0.20`](https://github.com/dotnet/maui/releases/tag/10.0.20): SR2 [Compare Source](dotnet/maui@10.0.11...10.0.20) ##### What's Changed **Note:** This is a service release (SR2) tracking ongoing release/10.0.1xx-sr2 branch development. The version number 10.0.20 represents the second service release for .NET MAUI 10. .NET MAUI 10.0.20 development introduces significant improvements across all platforms with focus on quality, performance, and developer experience. Current development includes enhancements to XAML Source Generator, iOS/macOS fixes, AppThemeBinding improvements, and improved developer tooling. ##### AI - PR Reviewer Agent by [@​PureWeen](https://github.com/PureWeen) in dotnet/maui#32340 - \[AI] The Issue-Resolver agent by [@​kubaflo](https://github.com/kubaflo) in dotnet/maui#32804 - \[AI] Fixed links for agents by [@​kubaflo](https://github.com/kubaflo) in dotnet/maui#32818 - Add checkpoint/resume system for PR review agent by [@​kubaflo](https://github.com/kubaflo) in dotnet/maui#32774 - Improved pr-reviewer AI agent and modified the usage instructions in README by [@​kubaflo](https://github.com/kubaflo) in dotnet/maui#32718 - Agents scripts by [@​PureWeen](https://github.com/PureWeen) in dotnet/maui#32819 - Simplify agent instructions and consolidate sandbox testing workflow by [@​Copilot](https://github.com/Copilot) in dotnet/maui#32950 ##### Brushes - Fix SolidColorBrush.Equals to compare Color values instead of references by [@​StephaneDelcroix](https://github.com/StephaneDelcroix) in dotnet/maui#32956 <details> <summary>🔧 Fixes</summary> - [Using DynamicResource with OnPlatform<Color> causes infinite loop](dotnet/maui#27281) </details> ##### Data Binding - Fix CS8603 error for nullable reference types in SourceGen binding paths by [@​Copilot](https://github.com/Copilot) in dotnet/maui#32480 <details> <summary>🔧 Fixes</summary> - [error CS8603: Possible null reference return in generated code using SourceGen](dotnet/maui#32478) </details> ##### Docs - Add README-AI.md file by [@​PureWeen](https://github.com/PureWeen) in dotnet/maui#32502 - Improve AI agent documentation and testing instructions by [@​Copilot](https://github.com/Copilot) in https://github.com/dotnet/maui/p...
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Description
Fixes #27281
The issue was that
SolidColorBrush.Equalsused==to compareColorobjects, which compares references instead of values. This caused infinite loops when usingDynamicResourcewithOnPlatform<Color>becauseOnPlatformcreates newColorinstances each time, and the equality check would always return false even for identical color values.Changes
SolidColorBrush.Equalsto useEquals(Color, dest.Color)instead ofColor == dest.ColorSolidColorBrushEqualsComparesColorValuesto verify the fixRoot Cause
Coloris a class, andOnPlatform<Color>creates a newColorinstance each time it is evaluated. WhenSolidColorBrush.Equalscompared colors using==, it was doing reference comparison instead of value comparison. This causedVisualElement.OnParentResourcesChangedto detect a "change" every time (even when the color values were identical), leading to an infinite loop.Fix
Use
Equals()which delegates toColor.Equals(), which compares colors by their RGBA values (viaToInt()).