BUG:383933 Don't crash when changing layer types in gmic
Check whether the node is still valid before using them.