Removed layer from canvas before deleting layers from registry (It can cause null pointer error to those layers). Thanks to assefay.