Open In progress bug report

Footprint/layer-map verbs fill PcbLibs with 1024 mechanical layers (GetMechanicalLayer loops create layers)

MartyPM · ·marked in progress by kcknox

altium-bridge 0.2.118 (agent script AdomAgent_de5bd2abe4.pas) · Altium Designer Develop 26.x (AD 26.10.1.5 installed alongside) · Windows 11 (Hydrogen local workspace)

What happens

PcbLibs that the bridge's footprint / layer-map verbs have worked on end up with all 1024 mechanical layers defined. Once such a library is open, Altium lists Mechanical 1..1024 in Preferences » PCB Editor » Layer Colors. A fresh Altium instance that has not loaded the library shows only Mechanical 1..16, as normal.

Layer records counted in the saved files (LAYER_V8_<n>NAME= records, highest MECHANICAL<n>):

PcbLib layer records highest mechanical layer
Organisation footprint template (never touched by the bridge) 71 66
Library built with altium_layer_map + altium_footprint_from_land_pattern / altium_edit_footprint (2026-12-01) 1048 1024
Second library, same verbs (2026-12-02) 1086 1024

Likely cause

In Altium, looking a mechanical layer up by its number creates it in the open document, and the next save keeps it. The agent script loops over every possible mechanical layer:

  • MechNoOfKind: For N := 1 To 1024 Do ... Board.MasterLayerStack.GetMechanicalLayer(N)
  • MechNoNamed: For N := 1 To 1024 Do ... GetMechanicalLayer(N)
  • FreeMechNo: For N := 17 To 1024 Do ... GetMechanicalLayer(N)

(around lines 1700-1760 of AdomAgent_de5bd2abe4.pas in %LOCALAPPDATA%\Adom Bridge\bridges-cache\altium\agent\ADDevelop\).

Confirmation from our own tooling: a verify script of ours looped LayerObject_V7(LayerUtils.MechanicalLayer(i)) for i = 1..128 (read-only intent). After it ran and the library was saved, a clean 71-record library had 152 records with Mechanical 67..128 added. Removing that loop stopped it.

Why it matters

Probably the cause of Altium hangs we saw. Attaching a STEP to a footprint (ComponentBody.ModelFactory_FromFilename + AddPCBObject) hung Altium twice in a 1024-layer library (window "not responding", had to be killed). The same attach on the same footprint, in a library recreated from the template (71 layer records), completed immediately.

Suggested fix

  • Never look mechanical layers up by number in a loop. Iterate only the layers the document already has, or keep a cache of known layers.
  • Find a typed layer by kind / name among existing layers only; when a new layer is needed, create exactly one.
  • Possibly add a guard to the verbs: report (and refuse to save) when a library's mechanical layer count jumps.

Repro (expected; inferred from the layer counts and the code above, not re-run in isolation)

  1. Copy a template PcbLib with few mechanical layers; count LAYER_V8_<n>NAME= records (e.g. 71).
  2. Run altium_layer_map {action:'from_template', ...} and altium_footprint_from_land_pattern on it; save.
  3. Count again: 1024 mechanical layers.

Related: #43 (the footprint verbs also create Mechanical 1 and 9 "Adom.SolderBalls" when nothing is drawn on them).

4 Replies

Colby Knox marked this in progress ·
Colby Knox ·

Thanks for tracking this down. The layer-search loops you point at are the cause as far as I can see, and the hang you saw is a good reason to treat this as urgent. I'm fixing it now so the footprint and layer-map verbs only read the mechanical layers a library already has, and create at most the one layer they need.

I'll also look at cleaning up a library that already has the extra layers, and post here when a fixed build is out.

Colby Knox ·

Fixed in altium-bridge 0.2.119.

Your diagnosis was right: looking a mechanical layer up by its number creates it, and the next save keeps it. The footprint and layer-map verbs now find typed and named layers among the library's enabled mechanical layers only (Altium lists those without creating any), and make at most the one layer a graphic needs.

Checked on Altium Designer 26.11.1 and Develop, with a QFN-16 from altium_footprint_from_land_pattern and a typed layer map (fab, courtyard and 3D body on AssemblyTop, CourtyardTop and 3DBodyTop):

layer records after save highest mechanical layer file size
fresh library 56 32 108 KB
0.2.118 1048 1024 1.08 MB
0.2.119 56 32 130 KB

The footprint itself is identical in both.

Libraries that already have the extra layers: copy their footprints into a fresh library (your template works) with altium_xcopy_footprint {fromLib, from, toLib} on 0.2.119. The copy carries only the layers its graphics use. A footprint copied out of a 1048-record library came out at 56 records, with every pad and graphic intact.

Colby Knox ·

altium-bridge 0.2.120 makes the repair easier:

  • altium_layer_map {action: "get", libraryPath} now reports libraryLayers for a .PcbLib or .PcbDoc, read from the saved file: layerRecords, mechanicalLayers, mechanicalLayersOn and bloated (true when all 1024 mechanical layers are defined). A library from 0.2.118 read 1048 / 1024 / 8 / true; its repaired copy read 56 / 32 / 7 / false.
  • altium_xcopy_footprint creates toLib if it doesn't exist yet, and now copies the footprint's height (it was left at 0).

Measured copy result: pads with their own pad stacks, embedded STEP bodies, typed-layer graphics and the description all come through identical. Close the library in Altium before swapping files on disk: Altium works on its in-memory copy, and a later save of it would write the old library back. A swapped-in library at the same path kept working for SchLib footprint links and an IntLib build.

Boards can be affected too: placing footprints on typed layers with 0.2.113–0.2.118 left some boards with 1024 layers. They still work, only larger, and libraryLayers shows it.

Colby Knox ·

The fix and the repair tools are now public: altium-bridge 0.2.120 is on the public tier, so a normal update picks it up.

Log in to reply.