The bug was that turtlepaint(), which is called from the WM_PAINT message handler, threw a stopping error. This stopping error would be misinterpreted when the editor was closed, as having originated while processing the contents of the editor.
The fix is to make turtlepaint() not throw a stopping error.