diff --git a/pcbnew/board.h b/pcbnew/board.h index aca46a79be..f7401b20cc 100644 --- a/pcbnew/board.h +++ b/pcbnew/board.h @@ -271,8 +271,13 @@ public: void IncrementTimeStamp() { m_timeStamp++; - m_InsideAreaCache.clear(); - m_InsideCourtyardCache.clear(); + + { + std::unique_lock cacheLock( m_CachesMutex ); + m_InsideAreaCache.clear(); + m_InsideCourtyardCache.clear(); + } + m_CopperZoneRTrees.clear(); } @@ -1142,6 +1147,7 @@ public: public: // ------------ Run-time caches ------------- + std::mutex m_CachesMutex; std::map< std::pair, bool > m_InsideCourtyardCache; std::map< std::pair, bool > m_InsideAreaCache; diff --git a/pcbnew/pcb_expr_evaluator.cpp b/pcbnew/pcb_expr_evaluator.cpp index 946c78d12a..982990c114 100644 --- a/pcbnew/pcb_expr_evaluator.cpp +++ b/pcbnew/pcb_expr_evaluator.cpp @@ -200,8 +200,9 @@ static void insideCourtyard( LIBEVAL::CONTEXT* aCtx, void* self ) if( !footprint ) return false; + std::unique_lock cacheLock( board->m_CachesMutex ); std::pair key( footprint, item ); - auto i = board->m_InsideCourtyardCache.find( key ); + auto i = board->m_InsideCourtyardCache.find( key ); if( i != board->m_InsideCourtyardCache.end() ) return i->second; @@ -347,7 +348,11 @@ static void insideArea( LIBEVAL::CONTEXT* aCtx, void* self ) if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T ) { - ZONE* itemZone = static_cast( item ); + ZONE* itemZone = static_cast( item ); + + if( !itemZone->IsFilled() ) + return false; + DRC_RTREE* itemRTree = board->m_CopperZoneRTrees[ itemZone ].get(); for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() ) @@ -376,15 +381,16 @@ static void insideArea( LIBEVAL::CONTEXT* aCtx, void* self ) if( !zone || zone == item || zone->GetParent() == item ) return false; + std::unique_lock cacheLock( board->m_CachesMutex ); std::pair key( zone, item ); - auto i = board->m_InsideAreaCache.find( key ); + auto i = board->m_InsideAreaCache.find( key ); if( i != board->m_InsideAreaCache.end() ) return i->second; bool result = realInsideZone( zone ); - board->m_InsideCourtyardCache[ key ] = result; + board->m_InsideAreaCache[ key ] = result; return result; };