mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Fix unlikely cases of skin blood color being wrong
The check before calling `normalize` incorrectly excludes skins containing zero in any color component instead of excluding only skins with zero in all components. The check can be removed entirely, because it is already checked inside the `normalize` function whether the length of the `vec3` is zero, in which case a zero `vec3` will be returned. For very large skins which use large color values in at least one component, the `int` used for calculating the blood color could overflow.
This commit is contained in:
parent
4eb0ffd701
commit
8adfb2f2ec
|
@ -207,8 +207,9 @@ const CSkin *CSkins::LoadSkin(const char *pName, CImageInfo &Info)
|
|||
|
||||
// dig out blood color
|
||||
{
|
||||
int aColors[3] = {0};
|
||||
int64_t aColors[3] = {0};
|
||||
for(int y = 0; y < BodyHeight; y++)
|
||||
{
|
||||
for(int x = 0; x < BodyWidth; x++)
|
||||
{
|
||||
uint8_t AlphaValue = pData[y * Pitch + x * PixelStep + 3];
|
||||
|
@ -219,10 +220,9 @@ const CSkin *CSkins::LoadSkin(const char *pName, CImageInfo &Info)
|
|||
aColors[2] += pData[y * Pitch + x * PixelStep + 2];
|
||||
}
|
||||
}
|
||||
if(aColors[0] != 0 && aColors[1] != 0 && aColors[2] != 0)
|
||||
Skin.m_BloodColor = ColorRGBA(normalize(vec3(aColors[0], aColors[1], aColors[2])));
|
||||
else
|
||||
Skin.m_BloodColor = ColorRGBA(0, 0, 0, 1);
|
||||
}
|
||||
|
||||
Skin.m_BloodColor = ColorRGBA(normalize(vec3(aColors[0], aColors[1], aColors[2])));
|
||||
}
|
||||
|
||||
CheckMetrics(Skin.m_Metrics.m_Body, pData, Pitch, 0, 0, BodyWidth, BodyHeight);
|
||||
|
|
Loading…
Reference in a new issue