[BUG] 22.4 Layer references do not match same layers from different arrays

Apparently 22.4 broke a lot of things. One of them is how layers are referenced (I guess)

Here’s a simple snippet:

    const doc = app.activeDocument;
    const activeLayers = doc.activeLayers.filter(l => doc.layerTree.includes(l));

Exact same situation and doc.layerTree.includes(l) on 22.3.1 still returns true if selected layer is on a top level tree, but 22.4.0 and 22.4.1 return false. My whole (payed) plugin is based on that selection and it doesn’t work anymore. Not cool at all :confused:

Any advice what would be the best approach to fix this? Or simply loop both arrays and check for layers IDs?


P. S. Is this the best place to report such bugs?

Best I can tell, it’s a bug.

To work around the problem until it’s fixed, you could match the _id field instead (AFAIK, this should continue to work after it’s fixed too):

const activeLayers = doc.activeLayers.filter(l => doc.layerTree.some(c => c._id === l._id));

FYI @Barkin / @heewoo / @samgannaway – Looks like a bug in the layer map cache. AFAICT, a new Layer object is always being created, rather than the old one being re-used if it exists. (Check src/dom/Layer.ts#PSLayer’s history – there’s a change around 3mo ago that may be involved – Pull #118)

1 Like