From 9990959c9921aa0e2e68d378c9e734043b56a471 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 27 Nov 2015 00:19:37 +0100 Subject: [PATCH] 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. --- include/wx/osx/core/colour.h | 2 +- src/osx/core/colour.cpp | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/include/wx/osx/core/colour.h b/include/wx/osx/core/colour.h index 679bb9d667..ff41bcb5dd 100644 --- a/include/wx/osx/core/colour.h +++ b/include/wx/osx/core/colour.h @@ -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 m_cgColour; diff --git a/src/osx/core/colour.cpp b/src/osx/core/colour.cpp index 7de9084fdc..2fbb616e0d 100644 --- a/src/osx/core/colour.cpp +++ b/src/osx/core/colour.cpp @@ -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