Skip to main content
Inspiring
August 13, 2018
Question

Document `layersDescriptor` is null if only one layer exists

  • August 13, 2018
  • 1 reply
  • 1585 views

I'm having long term bugs with having one layer in the Document:

ReadLayerDesc *readLayerDesc = gFilterRecord->documentInfo->layersDescriptor;

But this only happens when there's one image (Assuming the layer array is not initialized when there's only one layer present), even looking through the (FilterRecordPtr)`filterRecord` the only accessable data is the `documentInfo` property...

What's the solution to this to acquire a single layer from the descriptor with the filterRecord?

This topic has been closed for replies.

1 reply

i73Author
Inspiring
August 13, 2018

Currently the only work around to this is for me to create a layer and just break out of my iteration of the `layersDescriptor` when it hit's the created layer.

I'm not a fan of hacks.

Tom Ruark
Inspiring
August 14, 2018

You probably have a background only document. Photoshop treats this kind of document special. In this case look at the targetCompositeChannels. We call it a simple document internally and as you have seen it reports NO layers. If you double click the "Background" text in the layers panel and give the layer a name you have now created a document with one layer. But that means no layers as you have one layer. So you need a document with more than one to get "layers" to have something besides NULL. Check out the PoorMans example and how it deals with this situation.

Recap:

Test with a "Background" only.

Test with a layer.

Test with a "Background and a layer.

Test with multiple layers.

i73Author
Inspiring
August 16, 2018

Thanks for the reply Tom, just to confirm.

The PS document changes when there's only one layer in the scene? (I understand there's not a list / "Layers" of them, it's just a little bit backwards from a technical OOP standpoint to switch a vector / list out for a object when they both contain the same properties in the end)

None of the artists use background layers, and if one is found I remove it in the automation process, since the background layer contain different properties than a layer.