Commit Graph

50 Commits

Author SHA1 Message Date
Seth Hillbrand e60e619655 Fix data race in library manager row cache
Background library loading threads call GetRow() through
loadFromScope(), which writes to m_rowCache concurrently
with the main thread clearing it in loadTables(). The
unsynchronized access corrupts the map's red-black tree,
causing a double-free crash when switching projects.

Add m_rowCacheMutex to protect all m_rowCache accesses.
Also replace std::tie with std::make_tuple to avoid
unnecessary temporary conversions, and use a single
find() instead of contains() followed by at().
2026-03-04 12:32:57 -08:00
Jon Evans e77858bdbc Remove random include inserted by clion 2026-03-03 21:47:22 -05:00
Jon Evans a66db54bc5 Cache library manager row lookup 2026-03-03 21:26:09 -05:00
Seth Hillbrand 1e2a2fb02c Fix minor safety and visibility issues
Move onUpdateUI from public to private in EDA_BASE_FRAME since
it is an internal event handler bound via Bind(), not part of
the public API.

Capture the empty-check result before erasing rows in
library_manager.cpp to avoid using invalidated iterators from
the subrange returned by std::ranges::remove_if.

Add null guards to the netHighlightCond toolbar condition
lambda in PCB_EDIT_FRAME to prevent null dereference during
shutdown, matching the pattern used by other toolbar
conditions fixed in f962de966b.
2026-02-27 19:13:47 -08:00
Seth Hillbrand c064cdbf6b PCM: fix footprint libs removed from fp-lib-table when auto-remove is enabled
The `cleanupRemovedPCMLibraries` function used `wxFile::Exists()` to check
whether a library path still exists on disk. However, `wxFile::Exists()` only
checks for regular files, not directories.

Footprint libraries (.pretty) and design block libraries (.kicad_blocks) are
directories, not files.

Fix by using `wxFileName::Exists()` instead, which correctly handles both files
and directories.

Fixes: https://gitlab.com/kicad/code/kicad/-/issues/23128
2026-02-26 09:01:45 -08:00
Jeff Young b12af57fc9 Honour library table row disabled flags.
Fixes https://gitlab.com/kicad/code/kicad/-/issues/23091
2026-02-17 12:33:48 +00:00
Jeff Young 6d7c93f552 Suppress log messages.
Fixes https://gitlab.com/kicad/code/kicad/-/issues/23082
2026-02-16 15:53:53 +00:00
Seth Hillbrand a77f3b34f1 Fix assertion when library table file has mismatched type
When a library table file is corrupted or manually edited to contain a
different table type than expected (e.g., fp_lib_table content inside a
sym-lib-table file), the wxCHECK2 assertion in loadTables would fire.
Replace with a wxLogWarning and skip the mismatched table gracefully.

Fixes KICAD-9AB
2026-02-15 21:40:28 -08:00
Seth Hillbrand 9b67b0238d Fix thread-safety crash in async library loading
Resolve URI expansion on the main thread before dispatching async
library enumeration tasks. The getUri() call accesses PROJECT text
variables and SETTINGS_MANAGER::Prj() which are not thread-safe.

When a project is unloaded while worker threads are still running,
they would access freed or modified data in PROJECT::TextVarResolver,
causing either an access violation in (KICAD-14DS) or an assertion
failure when the project list is empty (KICAD-11Q9).

Pre-computing the expanded URI on the main thread and passing it to
enumerateLibrary() as a parameter eliminates the data race.

Resolves KICAD-14DS
Resolves KICAD-11Q9
2026-02-15 06:53:22 -08:00
Seth Hillbrand c52ab91c84 Reduce compile times by extracting headers
Break the most expensive header include chains that contaminate the
largest number of translation units

New lightweight headers for extractdded types:
font_metrics.h, mouse_drag_action.h, board_project_settings_params.h,
common_settings_internals.h, wx_infobar_message_type.h,
zone_layer_properties_grid.h
2026-02-13 17:10:45 -08:00
Seth Hillbrand fe1689a6c7 Honor disabled/hidden flags on nested library tables
When a nested library table row is marked as disabled or hidden, its
contained libraries are now properly excluded from the flattened
library list returned by LIBRARY_MANAGER::Rows(). Previously, libraries
from disabled/hidden nested tables were incorrectly included.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/22784
2026-01-30 20:40:43 -08:00
Seth Hillbrand e96ffa3c21 Pass project context to ExpandEnvVarSubstitutions
Environment variable expansion in paths now receives the active project
context instead of null. This enables project-specific variables to
resolve correctly in output directories and configuration paths.
2026-01-29 09:46:48 -08:00
Seth Hillbrand 95b29aba3f Simplify library adapter locking and reduce code duplication
The three library adapters (symbol, footprint, design block) each had
their own AsyncLoad() and GetLibraryStatus() implementations that were
nearly identical. This moves both to the base class.

The per-library mutex is removed. Each adapter now uses a single
shared_mutex for its library map. Read operations take shared locks,
write operations take unique locks. This simplifies the locking model
from two levels to one.

Derived classes override a new enumerateLibrary() method to perform
type-specific enumeration. The base class handles threading, status
tracking, and error handling.

Also adds a new WithFootprintsForLibrary() routine that takes a callback
but handles the locking internally so callers don't need to remember
2026-01-23 08:44:31 -08:00
Jeff Young 9bc7c1d63e Improve status update strategy for nested tables. 2026-01-22 13:32:27 +00:00
Jeff Young f4e025596b Passing a string to LIBRARY_TABLE's c'tor doesn't do what you think it does.
Also fixes nested tables being deleted out from under
the dialog.

Also fixes a bug where PANEL_DESIGN_BLOCK_LIB_TABLE
had fallen behind the the other two.
2026-01-20 13:18:46 +00:00
Jeff Young 75d523e3e9 Include "Table" in list of symbol library formats.
Make sure "Table" rows get a file picker instead of a
directory picker (return *.* from getFileTypes()).

Don't assert when we can't find a plugin for a
nested table.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/22731
2026-01-18 13:57:38 +00:00
Seth Hillbrand 5e2d8b9a98 Abort async library loads before modifying project list
When starting pcbnew in standalone mode and quickly opening a file, a race
condition could occur where background library loading threads tried to access
Prj() while the project list was being modified. This caused an assertion
failure: "no project in list".

The fix aborts any async library loads before modifying m_projects_list in
SETTINGS_MANAGER::LoadProject() and UnloadProject(). This ensures background
threads have completed before the project list becomes temporarily invalid.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/22697
2026-01-13 11:11:54 -08:00
Sven Pauli 3bf9396c28 Fix crash when starting FP editor during library load 2026-01-12 09:55:34 -08:00
Seth Hillbrand 9b9899979b Stop showing popup for library load errors
Errors are stored to a vector for display after clicking the warning
icon in the toolbar.
2025-12-31 13:15:06 -08:00
Mark Roszko d4668d0d01 Use a scoped_lock earlier in RemoveAdapter as checking m_adapters for a key runs into a theoretical conflict with RegisterAdapter touching it.
Silences coverity warning.
2025-12-11 19:37:48 -05:00
Jeff Young 29eebadbfd Reprocess library tables when they change. 2025-12-08 13:01:22 +00:00
Jeff Young f94485ba33 Formatting. 2025-12-08 13:01:22 +00:00
Jon Evans f59ae6d6f6 Clean up management of library adapters 2025-12-07 11:58:57 -05:00
Seth Hillbrand 2d538d3d69 ADDED: Remote symbol placement
Allows activating a display panel that shows a webpage designed to
provide instances of symbols, footprints, 3d models and spice models to
the designer.

The webpage can be installed via PCM or directly in the panel.  Webpages
should be registered with the KiCad project in order to avoid a warning
when showing content.
2025-11-29 17:58:32 -08:00
Jon Evans 253f965a18 Improve design block error reporting 2025-11-27 16:23:34 -05:00
Jeff Young 8f8f05a944 Improve error reporting for lib table rows. 2025-11-23 22:36:37 +00:00
Jon Evans d8a3ba97c5 Deprioritize library load background tasks 2025-11-08 10:32:22 -05:00
Jeff Young 91602e8eb5 Resolve text variables in library table paths. 2025-11-05 17:30:23 +00:00
Jeff Young 386cd19975 Formatting. 2025-11-05 17:30:23 +00:00
Jon Evans baa29c1a58 Port footprint library table to new system 2025-11-04 06:54:53 -05:00
Jon Evans 8c11293c0d Fix creation of new project library tables
Fixes https://gitlab.com/kicad/code/kicad/-/issues/22054
2025-10-21 23:03:38 -04:00
Jon Evans c69cf6487e Push library table saving to LIBRARY_TABLE 2025-10-21 21:48:46 -04:00
JamesJCode 668a869e51 Code formatting 2025-10-18 22:19:23 +01:00
JamesJCode 3d768498b7 Synchronise access to LIBRARY_MANAGER::m_adapters 2025-10-18 22:14:16 +01:00
Jeff Young d5e9169b76 Coverity fixes. 2025-10-17 17:02:14 +01:00
Jon Evans 2f99045186 MSVC build fixes 2025-10-15 22:18:55 -04:00
Jon Evans 6e9811fd07 Support resetting symbol library table 2025-10-15 22:18:55 -04:00
Jon Evans d44f0aa513 Symbol library editing fixups 2025-10-15 22:18:54 -04:00
Jon Evans d85fb038ba Port design blocks to new library table system
Generalize library adapter code to be shared
2025-10-15 22:18:54 -04:00
Jon Evans de20a697f6 Fix up some library table dialog behavior for nested tables 2025-10-15 22:18:53 -04:00
Jon Evans 93b59f011a Generate default library tables from first-start wizard 2025-10-15 22:18:53 -04:00
Jon Evans 266c8c8754 Refactor and consolidate startup wizard
- Add welcome page
- Add settings migration
- Add library table configuration
- Combine sentry and updates into a privacy step
- Support in single-top mode
2025-10-15 22:18:52 -04:00
Jon Evans f6e1e24fa0 Fix unit tests
Get rid of mocking of settings, instead
use actual QA test environment settings

Make sure to load null project at fixture startup

Improve XNODE attribute handling

Fix netlist detection regex for prettified output
2025-10-15 22:18:52 -04:00
Jon Evans 25f3fd1b6a Port importers to new library system 2025-10-15 22:18:52 -04:00
Jon Evans d0cbc983be Add support for PCM libraries to library manager 2025-10-15 22:18:51 -04:00
Jon Evans 992be7fe35 Move symbol editor to new library system 2025-10-15 22:18:51 -04:00
Jon Evans fa38311e3f Report errors loading libraries and nested tables 2025-10-15 22:18:51 -04:00
Jon Evans edad0c2af1 Move library table editing dialog to new system 2025-10-15 22:18:50 -04:00
Jon Evans 194091acae Switch schematic editor to using new library system
ADDED: lazy loading of symbol libraries in chooser
2025-10-15 22:18:50 -04:00
Jon Evans 0752b43057 Create a new library manager responsible for table loading 2025-10-15 22:18:49 -04:00