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

(cherry picked from commit df5dd15c6f)
This commit is contained in:
Seth Hillbrand 2024-04-18 08:39:42 -07:00
parent 798b827a12
commit fdc3806ed1
2 changed files with 3 additions and 0 deletions

View File

@ -2551,6 +2551,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

@ -1025,6 +1025,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