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 color validation by avoiding null vectors between identical colors & running all checks concurrently #17272

Merged
merged 3 commits into from
Feb 22, 2020

Conversation

robpvn
Copy link
Contributor

@robpvn robpvn commented Oct 24, 2019

This is a fix for issue #16837 , which also has some (possibly) unintended consequences worth discussing.

If the picked color and a forbidden color are identical (like if they both picked the same palette color and in the special case when a picked color is outside of the allowed range and the method
returns the picked color as the forbidden color), the vector between them is zero and the maths for adjusting the color fails by hitting the iteration limit. This changes the zero vector to the smallest possible vector in order to avoid the issue.

I also added an extra message if you hit the iteration failsafe that picks a random colour.

However, this can result in some seriously close adjustments in the case of picking identical palette colors, which might be undesirable compared to picking a new palette color. (See picture of adjusted identical palette picks below.) While technically the current behaviour of picking a random new palette color is a bug, I have a feeling many people might see it as a feature. Comments?

@robpvn
Copy link
Contributor Author

robpvn commented Oct 24, 2019

Woops, this actually only fixes the first part of issue #16837, where the range adjustment didn't get done. The second part, where the two checks aren't run concurrently, isn't fixed yet.

@robpvn
Copy link
Contributor Author

robpvn commented Oct 24, 2019

Now I've made a fix for the whole issue #16837, which ensures that all checks are made at the same time.

@robpvn robpvn changed the title Fix color validation by avoiding null vectors between identical colors Fix color validation by avoiding null vectors between identical colors & running all checks concurrently Oct 24, 2019
@abcdefg30
Copy link
Member

Sorry for looking at this only so late. The code changes look good to me on a first glance.

I'd agree that picking a random new colour is worse than just adjusting the colour slightly, so the behaviour in this PR should be fine.

One other thing I noticed: You should remove the allForbidden variable now that it is unused.

@robpvn
Copy link
Contributor Author

robpvn commented Jan 6, 2020

@abcdefg30 Don't worry about responding late, it turns out I'm slow to respond as well! :D

I deleted the unused variable and rebased the commits to the newest bleed.

abcdefg30
abcdefg30 previously approved these changes Jan 13, 2020
Copy link
Member

@abcdefg30 abcdefg30 left a comment

Choose a reason for hiding this comment

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

Code changes look good to me and I didn't spot any regressions.

@abcdefg30
Copy link
Member

I opened #17582 so we don't forget about it once this PR is merged.

OpenRA.Mods.Common/ColorValidator.cs Outdated Show resolved Hide resolved
OpenRA.Mods.Common/ColorValidator.cs Outdated Show resolved Hide resolved
OpenRA.Mods.Common/ColorValidator.cs Outdated Show resolved Hide resolved
@pchote
Copy link
Member

pchote commented Feb 16, 2020

LGTM otherwise, and it makes sense to get this in for the playtest so adding to the milestone.

Given the time constraints on the playtest release, I'll apply the fixups and merge this next weekend if not fixed sooner.

@pchote pchote added this to the Next Release milestone Feb 16, 2020
The failsafe in ColorValidator aborts after 255 iterations of
adjusting the color and picks a random color. This message makes it
clearer to the user. Results in two messages being displayed,
first one about adjusting and the about a random color pick.
If the picked color and a forbidden color are identical (like
if they both picked the same palette color and in the special case
when a picked color is outside of the allowed range and the method
returns the picked color as the forbidden color),
the vector between them is zero and the maths for adjusting
the color fails by hitting the iteration limit. This changes
the zero vector to the smallest possible vector in order to
avoid the issue.

This can result in some seriously close adjustments in the case of
picking identical palette colors, which might
be undesirable compared to picking a new palette color.
This ensures that color picks that have multiple issues will
have them all checked at the same time, including ensuring that
the fix for one issue doesn't cause another issue.

Handling of the onError action has been changed from being called
at once to collecting the potential errors in a HashSet to deduplicate
them and then calling onError after a valid color has been found.
(Otherwise you would in the worst case get 256 error messages logged!)
Copy link
Member

@pchote pchote left a comment

Choose a reason for hiding this comment

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

Pushed fixups, LGTM now 👍

@pchote pchote merged commit 885931a into OpenRA:bleed Feb 22, 2020
@robpvn
Copy link
Contributor Author

robpvn commented Feb 24, 2020

Sorry about not responding promptly, I was laid up with the flu last week. Thanks for the merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants