Skip to content

fix(tests/video_cmp): initialize grab_failure_cnt before the compare loop - #2317

Open
Anai-Guo wants to merge 2 commits into
TEN-framework:mainfrom
Anai-Guo:fix-grab-failure-cnt-init
Open

Anai-Guo wants to merge 2 commits into
TEN-framework:mainfrom
Anai-Guo:fix-grab-failure-cnt-init

Conversation

@Anai-Guo

Copy link
Copy Markdown

Problem

compare() in the ffmpeg integration test helper (video_cmp.py) counts consecutive failed frame grabs to bail out of a potential endless loop:

for _ in range(frame_count):
    retval1 = video1.grab()
    retval2 = video2.grab()

    if not retval1 or not retval2:
        grab_failure_cnt += 1          # <-- never initialized
        if grab_failure_cnt >= 10:
            raise Exception("Grab failed too much ...")
    else:
        grab_failure_cnt = 0

grab_failure_cnt is only ever assigned in the else branch (reset to 0 after a successful grab). The very first time either video1.grab() or video2.grab() returns False, grab_failure_cnt += 1 executes before any binding exists, so Python raises UnboundLocalError: local variable 'grab_failure_cnt' referenced before assignment — masking the real "grab failed" condition the counter was meant to detect.

Fix

Initialize grab_failure_cnt = 0 alongside similar before the loop, so the failure path counts as designed and the endless-loop guard can trigger.

Both identical copies (ffmpeg_basic/ and ffmpeg_bypass/) are fixed.

🤖 Generated with Claude Code

…loop

compare() increments grab_failure_cnt on a failed frame grab, but the counter is only ever assigned in the else branch (set to 0 on a successful grab). The first time video1.grab()/video2.grab() returns False, `grab_failure_cnt += 1` runs before any binding exists, raising UnboundLocalError instead of counting the failure and eventually raising the intended "Grab failed too much" guard. Initialize the counter to 0 alongside `similar` so the failure path works as designed.
…loop

compare() increments grab_failure_cnt on a failed frame grab, but the counter is only ever assigned in the else branch (set to 0 on a successful grab). The first time video1.grab()/video2.grab() returns False, `grab_failure_cnt += 1` runs before any binding exists, raising UnboundLocalError instead of counting the failure and eventually raising the intended "Grab failed too much" guard. Initialize the counter to 0 alongside `similar` so the failure path works as designed.
@Anai-Guo
Anai-Guo requested a review from halajohn as a code owner September 10, 2026 07:04

This branch has not been deployed

No deployments
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