Get rid of unnecessary wxColour::InitFromComponents() in wxOSX

This method was confusing and dangerous as it didn't actually initialize the
wxColour object because it didn't set its m_cgColour and so attempting to use
wxColour "initialized" using this method resulted in a crash whenever its
GetPixel(), GetCGColor() or CreateCGColor() methods were called.

Just merge this function with InitCGColorRef() which is the only remaining
place where it's used after rewriting wxColour(NSColor) ctor.
This commit is contained in:
Vadim Zeitlin 2015-11-27 00:19:37 +01:00
parent 10162b79fc
commit 9990959c99
2 changed files with 4 additions and 8 deletions

View File

@ -72,7 +72,7 @@ protected :
void InitRGBColor( const RGBColor& col );
#endif
void InitCGColorRef( CGColorRef col );
void InitFromComponents(const CGFloat* components, size_t numComponents );
private:
wxCFRef<CGColorRef> m_cgColour;

View File

@ -107,24 +107,20 @@ void wxColour::InitCGColorRef( CGColorRef col )
m_alpha = wxALPHA_OPAQUE;
components = CGColorGetComponents( col );
}
InitFromComponents(components, noComp);
}
void wxColour::InitFromComponents(const CGFloat* components, size_t numComponents )
{
if ( numComponents < 1 || !components )
if ( noComp < 1 || !components )
{
m_alpha = wxALPHA_OPAQUE;
m_red = m_green = m_blue = 0;
return;
}
if ( numComponents >= 3 )
if ( noComp >= 3 )
{
m_red = (int)(components[0]*255+0.5);
m_green = (int)(components[1]*255+0.5);
m_blue = (int)(components[2]*255+0.5);
if ( numComponents == 4 )
if ( noComp == 4 )
m_alpha = (int)(components[3]*255+0.5);
}
else