Skip to content

Fix hang when theme thumbnail cannot be generated - #699

Open
rmbakker88 wants to merge 1 commit into
t1m0thyj:mainfrom
rmbakker88:fix/thumbnail-hang
Open

Fix hang when theme thumbnail cannot be generated#699
rmbakker88 wants to merge 1 commit into
t1m0thyj:mainfrom
rmbakker88:fix/thumbnail-hang

Conversation

@rmbakker88

Copy link
Copy Markdown
Contributor

Fixes #696

Importing a theme whose images GDI+ cannot decode leaves the import dialog stuck on "Generating thumbnails, please wait..." forever, with no error and nothing in the log. .webp is the easy way to hit it, but a truncated JPEG does the same thing.

GetThumbnailImage decodes with System.Drawing, which throws ExternalException (or ArgumentException) for a format it cannot read. LoadThemes only caught OutOfMemoryException, so the exception escaped the loop and faulted the background task started by LoadImportedThemes — which closes the dialog on the line after LoadThemes returns, so thumbnailsLoaded was never set and OnImportDialogClosing kept cancelling the close.

Three changes, all in ThemeDialogUtils:

  • Catch every exception per theme instead of just OutOfMemoryException, and log it with the theme id, so the underlying exception ends up in debug.log when debug logging is on. The existing FailedToCreateThumbnail dialog still shows, now marshalled onto the UI thread rather than raised from the background task.
  • Release loadSemaphore from a finally, and only when the wait actually acquired it. Previously the release was the last statement of the method, so an escaping exception stranded the semaphore and the next load blocked for the full 60s.
  • Close the import dialog from a finally in LoadImportedThemes, so the import completes even when generating thumbnails throws. This is the part that actually ends the hang.

This deliberately does not change which formats are supported — an undecodable image still fails, it just fails visibly and lets the app carry on. Adding WebP support is #690, and a separate PR.

Most of the diff is re-indentation from the new try block; ?w=1 shows the real change.

Testing

  • dotnet test --filter "type!=system" — 7 passed, unchanged from main.
  • Manually, importing a .ddw whose images are .webp: on main the import dialog hangs indefinitely and the app has to be killed; with this change the import completes, the theme is reported as "Failed to generate thumbnail: The image could not be loaded", and the app stays usable.
  • Importing a normal .jpg theme behaves as before.

GetThumbnailImage decodes images with System.Drawing, which throws
ArgumentException or ExternalException for formats GDI+ cannot read.
LoadThemes only caught OutOfMemoryException, so any other decode failure
escaped the loop, faulted the background task started by
LoadImportedThemes, and left the import dialog stuck on "Generating
thumbnails, please wait..." with no error and nothing logged. The
loadSemaphore was leaked at the same time, so later loads blocked for 60
seconds.

Catch all exceptions per theme and log them, release the semaphore from a
finally block (and only when it was acquired), and close the import
dialog from a finally block so importing always completes.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

LoadThemes can proceed even when loadSemaphore.Wait(60000) times out, allowing concurrent loads and risking UI state races.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR addresses a hang in the theme import flow when thumbnail generation fails (e.g., unsupported/corrupt image formats causing System.Drawing to throw), ensuring the import dialog can complete and failures are surfaced/logged instead of leaving the UI stuck.

Changes:

  • Broaden per-theme exception handling during thumbnail generation and log failures with theme id, while marshaling error UI handling onto the UI thread.
  • Ensure loadSemaphore is released via finally to avoid stranding the semaphore on exceptions.
  • Ensure the import dialog is closed from a finally block so imports complete even if thumbnail generation throws.
File summaries
File Description
src/ThemeDialogUtils.cs Adds robust exception handling and finally cleanup to prevent the import dialog hang when thumbnail generation fails.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/ThemeDialogUtils.cs
Comment on lines +55 to 56
bool semaphoreAcquired = loadSemaphore.Wait(60000);

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.

Importing a theme whose images cannot be decoded hangs on "Generating thumbnails, please wait..."

2 participants