Fix race condition in zone fill

When checking collisions, the SHAPE_POLY_SET::Collide() routine is not
const because it will regenerate the triangulation cache if it is out of
date (using a const_cast, grrr).  This sidesteps the issue by assigning
a mutex to the triangulation caching

Fixes https://gitlab.com/kicad/code/kicad/-/issues/17180

(cherry picked from commit 81cb6d0c3f)
This commit is contained in:
Seth Hillbrand 2024-03-13 10:33:43 -07:00
parent 01590385c7
commit 734222bd88
2 changed files with 4 additions and 1 deletions

View File

@ -32,6 +32,7 @@
#include <deque> // for deque
#include <iosfwd> // for string, stringstream
#include <memory>
#include <mutex>
#include <set> // for set
#include <stdexcept> // for out_of_range
#include <stdlib.h> // for abs
@ -1572,7 +1573,8 @@ protected:
std::vector<POLYGON> m_polys;
std::vector<std::unique_ptr<TRIANGULATED_POLYGON>> m_triangulatedPolys;
bool m_triangulationValid = false;
bool m_triangulationValid = false;
std::mutex m_triangulationMutex;
private:
MD5_HASH m_hash;

View File

@ -3232,6 +3232,7 @@ static SHAPE_POLY_SET partitionPolyIntoRegularCellGrid( const SHAPE_POLY_SET& aP
void SHAPE_POLY_SET::cacheTriangulation( bool aPartition, bool aSimplify,
std::vector<std::unique_ptr<TRIANGULATED_POLYGON>>* aHintData )
{
std::unique_lock<std::mutex> lock( m_triangulationMutex );
bool recalculate = !m_hash.IsValid();
MD5_HASH hash;