diff --git a/pcbnew/zone.cpp b/pcbnew/zone.cpp index e850f9f456..fe642aaa48 100644 --- a/pcbnew/zone.cpp +++ b/pcbnew/zone.cpp @@ -344,14 +344,13 @@ const BOX2I ZONE::GetBoundingBox() const if( const BOARD* board = GetBoard() ) { std::unordered_map& cache = board->m_ZoneBBoxCache; + std::unique_lock cacheLock( const_cast( board )->m_CachesMutex ); auto cacheIter = cache.find( this ); if( cacheIter != cache.end() ) return cacheIter->second; BOX2I bbox = m_Poly->BBox(); - - std::unique_lock cacheLock( const_cast( board )->m_CachesMutex ); cache[ this ] = bbox; return bbox; @@ -365,12 +364,11 @@ void ZONE::CacheBoundingBox() { BOARD* board = GetBoard(); std::unordered_map& cache = board->m_ZoneBBoxCache; - - auto cacheIter = cache.find( this ); + std::unique_lock cacheLock( board->m_CachesMutex ); + auto cacheIter = cache.find( this ); if( cacheIter == cache.end() ) { - std::unique_lock cacheLock( board->m_CachesMutex ); cache[ this ] = m_Poly->BBox(); } }