fix: guard temp-dir cleanup so image/dir input doesn't crash main()#420
Open
MushiSenpai wants to merge 1 commit into
Open
fix: guard temp-dir cleanup so image/dir input doesn't crash main()#420MushiSenpai wants to merge 1 commit into
MushiSenpai wants to merge 1 commit into
Conversation
scripts/inference.py assigned save_dir_full only on the video-input branch, but cleanup called shutil.rmtree(save_dir_full) unconditionally. For image or image-directory input the variable is never bound, raising UnboundLocalError at cleanup (caught by the broad except, but only after the output is written, leaving temp files uncleaned and printing a spurious "Error occurred during processing"). Initialize it to None and guard the rmtree. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
scripts/inference.pycrashes during cleanup when the input is an image or animage directory (not a video).
save_dir_fullis assigned only on the video-input branch:…but cleanup calls it unconditionally:
So for image or directory input,
main()raisesUnboundLocalError: cannot access local variable 'save_dir_full'at cleanup. It'sswallowed by the surrounding
except Exception, but only after the output videois already written — so the user sees a spurious "Error occurred during processing:
…" and the temp frame directory / coord file are left uncleaned.
The fix
Initialize
save_dir_full = Nonebefore the input-type branch and guard the cleanup:Two lines, no behavior change for video input.
Validation
The bug is pure control flow. Reproducing
inference.py's exact structure(
save_dir_fullbound only in the video branch, referenced at cleanup):UnboundLocalErrorScope
Self-contained correctness fix, independent of #419 (the PyTorch 2.6
weights_onlyface-parse fix). No existing issue tracked this; happy to open one if maintainers prefer.
Disclosure: this fix was drafted with AI assistance (Claude) and reviewed, tested, and
submitted by me. The commit carries a
Co-Authored-Bytrailer.