Protect courtyard cache regen

The courtyards are referenced by multiple calls and will be rebuilt on
command.  If this happens during zone fill (because the board timestamp
has incremented since the start) multiple threads may generate the cache
at the same time, leaving one with an invalid pointer

Fixes https://gitlab.com/kicad/code/kicad/-/issues/17791
This commit is contained in:
Seth Hillbrand 2024-04-18 08:39:42 -07:00
parent b394d7eb96
commit df5dd15c6f
2 changed files with 3 additions and 0 deletions

View File

@ -2797,6 +2797,8 @@ std::shared_ptr<SHAPE> FOOTPRINT::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHI
const SHAPE_POLY_SET& FOOTPRINT::GetCourtyard( PCB_LAYER_ID aLayer ) const
{
std::lock_guard<std::mutex> lock( m_courtyard_cache_mutex );
if( GetBoard() && GetBoard()->GetTimeStamp() > m_courtyard_cache_timestamp )
const_cast<FOOTPRINT*>( this )->BuildCourtyardCaches();

View File

@ -1050,6 +1050,7 @@ private:
SHAPE_POLY_SET m_courtyard_cache_front; // Note that a footprint can have both front and back
SHAPE_POLY_SET m_courtyard_cache_back; // courtyards populated.
mutable int m_courtyard_cache_timestamp;
mutable std::mutex m_courtyard_cache_mutex;
};
#endif // FOOTPRINT_H