From 79924b5dfd2c666610bcaf2a5c1e01d1f3546e0b Mon Sep 17 00:00:00 2001
From: Jeff Young <jeff@rokeby.ie>
Date: Thu, 27 Mar 2025 15:25:00 +0000
Subject: [PATCH] Don't gate drill mark plotting on unenabled copper layers.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/20460
---
 pcbnew/plot_board_layers.cpp | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/pcbnew/plot_board_layers.cpp b/pcbnew/plot_board_layers.cpp
index 1294691e06..47e8434d8d 100644
--- a/pcbnew/plot_board_layers.cpp
+++ b/pcbnew/plot_board_layers.cpp
@@ -135,9 +135,19 @@ void PlotBoardLayers( BOARD* aBoard, PLOTTER* aPlotter, const LSEQ& aLayers,
     // if a drill mark must be plotted,it must be plotted as a filled
     // white shape *after* all other shapes are plotted, provided that
     // the other shapes are not copper layers
+    int copperLayers = 0;
+    int nonCopperLayers = 0;
+
+    for( PCB_LAYER_ID layer : aLayers )
+    {
+        if( IsCopperLayer( layer ) )
+            copperLayers++;
+        else
+            nonCopperLayers++;
+    }
+
     bool plot_mark = ( aPlotOptions.GetDrillMarksType() != DRILL_MARKS::NO_DRILL_SHAPE
-                       && !aPlotOptions.GetLayerSelection().ClearCopperLayers().empty()
-                       && !aPlotOptions.GetLayerSelection().ClearNonCopperLayers().empty() );
+                       && copperLayers > 0 && nonCopperLayers > 0 );
 
     for( PCB_LAYER_ID layer : aLayers )
         PlotOneBoardLayer( aBoard, aPlotter, layer, aPlotOptions, layer == aLayers[0] );