← Back to team overview

kicad-developers team mailing list archive

Re: [Patch] Fix initialization order for COLOR4D statics

 

Forgot that I split the updating the widget into a separate commit. Here is
an updated patch that just fixes the initialization (I updated the message).

-Ian

On Mon, Aug 5, 2019 at 10:58 AM Ian McInerney <Ian.S.McInerney@xxxxxxxx>
wrote:

> I decided to instrument my debug build with the address sanitizer and see
> what happened, and it has pointed out an initialization order fiasco in the
> loading of pcbnew.
>
> I tracked it down to the fact that COLOR4D has some static colors that
> were being used to initialize some other static variables in pcbnew's layer
> widgets. I have moved all the static colors to an initialize on first use
> paradigm (so now we just call them like a function, e.g.
> COLOR4D::UNSPECIFIED() ) to fix it.
>
> Also, this patch cleans up the layer toolbar button creation by moving all
> the statics into a member struct (this was done by Jeff as the fix in 5.1).
>
> -Ian
>
From 6f369328b3e4c3a66117a08d4e10736bfb081268 Mon Sep 17 00:00:00 2001
From: Ian McInerney <Ian.S.McInerney@xxxxxxxx>
Date: Mon, 5 Aug 2019 10:51:29 +0200
Subject: [PATCH] Fix initialization of COLOR4D statics

The previous implementation would give an initialization order
fiasco since they were being used to initialize other statics.
This moves them to an initialize on first use paradigm.
---
 .../3d_canvas/create_3Dgraphic_brd_items.cpp  |  2 +-
 common/board_printout.cpp                     |  4 ++--
 common/colors_design_settings.cpp             |  4 ++--
 common/eda_draw_frame.cpp                     |  2 +-
 common/eda_text.cpp                           |  2 +-
 common/gal/cairo/cairo_gal.cpp                |  2 +-
 common/gal/color4d.cpp                        |  6 +----
 common/gal/opengl/antialiasing.cpp            | 10 ++++----
 common/gal/opengl/opengl_compositor.cpp       |  2 +-
 common/gal/opengl/opengl_gal.cpp              |  2 +-
 common/gr_basic.cpp                           |  8 +++----
 common/plotters/DXF_plotter.cpp               | 10 +++-----
 common/plotters/PS_plotter.cpp                |  2 +-
 common/plotters/common_plot_functions.cpp     |  4 ++--
 common/widgets/color_swatch.cpp               |  4 ++--
 common/widgets/layer_box_selector.cpp         |  2 +-
 eeschema/dialogs/dialog_edit_line_style.cpp   |  6 ++---
 .../dialogs/dialog_print_using_printer.cpp    |  4 ++--
 eeschema/eeschema.cpp                         |  6 ++---
 eeschema/lib_text.cpp                         |  2 +-
 eeschema/sch_line.cpp                         | 16 ++++++-------
 eeschema/sch_sheet.cpp                        |  2 +-
 .../widgets/widget_eeschema_color_config.cpp  |  6 ++---
 gerbview/gbr_display_options.h                |  2 +-
 gerbview/gerbview_frame.cpp                   |  2 +-
 gerbview/gerbview_layer_widget.cpp            |  2 +-
 gerbview/gerbview_painter.cpp                 |  2 +-
 include/eda_draw_frame.h                      |  2 +-
 include/gal/color4d.h                         | 24 +++++++++++++++----
 include/msgpanel.h                            |  2 +-
 include/plotter.h                             |  4 ++--
 ...board_items_to_polygon_shape_transform.cpp |  2 +-
 pcbnew/dialogs/dialog_pad_properties.cpp      |  2 +-
 pcbnew/exporters/export_vrml.cpp              |  2 +-
 pcbnew/exporters/gen_drill_report_files.cpp   |  4 ++--
 pcbnew/layer_widget.cpp                       |  6 ++---
 pcbnew/layer_widget.h                         | 11 +++++----
 pcbnew/pad_print_functions.cpp                |  6 ++---
 pcbnew/pcb_layer_widget.cpp                   |  4 ++--
 pcbnew/pcbnew_printout.cpp                    |  6 ++---
 pcbnew/plot_board_layers.cpp                  |  8 ++++---
 pcbnew/plot_brditems_plotter.cpp              |  4 ++--
 pcbnew/toolbars_pcb_editor.cpp                | 10 ++++----
 pcbnew/tools/zone_create_helper.cpp           |  2 +-
 qa/eeschema/mocks_eeschema.cpp                |  4 ++--
 .../test_gal_pixel_alignment.cpp              |  2 +-
 46 files changed, 116 insertions(+), 105 deletions(-)

diff --git a/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp b/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp
index 737297ef0..c3faeb9b2 100644
--- a/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp
+++ b/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp
@@ -106,7 +106,7 @@ void CINFO3D_VISU::AddShapeWithClearanceToContainer( const TEXTE_PCB* aText,
     s_boardBBox3DU = &m_board2dBBox3DU;
 
     // not actually used, but needed by GRText
-    const COLOR4D dummy_color = COLOR4D::BLACK;
+    const COLOR4D dummy_color = COLOR4D::BLACK();
 
     if( aText->IsMultilineAllowed() )
     {
diff --git a/common/board_printout.cpp b/common/board_printout.cpp
index dfc7e9725..7ab909090 100644
--- a/common/board_printout.cpp
+++ b/common/board_printout.cpp
@@ -114,7 +114,7 @@ void BOARD_PRINTOUT::DrawPage( const wxString& aLayerName, int aPageNum, int aPa
     if( m_settings.m_blackWhite )
     {
         for( int i = 0; i < LAYER_ID_COUNT; ++i )
-            dstSettings->SetLayerColor( i, COLOR4D::BLACK );
+            dstSettings->SetLayerColor( i, COLOR4D::BLACK() );
     }
     else // color enabled
     {
@@ -196,7 +196,7 @@ void BOARD_PRINTOUT::setupViewLayers( const std::unique_ptr<KIGFX::VIEW>& aView,
 
 void BOARD_PRINTOUT::setupPainter( const std::unique_ptr<KIGFX::PAINTER>& aPainter )
 {
-    aPainter->GetSettings()->SetBackgroundColor( COLOR4D::WHITE );
+    aPainter->GetSettings()->SetBackgroundColor( COLOR4D::WHITE() );
 }
 
 
diff --git a/common/colors_design_settings.cpp b/common/colors_design_settings.cpp
index 67c764890..fac44ac0d 100644
--- a/common/colors_design_settings.cpp
+++ b/common/colors_design_settings.cpp
@@ -127,7 +127,7 @@ COLOR4D COLORS_DESIGN_SETTINGS::GetLayerColor( LAYER_NUM aLayer ) const
     if( (unsigned) aLayer < arrayDim( m_LayersColors ) )
         return m_LayersColors[aLayer];
 
-    return COLOR4D::UNSPECIFIED;
+    return COLOR4D::UNSPECIFIED();
 }
 
 
@@ -143,7 +143,7 @@ COLOR4D COLORS_DESIGN_SETTINGS::GetItemColor( int aItemIdx ) const
     if( (unsigned) aItemIdx < arrayDim( m_LayersColors ) )
         return m_LayersColors[aItemIdx];
 
-    return COLOR4D::UNSPECIFIED;
+    return COLOR4D::UNSPECIFIED();
 }
 
 
diff --git a/common/eda_draw_frame.cpp b/common/eda_draw_frame.cpp
index 187e720b3..41293fdfe 100644
--- a/common/eda_draw_frame.cpp
+++ b/common/eda_draw_frame.cpp
@@ -784,7 +784,7 @@ void EDA_DRAW_FRAME::PrintWorkSheet( wxDC* aDC, BASE_SCREEN* aScreen, int aLineW
     if( !m_showBorderAndTitleBlock )
         return;
 
-    COLOR4D color = ( aColor != COLOR4D::UNSPECIFIED ) ? aColor : COLOR4D( RED );
+    COLOR4D color = ( aColor != COLOR4D::UNSPECIFIED() ) ? aColor : COLOR4D( RED );
 
     wxPoint origin = aDC->GetDeviceOrigin();
 
diff --git a/common/eda_text.cpp b/common/eda_text.cpp
index fe5138a12..b7160261c 100644
--- a/common/eda_text.cpp
+++ b/common/eda_text.cpp
@@ -542,7 +542,7 @@ void EDA_TEXT::TransformTextShapeToSegmentList( std::vector<wxPoint>& aCornerBuf
     if( IsMirrored() )
         size.x = -size.x;
 
-    COLOR4D color = COLOR4D::BLACK;  // not actually used, but needed by GRText
+    COLOR4D color = COLOR4D::BLACK(); // not actually used, but needed by GRText
 
     if( IsMultilineAllowed() )
     {
diff --git a/common/gal/cairo/cairo_gal.cpp b/common/gal/cairo/cairo_gal.cpp
index 05b01e22a..cb9e42eff 100644
--- a/common/gal/cairo/cairo_gal.cpp
+++ b/common/gal/cairo/cairo_gal.cpp
@@ -1408,7 +1408,7 @@ void CAIRO_GAL::ClearTarget( RENDER_TARGET aTarget )
         break;
     }
 
-    compositor->ClearBuffer( COLOR4D::BLACK );
+    compositor->ClearBuffer( COLOR4D::BLACK() );
 
     // Restore the previous state
     compositor->SetBuffer( currentBuffer );
diff --git a/common/gal/color4d.cpp b/common/gal/color4d.cpp
index bc71f45bc..175a0a6f8 100644
--- a/common/gal/color4d.cpp
+++ b/common/gal/color4d.cpp
@@ -33,7 +33,7 @@ COLOR4D::COLOR4D( EDA_COLOR_T aColor )
 {
     if( aColor <= UNSPECIFIED_COLOR || aColor >= NBCOLORS )
     {
-        *this = COLOR4D::UNSPECIFIED;
+        *this = COLOR4D::UNSPECIFIED();
         return;
     }
 
@@ -361,7 +361,3 @@ COLOR4D& COLOR4D::Saturate( double aFactor )
 
     return *this;
 }
-
-const COLOR4D COLOR4D::UNSPECIFIED( 0, 0, 0, 0 );
-const COLOR4D COLOR4D::WHITE( 1, 1, 1, 1 );
-const COLOR4D COLOR4D::BLACK( 0, 0, 0, 1 );
diff --git a/common/gal/opengl/antialiasing.cpp b/common/gal/opengl/antialiasing.cpp
index 276b4d064..7fb1ebadb 100644
--- a/common/gal/opengl/antialiasing.cpp
+++ b/common/gal/opengl/antialiasing.cpp
@@ -182,7 +182,7 @@ VECTOR2U ANTIALIASING_SUPERSAMPLING::GetInternalBufferSize()
 void ANTIALIASING_SUPERSAMPLING::Begin()
 {
     compositor->SetBuffer( ssaaMainBuffer );
-    compositor->ClearBuffer( COLOR4D::BLACK );
+    compositor->ClearBuffer( COLOR4D::BLACK() );
 }
 
 
@@ -446,7 +446,7 @@ void ANTIALIASING_SMAA::DrawBuffer( GLuint buffer )
 void ANTIALIASING_SMAA::Begin()
 {
     compositor->SetBuffer( smaaBaseBuffer );
-    compositor->ClearBuffer( COLOR4D::BLACK );
+    compositor->ClearBuffer( COLOR4D::BLACK() );
 }
 
 
@@ -488,7 +488,7 @@ void ANTIALIASING_SMAA::Present()
     // pass 1: main-buffer -> smaaEdgesBuffer
     //
     compositor->SetBuffer( smaaEdgesBuffer );
-    compositor->ClearBuffer( COLOR4D::BLACK );
+    compositor->ClearBuffer( COLOR4D::BLACK() );
 
     glActiveTexture( GL_TEXTURE0 );
     glBindTexture( GL_TEXTURE_2D, sourceTexture );                                             checkGlError( "binding colorTex" );
@@ -500,7 +500,7 @@ void ANTIALIASING_SMAA::Present()
     // pass 2: smaaEdgesBuffer -> smaaBlendBuffer
     //
     compositor->SetBuffer( smaaBlendBuffer );
-    compositor->ClearBuffer( COLOR4D::BLACK );
+    compositor->ClearBuffer( COLOR4D::BLACK() );
 
     auto edgesTex = compositor->GetBufferTexture( smaaEdgesBuffer );
 
@@ -519,7 +519,7 @@ void ANTIALIASING_SMAA::Present()
     // pass 3: colorTex + BlendBuffer -> output
     //
     compositor->SetBuffer( OPENGL_COMPOSITOR::DIRECT_RENDERING );
-    compositor->ClearBuffer( COLOR4D::BLACK );
+    compositor->ClearBuffer( COLOR4D::BLACK() );
     auto blendTex = compositor->GetBufferTexture( smaaBlendBuffer );
 
     glActiveTexture( GL_TEXTURE0 );
diff --git a/common/gal/opengl/opengl_compositor.cpp b/common/gal/opengl/opengl_compositor.cpp
index 6fae6014f..5fb50a803 100644
--- a/common/gal/opengl/opengl_compositor.cpp
+++ b/common/gal/opengl/opengl_compositor.cpp
@@ -247,7 +247,7 @@ unsigned int OPENGL_COMPOSITOR::CreateBuffer( VECTOR2U aDimensions )
         return 0;
     }
 
-    ClearBuffer( COLOR4D::BLACK );
+    ClearBuffer( COLOR4D::BLACK() );
 
     // Return to direct rendering (we were asked only to create a buffer, not switch to one)
     bindFb( DIRECT_RENDERING );
diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp
index c96200cac..93842a61c 100644
--- a/common/gal/opengl/opengl_gal.cpp
+++ b/common/gal/opengl/opengl_gal.cpp
@@ -1589,7 +1589,7 @@ void OPENGL_GAL::ClearTarget( RENDER_TARGET aTarget )
     if( aTarget != TARGET_OVERLAY )
         compositor->ClearBuffer( m_clearColor );
     else
-        compositor->ClearBuffer( COLOR4D::BLACK );
+        compositor->ClearBuffer( COLOR4D::BLACK() );
 
     // Restore the previous state
     compositor->SetBuffer( oldTarget );
diff --git a/common/gr_basic.cpp b/common/gr_basic.cpp
index 6d4125128..215ba8792 100644
--- a/common/gr_basic.cpp
+++ b/common/gr_basic.cpp
@@ -120,8 +120,8 @@ static void WinClipAndDrawLine( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int
 void GRResetPenAndBrush( wxDC* DC )
 {
     GRSetBrush( DC, BLACK );  // Force no fill
-    s_DC_lastbrushcolor = COLOR4D::UNSPECIFIED;
-    s_DC_lastcolor =  COLOR4D::UNSPECIFIED;
+    s_DC_lastbrushcolor = COLOR4D::UNSPECIFIED();
+    s_DC_lastcolor = COLOR4D::UNSPECIFIED();
     s_DC_lastDC    = NULL;
 }
 
@@ -139,7 +139,7 @@ void GRSetColorPen( wxDC* DC, COLOR4D Color, int width, wxPenStyle style )
         width = DC->DeviceToLogicalXRel( 1 );
 
     if( s_ForceBlackPen )
-        Color = COLOR4D::BLACK;
+        Color = COLOR4D::BLACK();
 
     const wxPen& curr_pen = DC->GetPen();
 
@@ -170,7 +170,7 @@ void GRSetColorPen( wxDC* DC, COLOR4D Color, int width, wxPenStyle style )
 void GRSetBrush( wxDC* DC, COLOR4D Color, bool fill )
 {
     if( s_ForceBlackPen )
-        Color = COLOR4D::BLACK;
+        Color = COLOR4D::BLACK();
 
     if(   s_DC_lastbrushcolor != Color
        || s_DC_lastbrushfill  != fill
diff --git a/common/plotters/DXF_plotter.cpp b/common/plotters/DXF_plotter.cpp
index ffb31122e..26174dc6c 100644
--- a/common/plotters/DXF_plotter.cpp
+++ b/common/plotters/DXF_plotter.cpp
@@ -167,7 +167,7 @@ void DXF_PLOTTER::SetViewport( const wxPoint& aOffset, double aIusPerDecimil,
 
     SetDefaultLineWidth( 0 );               // No line width on DXF
     m_plotMirror = false;                   // No mirroring on DXF
-    m_currentColor = COLOR4D::BLACK;
+    m_currentColor = COLOR4D::BLACK();
 }
 
 /**
@@ -405,14 +405,10 @@ bool DXF_PLOTTER::EndPlot()
  */
 void DXF_PLOTTER::SetColor( COLOR4D color )
 {
-    if( ( colorMode )
-       || ( color == COLOR4D::BLACK )
-       || ( color == COLOR4D::WHITE ) )
-    {
+    if( ( colorMode ) || ( color == COLOR4D::BLACK() ) || ( color == COLOR4D::WHITE() ) )
         m_currentColor = color;
-    }
     else
-        m_currentColor = COLOR4D::BLACK;
+        m_currentColor = COLOR4D::BLACK();
 }
 
 /**
diff --git a/common/plotters/PS_plotter.cpp b/common/plotters/PS_plotter.cpp
index 52353577a..4392f8e62 100644
--- a/common/plotters/PS_plotter.cpp
+++ b/common/plotters/PS_plotter.cpp
@@ -72,7 +72,7 @@ void PSLIKE_PLOTTER::SetColor( COLOR4D color )
          * holes in white on pads in black
          */
         double k = 1; // White
-        if( color != COLOR4D::WHITE )
+        if( color != COLOR4D::WHITE() )
             k = 0;
         if( negativeMode )
             emitSetRGBColor( 1 - k, 1 - k, 1 - k );
diff --git a/common/plotters/common_plot_functions.cpp b/common/plotters/common_plot_functions.cpp
index 14b984f28..5663cb369 100644
--- a/common/plotters/common_plot_functions.cpp
+++ b/common/plotters/common_plot_functions.cpp
@@ -59,9 +59,9 @@ void PlotWorkSheet( PLOTTER* plotter, const TITLE_BLOCK& aTitleBlock,
      */
     double   iusPerMil = plotter->GetIUsPerDecimil() * 10.0;
 
-    COLOR4D plotColor = plotter->GetColorMode() ? aColor : COLOR4D::BLACK;
+    COLOR4D plotColor = plotter->GetColorMode() ? aColor : COLOR4D::BLACK();
 
-    if( plotColor == COLOR4D::UNSPECIFIED )
+    if( plotColor == COLOR4D::UNSPECIFIED() )
         plotColor = COLOR4D( RED );
 
     plotter->SetColor( plotColor );
diff --git a/common/widgets/color_swatch.cpp b/common/widgets/color_swatch.cpp
index 4d719a697..dbc0f75d9 100644
--- a/common/widgets/color_swatch.cpp
+++ b/common/widgets/color_swatch.cpp
@@ -155,14 +155,14 @@ COLOR4D COLOR_SWATCH::GetSwatchColor() const
 
 void COLOR_SWATCH::GetNewSwatchColor()
 {
-    COLOR4D newColor = COLOR4D::UNSPECIFIED;
+    COLOR4D newColor = COLOR4D::UNSPECIFIED();
 
     DIALOG_COLOR_PICKER dialog( ::wxGetTopLevelParent( this ), m_color, true );
 
     if( dialog.ShowModal() == wxID_OK )
         newColor = dialog.GetColor();
 
-    if( newColor != COLOR4D::UNSPECIFIED )
+    if( newColor != COLOR4D::UNSPECIFIED() )
     {
         m_color = newColor;
 
diff --git a/common/widgets/layer_box_selector.cpp b/common/widgets/layer_box_selector.cpp
index cc7b46fc4..0cda48a84 100644
--- a/common/widgets/layer_box_selector.cpp
+++ b/common/widgets/layer_box_selector.cpp
@@ -53,7 +53,7 @@ void LAYER_SELECTOR::DrawColorSwatch( wxBitmap& aLayerbmp, COLOR4D aBackground,
     bmpDC.SelectObject( aLayerbmp );
 
     brush.SetStyle( wxBRUSHSTYLE_SOLID );
-    if( aBackground != COLOR4D::UNSPECIFIED )
+    if( aBackground != COLOR4D::UNSPECIFIED() )
     {
         brush.SetColour( aBackground.WithAlpha(1.0).ToColour() );
         bmpDC.SetBrush( brush );
diff --git a/eeschema/dialogs/dialog_edit_line_style.cpp b/eeschema/dialogs/dialog_edit_line_style.cpp
index efd955698..c0efc23dd 100644
--- a/eeschema/dialogs/dialog_edit_line_style.cpp
+++ b/eeschema/dialogs/dialog_edit_line_style.cpp
@@ -64,13 +64,13 @@ bool DIALOG_EDIT_LINE_STYLE::TransferDataToWindow()
 
 void DIALOG_EDIT_LINE_STYLE::onColorButtonClicked( wxCommandEvent& event )
 {
-    COLOR4D newColor = COLOR4D::UNSPECIFIED;
+    COLOR4D             newColor = COLOR4D::UNSPECIFIED();
     DIALOG_COLOR_PICKER dialog( this, m_selectedColor, false );
 
     if( dialog.ShowModal() == wxID_OK )
         newColor = dialog.GetColor();
 
-    if( newColor == COLOR4D::UNSPECIFIED || m_selectedColor == newColor )
+    if( newColor == COLOR4D::UNSPECIFIED() || m_selectedColor == newColor )
         return;
 
     setColor( newColor );
@@ -128,4 +128,4 @@ bool DIALOG_EDIT_LINE_STYLE::TransferDataFromWindow()
     m_frame->OnModify();
 
     return true;
-}
\ No newline at end of file
+}
diff --git a/eeschema/dialogs/dialog_print_using_printer.cpp b/eeschema/dialogs/dialog_print_using_printer.cpp
index 63f4a7c97..84052aca2 100644
--- a/eeschema/dialogs/dialog_print_using_printer.cpp
+++ b/eeschema/dialogs/dialog_print_using_printer.cpp
@@ -425,10 +425,10 @@ void SCH_PRINTOUT::PrintPage( SCH_SCREEN* aScreen )
     aScreen->m_IsPrinting = true;
 
     COLOR4D bgColor = m_parent->GetDrawBgColor();
-    m_parent->SetDrawBgColor( COLOR4D::WHITE );
+    m_parent->SetDrawBgColor( COLOR4D::WHITE() );
 
     GRSFilledRect( nullptr, dc, fitRect.GetX(), fitRect.GetY(), fitRect.GetRight(),
-                   fitRect.GetBottom(), 0, COLOR4D::WHITE, COLOR4D::WHITE );
+                   fitRect.GetBottom(), 0, COLOR4D::WHITE(), COLOR4D::WHITE() );
 
     if( m_parent->GetPrintMonochrome() )
         GRForceBlackPen( true );
diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp
index 3bd373d7c..98f851902 100644
--- a/eeschema/eeschema.cpp
+++ b/eeschema/eeschema.cpp
@@ -169,7 +169,7 @@ void SetLayerColor( COLOR4D aColor, SCH_LAYER_ID aLayer )
     // Do not allow non-background layers to be completely white.
     // This ensures the BW printing recognizes that the colors should be
     // printed black.
-    if( aColor == COLOR4D::WHITE && aLayer != LAYER_SCHEMATIC_BACKGROUND )
+    if( aColor == COLOR4D::WHITE() && aLayer != LAYER_SCHEMATIC_BACKGROUND )
         aColor.Darken( 0.01 );
 
     unsigned layer = aLayer;
@@ -239,8 +239,8 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
     for( SCH_LAYER_ID ii = SCH_LAYER_ID_START; ii < SCH_LAYER_ID_END; ++ii )
         SetLayerColor( COLOR4D( DARKGRAY ), ii );
 
-    SetLayerColor( COLOR4D::WHITE, LAYER_SCHEMATIC_BACKGROUND );
-    SetLayerColor( COLOR4D::BLACK, LAYER_SCHEMATIC_CURSOR );
+    SetLayerColor( COLOR4D::WHITE(), LAYER_SCHEMATIC_BACKGROUND );
+    SetLayerColor( COLOR4D::BLACK(), LAYER_SCHEMATIC_CURSOR );
 
     wxConfigLoadSetups( KifaceSettings(), cfg_params() );
 
diff --git a/eeschema/lib_text.cpp b/eeschema/lib_text.cpp
index b6b88f533..47921cb87 100644
--- a/eeschema/lib_text.cpp
+++ b/eeschema/lib_text.cpp
@@ -191,7 +191,7 @@ void LIB_TEXT::Plot( PLOTTER* plotter, const wxPoint& offset, bool fill,
     if( plotter->GetColorMode() )       // Used normal color or selected color
         color = GetDefaultColor();
     else
-        color = COLOR4D::BLACK;
+        color = COLOR4D::BLACK();
 
     plotter->Text( pos, color, GetText(), t1 ? TEXT_ANGLE_HORIZ : TEXT_ANGLE_VERT,
                    GetTextSize(), GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
diff --git a/eeschema/sch_line.cpp b/eeschema/sch_line.cpp
index 9c24e3ded..b410acb69 100644
--- a/eeschema/sch_line.cpp
+++ b/eeschema/sch_line.cpp
@@ -64,7 +64,7 @@ SCH_LINE::SCH_LINE( const wxPoint& pos, int layer ) :
     m_startIsDangling = m_endIsDangling = false;
     m_size  = 0;
     m_style = -1;
-    m_color = COLOR4D::UNSPECIFIED;
+    m_color = COLOR4D::UNSPECIFIED();
 
     switch( layer )
     {
@@ -239,7 +239,7 @@ COLOR4D SCH_LINE::GetDefaultColor() const
 void SCH_LINE::SetLineColor( const COLOR4D aColor )
 {
     if( aColor == GetDefaultColor() )
-        m_color = COLOR4D::UNSPECIFIED;
+        m_color = COLOR4D::UNSPECIFIED();
     else
         m_color = aColor;
 }
@@ -249,8 +249,8 @@ void SCH_LINE::SetLineColor( const double r, const double g, const double b, con
 {
     COLOR4D newColor(r, g, b, a);
 
-    if( newColor == GetDefaultColor() || newColor == COLOR4D::UNSPECIFIED )
-        m_color = COLOR4D::UNSPECIFIED;
+    if( newColor == GetDefaultColor() || newColor == COLOR4D::UNSPECIFIED() )
+        m_color = COLOR4D::UNSPECIFIED();
     else
     {
         // Eeschema does not allow alpha channel in colors
@@ -262,7 +262,7 @@ void SCH_LINE::SetLineColor( const double r, const double g, const double b, con
 
 COLOR4D SCH_LINE::GetLineColor() const
 {
-    if( m_color == COLOR4D::UNSPECIFIED )
+    if( m_color == COLOR4D::UNSPECIFIED() )
         return GetLayerColor( m_Layer );
 
     return m_color;
@@ -319,14 +319,14 @@ int SCH_LINE::GetPenSize() const
 {
     if( m_size > 0 )
         return m_size;
-    
+
     return GetDefaultWidth();
 }
 
 
 void SCH_LINE::Print( wxDC* DC, const wxPoint& offset )
 {
-    COLOR4D color = ( m_color != COLOR4D::UNSPECIFIED ) ? m_color : GetLayerColor( m_Layer );
+    COLOR4D color = ( m_color != COLOR4D::UNSPECIFIED() ) ? m_color : GetLayerColor( m_Layer );
     int     width = GetPenSize();
     wxPoint start = m_start;
     wxPoint end = m_end;
@@ -753,7 +753,7 @@ bool SCH_LINE::doIsConnected( const wxPoint& aPosition ) const
 
 void SCH_LINE::Plot( PLOTTER* aPlotter )
 {
-    if( m_color != COLOR4D::UNSPECIFIED )
+    if( m_color != COLOR4D::UNSPECIFIED() )
         aPlotter->SetColor( m_color );
     else
         aPlotter->SetColor( GetLayerColor( GetLayer() ) );
diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp
index 29155bc80..1abb5a0e9 100644
--- a/eeschema/sch_sheet.cpp
+++ b/eeschema/sch_sheet.cpp
@@ -882,7 +882,7 @@ void SCH_SHEET::GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems,
 
 void SCH_SHEET::Plot( PLOTTER* aPlotter )
 {
-    COLOR4D    txtcolor = COLOR4D::UNSPECIFIED;
+    COLOR4D     txtcolor = COLOR4D::UNSPECIFIED();
     wxSize      size;
     wxString    Text;
     int         name_orientation;
diff --git a/eeschema/widgets/widget_eeschema_color_config.cpp b/eeschema/widgets/widget_eeschema_color_config.cpp
index 90017cb66..f4ef4f0ad 100644
--- a/eeschema/widgets/widget_eeschema_color_config.cpp
+++ b/eeschema/widgets/widget_eeschema_color_config.cpp
@@ -204,8 +204,8 @@ void WIDGET_EESCHEMA_COLOR_CONFIG::SetColor( wxCommandEvent& event )
     COLORBUTTON* colorButton = (COLORBUTTON*) button->GetClientData();
 
     wxCHECK_RET( colorButton != NULL, wxT( "Client data not set for color button." ) );
-    COLOR4D oldColor = currentColors[ colorButton->m_Layer ];
-    COLOR4D newColor = COLOR4D::UNSPECIFIED;
+    COLOR4D             oldColor = currentColors[colorButton->m_Layer];
+    COLOR4D             newColor = COLOR4D::UNSPECIFIED();
     DIALOG_COLOR_PICKER dialog( this, oldColor, false );
 
     if( dialog.ShowModal() == wxID_OK )
@@ -213,7 +213,7 @@ void WIDGET_EESCHEMA_COLOR_CONFIG::SetColor( wxCommandEvent& event )
         newColor = dialog.GetColor();
     }
 
-    if( newColor == COLOR4D::UNSPECIFIED || oldColor == newColor )
+    if( newColor == COLOR4D::UNSPECIFIED() || oldColor == newColor )
         return;
 
     currentColors[ colorButton->m_Layer ] = newColor;
diff --git a/gerbview/gbr_display_options.h b/gerbview/gbr_display_options.h
index bcb38f7bf..73d2cd993 100644
--- a/gerbview/gbr_display_options.h
+++ b/gerbview/gbr_display_options.h
@@ -66,7 +66,7 @@ public:
         m_DisplayNegativeObjects = false;
         m_ForceBlackAndWhite = false;
         m_NegativeDrawColor = COLOR4D( DARKGRAY );
-        m_BgDrawColor = COLOR4D::BLACK;
+        m_BgDrawColor = COLOR4D::BLACK();
         m_DiffMode = false;
         m_HighContrastMode = false;
     }
diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp
index 54ba5f76f..439d2f4c4 100644
--- a/gerbview/gerbview_frame.cpp
+++ b/gerbview/gerbview_frame.cpp
@@ -811,7 +811,7 @@ bool GERBVIEW_FRAME::IsLayerVisible( int aLayer ) const
 
 COLOR4D GERBVIEW_FRAME::GetVisibleElementColor( int aLayerID )
 {
-    COLOR4D color = COLOR4D::UNSPECIFIED;
+    COLOR4D color = COLOR4D::UNSPECIFIED();
 
     switch( aLayerID )
     {
diff --git a/gerbview/gerbview_layer_widget.cpp b/gerbview/gerbview_layer_widget.cpp
index c16b606ce..b033485c0 100644
--- a/gerbview/gerbview_layer_widget.cpp
+++ b/gerbview/gerbview_layer_widget.cpp
@@ -108,7 +108,7 @@ void GERBER_LAYER_WIDGET::ReFillRender()
 
     for( unsigned row=0;  row<arrayDim(renderRows);  ++row )
     {
-        if( renderRows[row].color != COLOR4D::UNSPECIFIED )       // does this row show a color?
+        if( renderRows[row].color != COLOR4D::UNSPECIFIED() )       // does this row show a color?
             renderRows[row].color = myframe->GetVisibleElementColor( renderRows[row].id );
 
         if( renderRows[row].id )    // if not the separator
diff --git a/gerbview/gerbview_painter.cpp b/gerbview/gerbview_painter.cpp
index a8e3455bf..1c013d3e7 100644
--- a/gerbview/gerbview_painter.cpp
+++ b/gerbview/gerbview_painter.cpp
@@ -33,7 +33,7 @@ using namespace KIGFX;
 
 GERBVIEW_RENDER_SETTINGS::GERBVIEW_RENDER_SETTINGS()
 {
-    m_backgroundColor = COLOR4D::BLACK;
+    m_backgroundColor = COLOR4D::BLACK();
 
     m_spotFill          = true;
     m_lineFill          = true;
diff --git a/include/eda_draw_frame.h b/include/eda_draw_frame.h
index 0857a862b..4fcc69a8b 100644
--- a/include/eda_draw_frame.h
+++ b/include/eda_draw_frame.h
@@ -388,7 +388,7 @@ public:
      */
     void PrintWorkSheet( wxDC* aDC, BASE_SCREEN* aScreen, int aLineWidth, double aScale,
                          const wxString &aFilename, const wxString &aSheetLayer = wxEmptyString,
-                         COLOR4D aColor = COLOR4D::UNSPECIFIED );
+                         COLOR4D aColor = COLOR4D::UNSPECIFIED() );
 
     void DisplayToolMsg( const wxString& msg ) override;
 
diff --git a/include/gal/color4d.h b/include/gal/color4d.h
index 1b3932623..56a98438a 100644
--- a/include/gal/color4d.h
+++ b/include/gal/color4d.h
@@ -303,12 +303,26 @@ public:
     double b; ///< Blue component
     double a; ///< Alpha component
 
-    /// For legacy support; used as a value to indicate color hasn't been set yet
-    static const COLOR4D UNSPECIFIED;
+    /// A value to indicate a color hasn't been set yet
+    static const COLOR4D& UNSPECIFIED()
+    {
+        const static COLOR4D* color = new COLOR4D( 0, 0, 0, 0 );
+        return *color;
+    }
 
-    // Declare a few color shortcuts that are used for comparisons frequently
-    static const COLOR4D WHITE;
-    static const COLOR4D BLACK;
+    /// The color white
+    static const COLOR4D& WHITE()
+    {
+        const static COLOR4D* color = new COLOR4D( 1, 1, 1, 1 );
+        return *color;
+    };
+
+    /// The color black
+    static const COLOR4D& BLACK()
+    {
+        const static COLOR4D* color = new COLOR4D( 0, 0, 0, 1 );
+        return *color;
+    };
 };
 
 /// @brief Equality operator, are two colors equal
diff --git a/include/msgpanel.h b/include/msgpanel.h
index 04a0dd263..69b483b72 100644
--- a/include/msgpanel.h
+++ b/include/msgpanel.h
@@ -82,7 +82,7 @@ public:
         m_X = 0;
         m_UpperY = 0;
         m_LowerY = 0;
-        m_Color = COLOR4D::UNSPECIFIED;
+        m_Color = COLOR4D::UNSPECIFIED();
     }
 
     void SetUpperText( const wxString& aUpperText ) { m_UpperText = aUpperText; }
diff --git a/include/plotter.h b/include/plotter.h
index a30043b0f..a3a819fe6 100644
--- a/include/plotter.h
+++ b/include/plotter.h
@@ -1257,7 +1257,7 @@ public:
     DXF_PLOTTER() : textAsLines( false )
     {
         textAsLines = true;
-        m_currentColor = COLOR4D::BLACK;
+        m_currentColor = COLOR4D::BLACK();
         m_currentLineType = 0;
         SetUnits( DXF_PLOTTER::DXF_UNIT_INCHES );
     }
@@ -1404,7 +1404,7 @@ void PlotWorkSheet( PLOTTER* plotter, const TITLE_BLOCK& aTitleBlock,
                     int aSheetNumber, int aNumberOfSheets,
                     const wxString &aSheetDesc,
                     const wxString &aFilename,
-                    const COLOR4D aColor = COLOR4D::UNSPECIFIED );
+                    const COLOR4D aColor = COLOR4D::UNSPECIFIED() );
 
 /** Returns the default plot extension for a format
   */
diff --git a/pcbnew/board_items_to_polygon_shape_transform.cpp b/pcbnew/board_items_to_polygon_shape_transform.cpp
index 29268ba49..427134e1c 100644
--- a/pcbnew/board_items_to_polygon_shape_transform.cpp
+++ b/pcbnew/board_items_to_polygon_shape_transform.cpp
@@ -399,7 +399,7 @@ void TEXTE_PCB::TransformShapeWithClearanceToPolygonSet(
     prms.m_cornerBuffer = &aCornerBuffer;
     prms.m_textWidth = GetThickness() + ( 2 * aClearanceValue );
     prms.m_error = aError;
-    COLOR4D color = COLOR4D::BLACK;  // not actually used, but needed by GRText
+    COLOR4D color = COLOR4D::BLACK(); // not actually used, but needed by GRText
 
     if( IsMultilineAllowed() )
     {
diff --git a/pcbnew/dialogs/dialog_pad_properties.cpp b/pcbnew/dialogs/dialog_pad_properties.cpp
index 81c5857d0..a7936db3b 100644
--- a/pcbnew/dialogs/dialog_pad_properties.cpp
+++ b/pcbnew/dialogs/dialog_pad_properties.cpp
@@ -274,7 +274,7 @@ void DIALOG_PAD_PROPERTIES::OnPaintShowPanel( wxPaintEvent& event )
     wxPaintDC    dc( m_panelShowPad );
     PAD_DRAWINFO drawInfo;
 
-    COLOR4D color = COLOR4D::BLACK;
+    COLOR4D color = COLOR4D::BLACK();
 
     if( m_dummyPad->GetLayerSet()[F_Cu] )
         color = m_parent->Settings().Colors().GetItemColor( LAYER_PAD_FR );
diff --git a/pcbnew/exporters/export_vrml.cpp b/pcbnew/exporters/export_vrml.cpp
index 7f0b8e566..0eeace4b9 100644
--- a/pcbnew/exporters/export_vrml.cpp
+++ b/pcbnew/exporters/export_vrml.cpp
@@ -780,7 +780,7 @@ static void export_vrml_pcbtext( MODEL_VRML& aModel, TEXTE_PCB* text )
     if( text->IsMirrored() )
         size.x = -size.x;
 
-    COLOR4D color = COLOR4D::BLACK;  // not actually used, but needed by GRText
+    COLOR4D color = COLOR4D::BLACK(); // not actually used, but needed by GRText
 
     if( text->IsMultilineAllowed() )
     {
diff --git a/pcbnew/exporters/gen_drill_report_files.cpp b/pcbnew/exporters/gen_drill_report_files.cpp
index b815dd840..02516415e 100644
--- a/pcbnew/exporters/gen_drill_report_files.cpp
+++ b/pcbnew/exporters/gen_drill_report_files.cpp
@@ -229,7 +229,7 @@ bool GENDRILL_WRITER_BASE::genDrillMapFile( const wxString& aFullFileName,
 
     // Plot title  "Info"
     wxString Text = wxT( "Drill Map:" );
-    plotter->Text( wxPoint( plotX, plotY ), COLOR4D::UNSPECIFIED, Text, 0,
+    plotter->Text( wxPoint( plotX, plotY ), COLOR4D::UNSPECIFIED(), Text, 0,
                    wxSize( KiROUND( charSize * charScale ),
                            KiROUND( charSize * charScale ) ),
                    GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
@@ -276,7 +276,7 @@ bool GENDRILL_WRITER_BASE::genDrillMapFile( const wxString& aFullFileName,
         if( tool.m_Hole_NotPlated )
             msg += wxT( " (not plated)" );
 
-        plotter->Text( wxPoint( plotX, y ), COLOR4D::UNSPECIFIED, msg, 0,
+        plotter->Text( wxPoint( plotX, y ), COLOR4D::UNSPECIFIED(), msg, 0,
                        wxSize( KiROUND( charSize * charScale ),
                                KiROUND( charSize * charScale ) ),
                        GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
diff --git a/pcbnew/layer_widget.cpp b/pcbnew/layer_widget.cpp
index d9eae839c..1658b50e5 100644
--- a/pcbnew/layer_widget.cpp
+++ b/pcbnew/layer_widget.cpp
@@ -400,7 +400,7 @@ void LAYER_WIDGET::insertRenderRow( int aRow, const ROW& aSpec )
 
     // column 0
     col = 0;
-    if( aSpec.color != COLOR4D::UNSPECIFIED )
+    if( aSpec.color != COLOR4D::UNSPECIFIED() )
     {
         auto bmb = new COLOR_SWATCH( m_RenderScrolledWindow, aSpec.color, encodeId( col, aSpec.id ),
                                      getBackgroundLayerColor() );
@@ -741,7 +741,7 @@ COLOR4D LAYER_WIDGET::GetLayerColor( LAYER_NUM aLayer ) const
         return swatch->GetSwatchColor();
     }
 
-    return COLOR4D::UNSPECIFIED;   // it's caller fault, gave me a bad layer
+    return COLOR4D::UNSPECIFIED();   // it's caller fault, gave me a bad layer
 }
 
 
@@ -894,7 +894,7 @@ public:
 
         // add some render rows
         static const LAYER_WIDGET::ROW renderRows[] = {
-            LAYER_WIDGET::ROW( wxT("With Very Large Ears"), 0, COLOR4D::UNSPECIFIED, wxT("Spock here") ),
+            LAYER_WIDGET::ROW( wxT("With Very Large Ears"), 0, COLOR4D::UNSPECIFIED(), wxT("Spock here") ),
             LAYER_WIDGET::ROW( wxT("With Legs"), 1, YELLOW ),
             LAYER_WIDGET::ROW( wxT("With Oval Eyes"), 1, BROWN, wxT("My eyes are upon you") ),
         };
diff --git a/pcbnew/layer_widget.h b/pcbnew/layer_widget.h
index 9d50797b7..365d24d3d 100644
--- a/pcbnew/layer_widget.h
+++ b/pcbnew/layer_widget.h
@@ -88,13 +88,13 @@ public:
     {
         wxString    rowName;    ///< the prompt or layername
         int         id;         ///< either a layer or "visible element" id
-        COLOR4D     color;      ///< COLOR4D::UNSPECIFIED if none.
+        COLOR4D     color;      ///< COLOR4D::UNSPECIFIED() if none.
         bool        state;      ///< initial wxCheckBox state
         wxString    tooltip;    ///< if not empty, use this tooltip on row
         bool        changeable; ///< if true, the state can be changed
         bool        spacer;     ///< if true, this row is a spacer
 
-        ROW( const wxString& aRowName, int aId, COLOR4D aColor = COLOR4D::UNSPECIFIED,
+        ROW( const wxString& aRowName, int aId, COLOR4D aColor = COLOR4D::UNSPECIFIED(),
             const wxString& aTooltip = wxEmptyString, bool aState = true, bool aChangeable = true )
         {
             rowName = aRowName;
@@ -109,7 +109,7 @@ public:
         ROW()
         {
             id = 0;
-            color = COLOR4D::UNSPECIFIED;
+            color = COLOR4D::UNSPECIFIED();
             state = true;
             changeable = true;
             spacer = true;
@@ -148,7 +148,10 @@ protected:
      * Subclasses can override this to provide accurate representation
      * of transparent colour swatches.
      */
-    virtual COLOR4D getBackgroundLayerColor() { return COLOR4D::BLACK; }
+    virtual COLOR4D getBackgroundLayerColor()
+    {
+        return COLOR4D::BLACK();
+    }
 
     /**
      * Function encodeId
diff --git a/pcbnew/pad_print_functions.cpp b/pcbnew/pad_print_functions.cpp
index 673098ccd..906d2e63e 100644
--- a/pcbnew/pad_print_functions.cpp
+++ b/pcbnew/pad_print_functions.cpp
@@ -106,7 +106,7 @@ void D_PAD::Print( PCB_BASE_FRAME* aFrame, wxDC* aDC, const wxPoint& aOffset )
     else
         drawInfo.m_ShowPadFilled = true;
 
-    COLOR4D color = COLOR4D::BLACK;
+    COLOR4D color = COLOR4D::BLACK();
 
     if( m_layerMask[F_Cu] )
     {
@@ -435,12 +435,12 @@ void D_PAD::PrintShape( wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
                                                            aDrawInfo.m_HoleColor;
         COLOR4D hole_color = fillcolor;
 
-        fillcolor = COLOR4D::WHITE;
+        fillcolor = COLOR4D::WHITE();
         blackpenstate = GetGRForceBlackPenState();
         GRForceBlackPen( false );
 
         if( blackpenstate )
-            hole_color = COLOR4D::BLACK;
+            hole_color = COLOR4D::BLACK();
 
         switch( GetDrillShape() )
         {
diff --git a/pcbnew/pcb_layer_widget.cpp b/pcbnew/pcb_layer_widget.cpp
index 4dd17c90b..852e9cae8 100644
--- a/pcbnew/pcb_layer_widget.cpp
+++ b/pcbnew/pcb_layer_widget.cpp
@@ -53,7 +53,7 @@
 const LAYER_WIDGET::ROW PCB_LAYER_WIDGET::s_render_rows[] = {
 
 #define RR  LAYER_WIDGET::ROW   // Render Row abbreviation to reduce source width
-#define NOCOLOR COLOR4D::UNSPECIFIED    // specify rows that do not have a color selector icon
+#define NOCOLOR COLOR4D::UNSPECIFIED()    // specify rows that do not have a color selector icon
 
          // text                     id                      color       tooltip
     RR( _( "Footprints Front" ),     LAYER_MOD_FR,         NOCOLOR,  _( "Show footprints that are on board's front") ),
@@ -399,7 +399,7 @@ void PCB_LAYER_WIDGET::ReFillRender()
             renderRow.tooltip = wxGetTranslation( s_render_rows[row].tooltip );
             renderRow.rowName = wxGetTranslation( s_render_rows[row].rowName );
 
-            if( renderRow.color != COLOR4D::UNSPECIFIED )       // does this row show a color?
+            if( renderRow.color != COLOR4D::UNSPECIFIED() )       // does this row show a color?
             {
                 // this window frame must have an established BOARD, i.e. after SetBoard()
                 renderRow.color = myframe->Settings().Colors().GetItemColor(
diff --git a/pcbnew/pcbnew_printout.cpp b/pcbnew/pcbnew_printout.cpp
index a21121e1f..e146fc735 100644
--- a/pcbnew/pcbnew_printout.cpp
+++ b/pcbnew/pcbnew_printout.cpp
@@ -185,9 +185,9 @@ void PCBNEW_PRINTOUT::setupPainter( const std::unique_ptr<KIGFX::PAINTER>& aPain
             break;
     }
 
-    painter->GetSettings()->SetLayerColor( LAYER_PADS_PLATEDHOLES, COLOR4D::WHITE );
-    painter->GetSettings()->SetLayerColor( LAYER_NON_PLATEDHOLES, COLOR4D::WHITE );
-    painter->GetSettings()->SetLayerColor( LAYER_VIAS_HOLES, COLOR4D::WHITE );
+    painter->GetSettings()->SetLayerColor( LAYER_PADS_PLATEDHOLES, COLOR4D::WHITE() );
+    painter->GetSettings()->SetLayerColor( LAYER_NON_PLATEDHOLES, COLOR4D::WHITE() );
+    painter->GetSettings()->SetLayerColor( LAYER_VIAS_HOLES, COLOR4D::WHITE() );
 }
 
 
diff --git a/pcbnew/plot_board_layers.cpp b/pcbnew/plot_board_layers.cpp
index 1504512e5..cd4ce84fd 100644
--- a/pcbnew/plot_board_layers.cpp
+++ b/pcbnew/plot_board_layers.cpp
@@ -97,13 +97,15 @@ void PlotSilkScreen( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask,
                 if( !( masklayer & layersmask_plotpads ).any() )
                     continue;
 
-                COLOR4D color = COLOR4D::BLACK;
+                COLOR4D color = COLOR4D::BLACK();
 
                 if( layersmask_plotpads[B_SilkS] )
                    color = aBoard->Colors().GetLayerColor( B_SilkS );
 
                 if( layersmask_plotpads[F_SilkS] )
-                    color = ( color == COLOR4D::BLACK) ? aBoard->Colors().GetLayerColor( F_SilkS ) : color;
+                    color = ( color == COLOR4D::BLACK() ) ?
+                                    aBoard->Colors().GetLayerColor( F_SilkS ) :
+                                    color;
 
                 itemplotter.PlotPad( pad, color, SKETCH );
             }
@@ -399,7 +401,7 @@ void PlotStandardLayer( BOARD *aBoard, PLOTTER* aPlotter,
             if( padPlotsSize.x <= 0 || padPlotsSize.y <= 0 )
                 continue;
 
-            COLOR4D color = COLOR4D::BLACK;
+            COLOR4D color = COLOR4D::BLACK();
 
             if( pad->GetLayerSet()[B_Cu] )
                color = aBoard->Colors().GetItemColor( LAYER_PAD_BK );
diff --git a/pcbnew/plot_brditems_plotter.cpp b/pcbnew/plot_brditems_plotter.cpp
index 6c3c84df1..ebd6c0dd6 100644
--- a/pcbnew/plot_brditems_plotter.cpp
+++ b/pcbnew/plot_brditems_plotter.cpp
@@ -55,7 +55,7 @@ COLOR4D BRDITEMS_PLOTTER::getColor( LAYER_NUM aLayer )
 
     // A hack to avoid plotting ahite itmen in white color, expecting the paper
     // is also white: use a non white color:
-    if( color == COLOR4D::WHITE )
+    if( color == COLOR4D::WHITE() )
         color = COLOR4D( LIGHTGRAY );
 
     return color;
@@ -292,7 +292,7 @@ void BRDITEMS_PLOTTER::PlotTextModule( TEXTE_MODULE* pt_texte, COLOR4D aColor )
     double  orient;
     int     thickness;
 
-    if( aColor == COLOR4D::WHITE )
+    if( aColor == COLOR4D::WHITE() )
         aColor = COLOR4D( LIGHTGRAY );
 
     m_plotter->SetColor( aColor );
diff --git a/pcbnew/toolbars_pcb_editor.cpp b/pcbnew/toolbars_pcb_editor.cpp
index f7c8e0526..abad13918 100644
--- a/pcbnew/toolbars_pcb_editor.cpp
+++ b/pcbnew/toolbars_pcb_editor.cpp
@@ -91,11 +91,11 @@ void PCB_EDIT_FRAME::PrepareLayerIndicator( bool aForceRebuild )
     bool       change = aForceRebuild;
 
     static int previous_requested_scale;
-    static COLOR4D previous_active_layer_color = COLOR4D::UNSPECIFIED;
-    static COLOR4D previous_Route_Layer_TOP_color = COLOR4D::UNSPECIFIED;
-    static COLOR4D previous_Route_Layer_BOTTOM_color = COLOR4D::UNSPECIFIED;
-    static COLOR4D previous_via_color = COLOR4D::UNSPECIFIED;
-    static COLOR4D previous_background_color = COLOR4D::UNSPECIFIED;
+    static COLOR4D previous_active_layer_color = COLOR4D::UNSPECIFIED();
+    static COLOR4D previous_Route_Layer_TOP_color = COLOR4D::UNSPECIFIED();
+    static COLOR4D previous_Route_Layer_BOTTOM_color = COLOR4D::UNSPECIFIED();
+    static COLOR4D previous_via_color = COLOR4D::UNSPECIFIED();
+    static COLOR4D previous_background_color = COLOR4D::UNSPECIFIED();
 
     int requested_scale;
     Pgm().CommonSettings()->Read( ICON_SCALE_KEY, &requested_scale, 0 );
diff --git a/pcbnew/tools/zone_create_helper.cpp b/pcbnew/tools/zone_create_helper.cpp
index 99a6e3260..c916a1876 100644
--- a/pcbnew/tools/zone_create_helper.cpp
+++ b/pcbnew/tools/zone_create_helper.cpp
@@ -237,7 +237,7 @@ bool ZONE_CREATE_HELPER::OnFirstPoint( POLYGON_GEOM_MANAGER& aMgr )
             const auto& settings = *m_parentView.GetPainter()->GetSettings();
             COLOR4D color = settings.GetColor( nullptr, m_zone->GetLayer() );
 
-            m_previewItem.SetStrokeColor( COLOR4D::WHITE );
+            m_previewItem.SetStrokeColor( COLOR4D::WHITE() );
             m_previewItem.SetFillColor( color.WithAlpha( 0.2 ) );
 
             m_parentView.SetVisible( &m_previewItem, true );
diff --git a/qa/eeschema/mocks_eeschema.cpp b/qa/eeschema/mocks_eeschema.cpp
index 4b21eadc9..639a49d20 100644
--- a/qa/eeschema/mocks_eeschema.cpp
+++ b/qa/eeschema/mocks_eeschema.cpp
@@ -132,10 +132,10 @@ void SetLayerColor( COLOR4D aColor, SCH_LAYER_ID aLayer )
     // Do not allow non-background layers to be completely white.
     // This ensures the BW printing recognizes that the colors should be
     // printed black.
-    if( aColor == COLOR4D::WHITE && aLayer != LAYER_SCHEMATIC_BACKGROUND )
+    if( aColor == COLOR4D::WHITE() && aLayer != LAYER_SCHEMATIC_BACKGROUND )
         aColor.Darken( 0.01 );
 
     unsigned layer = aLayer;
     wxASSERT( layer < arrayDim( s_layerColor ) );
     s_layerColor[layer] = aColor;
-}
\ No newline at end of file
+}
diff --git a/qa/gal/gal_pixel_alignment/test_gal_pixel_alignment.cpp b/qa/gal/gal_pixel_alignment/test_gal_pixel_alignment.cpp
index 3326ba466..3516822a9 100644
--- a/qa/gal/gal_pixel_alignment/test_gal_pixel_alignment.cpp
+++ b/qa/gal/gal_pixel_alignment/test_gal_pixel_alignment.cpp
@@ -82,7 +82,7 @@ public:
         auto gal = aView->GetGAL();
         gal->SetTarget( KIGFX::TARGET_NONCACHED );
         gal->SetIsStroke( true );
-        gal->SetStrokeColor( COLOR4D::WHITE );
+        gal->SetStrokeColor( COLOR4D::WHITE() );
 
        /* for( int i=0;i < 100; i++ )
         {
-- 
2.21.0


References