Fix crash when deleting entity.