diff --git a/3d-viewer/3d_canvas/create_layer_items.cpp b/3d-viewer/3d_canvas/create_layer_items.cpp index db1b654322..744a2af9b7 100644 --- a/3d-viewer/3d_canvas/create_layer_items.cpp +++ b/3d-viewer/3d_canvas/create_layer_items.cpp @@ -686,19 +686,24 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) if( aStatusReporter ) aStatusReporter->Report( _( "Create zones" ) ); - std::vector> zones; + std::vector> zones; + std::unordered_map> layer_lock; for( ZONE* zone : m_board->Zones() ) { for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() ) + { zones.emplace_back( std::make_pair( zone, layer ) ); + layer_lock.emplace( layer, std::make_unique() ); + } } // Add zones objects std::atomic nextZone( 0 ); std::atomic threadsFinished( 0 ); - size_t parallelThreadCount = std::max( std::thread::hardware_concurrency(), 2 ); + size_t parallelThreadCount = std::min( zones.size(), + std::max( std::thread::hardware_concurrency(), 2 ) ); for( size_t ii = 0; ii < parallelThreadCount; ++ii ) { @@ -708,7 +713,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) areaId < zones.size(); areaId = nextZone.fetch_add( 1 ) ) { - const ZONE* zone = zones[areaId].first; + ZONE* zone = zones[areaId].first; if( zone == nullptr ) break; @@ -716,9 +721,22 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) PCB_LAYER_ID layer = zones[areaId].second; auto layerContainer = m_layerMap.find( layer ); + auto layerPolyContainer = m_layers_poly.find( layer ); if( layerContainer != m_layerMap.end() ) + { addSolidAreasShapes( zone, layerContainer->second, layer ); + } + + if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS ) + && ( m_renderEngine == RENDER_ENGINE::OPENGL_LEGACY ) + && layerPolyContainer != m_layers_poly.end() ) + { + auto mut_it = layer_lock.find( layer ); + + std::lock_guard< std::mutex > lock( *( mut_it->second ) ); + zone->TransformSolidAreasShapesToPolygon( layer, *layerPolyContainer->second ); + } } threadsFinished++; @@ -732,25 +750,6 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) } - if( GetFlag( FL_ZONE ) && GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS ) - && ( m_renderEngine == RENDER_ENGINE::OPENGL_LEGACY ) ) - { - // Add copper zones - for( ZONE* zone : m_board->Zones() ) - { - if( zone == nullptr ) - break; - - for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() ) - { - auto layerContainer = m_layers_poly.find( layer ); - - if( layerContainer != m_layers_poly.end() ) - zone->TransformSolidAreasShapesToPolygon( layer, *layerContainer->second ); - } - } - } - // Simplify layer polygons if( aStatusReporter )