Two issues found with the locking system used to prevent access to
stale connectivity data during the zone fill process:
1) a std::mutex has undefined behavior if you try to use it to guard
against access from the same thread. Because of the use of wx event
loops (and coroutines) it is entirely possible, and in some situations
inevitable, that the same thread will try to redraw the ratsnest in the
middle of zone refilling.
2) The mutex was only guarding the ZONE_FILLER::Fill method, but the callers
of that method also do connectivity updates as part of the COMMIT::Push.
Redrawing the ratsnest after the Fill but before the Push will result in
stale connectivity pointers to zone filled areas.
Fixed (1) by switching to a trivial spinlock implementation. Spinlocks would
generally not be desirable if the contention for the connectivity data crossed
thread boundaries, but at the moment I believe it's guaranteed that the reads
and writes to connectivity that are guarded by this lock happen from the main
UI thread. The writes are also quite rare compared to reads, and reads are
generally fast, so I'm not really worried about the UI thread spinning for any
real amount of time.
Fixed (2) by moving the locking location up to the call sites of
ZONE_FILLER::Fill.
This issue was quite difficult to reproduce, but I found a fairly reliable way:
It only happens (for me) on Windows, MSYS2 build, with wxWidgets 3.0
It also only happens if I restrict PcbNew to use 2 CPU cores.
With those conditions, I can reproduce the issue described in #6471 by
repeatedly editing a zone properties and changing its net. The crash is
especially easy to trigger if you press some keys (such as 'e' for edit)
while the progress dialog is displayed. It's easiest to do this in a debug
build as the slower KiCad is running, the bigger the window is to trigger this
bug.
Fixes https://gitlab.com/kicad/code/kicad/-/issues/6471
Fixes https://gitlab.com/kicad/code/kicad/-/issues/7048
1) better load-balancing for deferred zones
2) sort zones by priority before filling
3) retire BOARD::GetZoneList() which had a horrible performance profile
4) implement a zone bounding box cache
5) better checks for IsCancelled() so long fills can be exited
Fixes https://gitlab.com/kicad/code/kicad/issues/5738
1) For a while now we've been using a calculated seg count from a given
maxError, and a correction factor to push the radius out so that all
the error is outside the arc/circle. However, the second calculation
(which pre-dates the first) is pretty much just the inverse of the first
(and yields nothing more than maxError back). This is particularly
sub-optimal given the cost of trig functions.
2) There are a lot of old optimizations to reduce segcounts in certain
situations, someting that our error-based calculation compensates for
anyway. (Smaller radii need fewer segments to meet the maxError
condition.) But perhaps more importantly we now surface maxError in the
UI and we don't really want to call it "Max deviation except when it's
not".
3) We were also clamping the segCount twice: once in the calculation
routine and once in most of it's callers. Furthermore, the caller
clamping was inconsistent (both in being done and in the clamping
value). We now clamp only in the calculation routine.
4) There's no reason to use the correction factors in the 3Dviewer;
it's just a visualization and whether the polygonization error is
inside or outside the shape isn't really material.
5) The arc-correction-disabling stuff (used for solder mask layer) was
somewhat fragile in that it depended on the caller to turn it back on
afterwards. It's now only exposed as a RAII object which automatically
cleans up when it goes out of scope.
6) There were also bugs in a couple of the polygonization routines where
we'd accumulate round-off error in adding up the segments and end up with
an overly long last segment (which of course would voilate the error
max). This was the cause of the linked bug and also some issues with vias
that we had fudged in the past with extra clearance.
Fixes https://gitlab.com/kicad/code/kicad/issues/5567
This introduces layer handling to a lot of the geometry routines.
Many of them don't do much with it now, but it does help multi-layer
zones and will help when padstacks are implemented.
This unifies the zone refill across architecture into the tool-based
architecture. Also provides ZONE_FILLER-based progress managment for
tools.
(cherry picked from commit be9cd98cb1)
Give the user the option of cancelling a file open if there are
segment zones; otherwise they're converted to polygon fills.
Fixes: lp:1823087
* https://bugs.launchpad.net/kicad/+bug/1823087
the filled areas can use a hatch pattern (crossing lines) using square holes.
The zone filler removes too small holes (truncated holes) from hatch pattern.
It avoid to create small holes when a hole pattern is truncated by the filled area base shape.
Previously, in many cases the selected zone was refilled on exit selection, even if the zone was not modified.
This is annoying, because the zone fill can be really time consuming, and cannot be called without a good reason.
Now the refilling is made only if a zone parameter is actually modified.
This is a boyscouting commit to standardize the threading of zone fills.
We do not need to join threads after their completion, instead we simply
allow them to clean up their memory without blocking the user. This
also sets the maximum number of threads that may be created to the
number of zones being filled. More than this will only leave un-used
threads being created and immediately killed.
We also include the connectivity search as a phase in the fill progress
reporter. This was the case before but did not utilize the correct
maxsize, leading to stalled progress bar.
The calculation was made too early, before removing insulated islands.
Note: filling zones with segments is an old option, not very useful:
using only polygons has never created issues in gerber files.