-
Notifications
You must be signed in to change notification settings - Fork 110
Fix for alpha value out of range #18
Fix for alpha value out of range #18
Conversation
Do you have a specific scenario where alpha in this methods is outside the 0..1 range? |
Not really. These pull requests come from 8 years of experience and testing with Substance+Flamingo 😄 I've seen this error and fixed it. This guy also made a lot of fixes including this one: |
The first fix doesn't seem to be right. It should be Math.min there. As for doing it defensively, my strong preference is to do that only when it's actually shown to happen. Otherwise you're treating the symptom and not the core - which would be somewhere in Trident. And you can go really far with treating the symptoms, wrapping every method call to catch every kind of exception :) |
I must say I was using I saw you followed a similar approach on |
That code in LafWidgetUtilities is indeed there. It's been a while, so I can't really say why it's there. Having said that, what do you mean by "any other error"? Does this mean that you are seeing alpha values outside the 0..1 range without this fix in SubstanceImageCreator? If not, then I won't be making this change. |
What I meant is that without the fix I was having the "alpha value out of range" exception (sporadically), but after controlling the alpha range (by overriding your class in my project) I didn't have any other error regarding the alpha. |
Is that under the latest 7.0? |
No, this comes from a previous version, I just found out about Substance back in the game today 👍 Here is another user with the same issue: Insubstantial#138
|
As I stated on Insubstantial bug 138, I saw this bug a few times, and I fixed it in my fork by adding a check to make sure the value was between 0.0 and 1.0. I never had a reliable way to trigger the bug, and I have never seen the problem again since my fix. |
I must say that I didn't really like putting in that fix without understanding why it was happening, but since I couldn't reproduce it reliably and don't understand the code sufficiently, I didn't see any other option. |
In theory even with floating arithmetic imprecisions you should never end up with a product of positive numbers being less than zero, and with a product of <= 1 numbers being more than one. For this one I'm taking a more pragmatic stance and doing range clamp. This is the same as in the above-mentioned alpha composite method, as well as in the color interpolation code in SubstanceColorUtilities (used to be direct linear interpolation of each color channel, and is now using gamma space). |
"In theory ..." I wonder whether the bugs could be related to threading. Maybe non-atomic operations are happening with them on Swing and non-Swing threads. But, whatever, I'm happy with the pragmatic "clamp" approach which has worked well for me for several years. |
No description provided.