This change arose from a problem reported by Geoff Stone in this Comm Center thread ( located closer to the end, tmpDoc failure). Trying to use a MaxIm.Document handle after calling its SaveFile() method can lead to interesting results. Alter the code so that the Document is always closed after SaveFile() and then re-opened with a fresh MaxIm.Document if needed later.
This appears to be limited to systems with SSD and fast CPU.