Fix a crash in layer node after removal of layer from registry.

A crash may occur when using custom layer tree in composer legend and layer from that tree is removed from registry.
This would happen only in some code paths.