pdImage: fix potential error when deleting a bunch of layers in a row