From d538f8d848798f3905ab9664df7e28cf79a1271b Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 24 Jul 2025 13:39:13 -0700 Subject: [PATCH] Avoid unmapped layers ViewGetLayers returns the item layer even if it is invalid. We filter this out at the base and skip items that cannot be displayed in the view. Fixes https://gitlab.com/kicad/code/kicad/-/issues/21368 --- common/view/view.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/common/view/view.cpp b/common/view/view.cpp index e8168e82b8..30d56e3415 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -312,6 +312,15 @@ void VIEW::Add( VIEW_ITEM* aItem, int aDrawPriority ) aItem->m_viewPrivData->m_cachedIndex = m_allItems->size(); std::vector layers = aItem->ViewGetLayers(); + + std::erase_if( layers, []( int layer ) + { + return layer < 0 || layer >= VIEW_MAX_LAYERS; + } ); + + if( layers.empty() ) + return; + aItem->viewPrivData()->saveLayers( layers ); m_allItems->push_back( aItem );