7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-19 23:21:41 +00:00

Pcbnew: fix bad layer maths in stackup dialog

F_Cu | B_Cu is not the same as LSET( F_Cu ) | LSET( B_Cu),
so you cannot do some_lset |= F_Cu | B_Cu (or rather you can, but
it is not what you expect).

F_Cu and B_Cu are just ints, so 0 | 2 == 2. This isn't the
same as setting *bit indices* 0 and 2. OR-ing with 2 is setting
bit index 1, which is F_Mask.

You can set them one by one with lset.set( F_Cu ) or OR with
LSET::ExternalCuMask() helper. But actually, we're trying to set all 'n'
copper layers, and LSET has AllCuMask and we can save all the hassle
in this function.

Thanks to @aris-kimi for finding the problematic code lines and
providing the foundation of this fix.

Fixes: https://gitlab.com/kicad/code/kicad/-/issues/19855
This commit is contained in:
John Beard 2025-02-06 12:50:02 +08:00
parent 3018d7af09
commit 14cbce5d0f

View File

@ -605,20 +605,12 @@ int PANEL_SETUP_BOARD_STACKUP::GetCopperLayerCount() const
void PANEL_SETUP_BOARD_STACKUP::updateCopperLayerCount()
{
int copperCount = GetCopperLayerCount();
const int copperCount = GetCopperLayerCount();
wxASSERT( copperCount >= 2 );
m_enabledLayers.ClearCopperLayers();
m_enabledLayers |= F_Cu | B_Cu;
// F_Cu and B_Cu are already enabled. Enable internal cu layers
int internal_cu_count = copperCount - 2;
// Inner layers start at B_Cu+2: B_Cu+2, B_Cu+4 ... B_Cu+2n
// and use even indexes (F_Cu, B_Cu, 4, 6, ...)
for( int i = 1; i <= internal_cu_count; i++ )
m_enabledLayers.set( B_Cu + (i*2) );
m_enabledLayers |= LSET::AllCuMask( copperCount );
}