Skip to content

Fix unhandled IOException when saving file in use by another process#161

Open
Slashxdd wants to merge 1 commit intoModuleArt:feature/new-webp-decoderfrom
Slashxdd:fix/save-file-in-use-exception
Open

Fix unhandled IOException when saving file in use by another process#161
Slashxdd wants to merge 1 commit intoModuleArt:feature/new-webp-decoderfrom
Slashxdd:fix/save-file-in-use-exception

Conversation

@Slashxdd
Copy link
Copy Markdown

Fixes #106

Problem

Saving (Ctrl+S or Save As) a file that is locked by another process throws an unhandled System.IO.IOException and crashes the app. The FileStream constructor on line 2483 had no exception handling.

Additionally, in the Save As path (dispose = true), originalImage was disposed before the save attempt — meaning a failed save would leave the user with a blank screen and their edits permanently lost.

Changes

SaveFile now returns booltrue on success, false on failure.

File I/O wrapped in try/catch IOException — on failure, shows a friendly status bar message ("Not saved: <reason>") instead of crashing.

dispose block moved to after a successful save — if Save As fails, the original image stays intact and the "unsaved changes" flag is preserved.

Callers updatedsaveBtn_Click and saveAsButton_Click only call setImageChanged(false) / OpenFile() when SaveFile returns true.

Before: IOException → unhandled → crash
After:  IOException → "Not saved: The process cannot access the file..." (status bar)

Resolves ModuleArt#106: saving over a file locked by another app threw an
unhandled IOException crashing the application.

Changes:
- SaveFile now returns bool (true = success, false = failure)
- File I/O wrapped in try/catch IOException; shows "Not saved: <reason>"
  via showSuggestion on failure
- dispose block moved to AFTER successful save so that if Save As fails,
  the original image remains visible and unsaved changes are preserved
- saveBtn_Click and saveAsButton_Click only call setImageChanged(false)
  and reload on successful save

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant