Skip to content

fix(task): raise CaptureException when frame capture stalls#72

Open
nagameTW wants to merge 1 commit into
ok-oldking:masterfrom
nagameTW:fix/frame-stall-capture-exception
Open

fix(task): raise CaptureException when frame capture stalls#72
nagameTW wants to merge 1 commit into
ok-oldking:masterfrom
nagameTW:fix/frame-stall-capture-exception

Conversation

@nagameTW

Copy link
Copy Markdown

Problem

ok-oldking/ok-wuthering-waves#1466 — a farming task dies with AttributeError: 'NoneType' object has no attribute 'shape' in FeatureSet.check_size after the user locks the screen / turns off the monitor.

From the log attached to that issue: right before the crash the capture layer logs no frame for 10 sec, try to restart twice — a transient stall during the lock-screen transition. next_frame(time_out=6) returns None after its timeout, the frame property passes that None through, and the recognition path crashes. All three tracebacks in the log funnel through FeatureSet.check_size, so a stall of ~10-20 seconds permanently kills the running task.

Fix

  • TaskExecutor.frame now keeps retrying next_frame(), so transient capture stalls no longer kill the task — it resumes once frames come back.
  • If no frame arrives for frame_stall_timeout seconds (new constructor param, default 60), it raises the existing CaptureException, which the executor main loop already handles (capture_error signal + task stopped with a clear message) — instead of the raw AttributeError.
  • The error-handler screenshot path now uses the cached _frame instead of the frame property, so error handling itself can never raise CaptureException.

Callers that want a nullable frame still have nullable_frame(); no caller relies on the frame property returning None (they would all crash on it).

Tests

tests/test_task_executor_frame.py, following the TaskExecutor.__new__ pattern of test_task_executor_queue.py:

  • capture stalled → raises CaptureException
  • capture recovers mid-stall → returns the frame
  • frame already present → returned directly, no capture call

Note: developed on Linux where the package cannot be imported (win32 deps), so the tests are written but were not executed here — verified via py_compile and review. Please run them on Windows before merging.

When screen capture produces no frames for a while (e.g. Windows lock
screen transition, WGC restart), next_frame() times out and the frame
property returned None, crashing every downstream consumer with
AttributeError: 'NoneType' object has no attribute 'shape' in
FeatureSet.check_size and killing the running task.

The frame property now keeps retrying next_frame() so transient stalls
no longer kill the task, and raises the existing CaptureException
(already handled by the executor main loop via capture_error) after
frame_stall_timeout seconds (default 60, constructor param) when
capture is really gone.

Also use the cached _frame in the executor error handler screenshot
path so error handling itself can never raise CaptureException.

Fixes ok-oldking/ok-wuthering-waves#1466
@sonarqubecloud

Copy link
Copy Markdown

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