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

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>
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..."

1 participant