WGC regressed on exclusive fullscreen since 2.0.8: lock timeout misclassified as failure, invalidates WGC for all Windows consumers

Open
#103 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python

Research direction

Start with ok/device/capture_methods/windows_graphics.py and trace how get_frame_lock contention is handled through ok/device/capture_methods/update.py and base.py; also read ok/task/exceptions.py and the WGC probing path. Done means transient BUSY contention keeps WGC selected without poisoning its failure cache or falling back, while the probe respects its deadline and the documented lock-order and resource-safety invariants remain intact.

Written by the indexing model from the issue text.

Description

Summary

WindowsGraphicsCaptureMethod fails to produce any frame on exclusive fullscreen since ok-script 2.0.8. The new timeout-guarded get_frame_lock serialization (added by the commit that split start_or_stop/do_get_frame into _start_or_stop/_do_get_frame) turns ordinary lock contention into a TimeoutError. The capture-method selector then interprets that error as "WGC is broken", closes the instance, and falls back to BitBlt_RenderFull — which cannot capture exclusive fullscreen at all. Net effect: no frames, no recognition.

This affects every downstream consumer whose game runs exclusive fullscreen (ok-wuthering-waves "Enable Boxes" debug overlay draws nothing, tasks stall).

Environment

  • ok-script 2.0.8 (file sha 0ea7339), Windows 11 build 29680
  • Game: Wuthering Waves, exclusive fullscreen, single monitor 2880x1620 (150% DPI)
  • Capture preference: ['WGC', 'BitBlt_RenderFull']

Evidence (logs)

WARNING update: Windows Graphics Capture did not produce a frame within 1.5s
INFO    update: use BitBlt_RenderFull capture render_full: True
ERROR   bitblt_utils: capture_by_bitblt exception: BitBlt failed
ERROR   update_window_size hwnd_window: og.executor.pause pos_invalid: (-32000, -32000, 0, 0)
WARNING overlay  really: rect stuck at (0,0,2880x1620), boxes_enabled=True boxes_active=True

After reverting the 2.0.8 lock wrapper locally (raw revert), the same session logs:

INFO RefreshAdb update: use WGC capture
INFO start_controller  update:use WGC capture
INFO overlay: Win32 overlay presented: ... boxes_active=True

So WGC itself works; it is the new timeout/error semantics that disqualify it.

Root cause

ok/device/capture_methods/windows_graphics.py (2.0.8):

def do_get_frame(self):
    if not self.get_frame_lock.acquire(timeout=WGC_FRAME_WAIT_TIMEOUT):
        raise TimeoutError('Windows Graphics Capture is busy, ...')
    try:
        return self._do_get_frame()
    finally:
        self.get_frame_lock.release()
  • _do_get_frame() can hold get_frame_lock for up to WGC_FRAME_WAIT_TIMEOUT = 4.0s while waiting for a frame (windows_graphics.py frame loop).
  • On exclusive fullscreen the first frame is slower, so a concurrent caller (device refresh via update.py:50, another get_frame(), or an hwnd_window setter) contends for the lock.
  • A second caller times out and raises TimeoutError.
  • ok/device/capture_methods/update.py _capture_can_produce_frame() treats any exception from get_frame() as "did not produce a frame" → get_win_graphics_capture() closes the WGC instance and sets last_start_failure_key/last_start_failure_time (5s failure cache) → selector falls through to the next method.
  • BitBlt is documented as unable to capture exclusive fullscreen (bitblt.py:21-28), so the fallback also fails.

The 2.0.8 lock itself addresses a real cross-thread lock-order inversion (get_frame_lock -> self.lock vs self.lock -> get_frame_lock via close()), which the fix intends to guard. The bug is that lock contention is modelled as failure instead of a retryable BUSY state.

Additionally update.py's WGC_FIRST_FRAME_TIMEOUT = 1.5 cannot interrupt a single get_frame() call that internally blocks ~4s, so the probe budget is not actually honoured.

Impact

  • All ok-script Windows consumers preferring WGC, plus BrowserWGC which inherits WindowsGraphicsCaptureMethod.
  • Hard failure (not flaky) on exclusive fullscreen.
  • Recovery paths degrade to BitBlt which cannot handle this mode.

Proposed fix (durable)

Introduce a dedicated retryable CaptureBusyException and separate BUSY from genuine failure:

  1. CaptureBusyException in ok/task/exceptions.py (subclass Exception, not CaptureException).
  2. windows_graphics.py: start_or_stop() and do_get_frame() keep uniform get_frame_lock -> self.lock ordering, but acquire non-blocking; on contention raise CaptureBusyException (does not poison failure cache, does not close()).
  3. Add get_frame_for_probe(timeout) that honours an absolute caller deadline and propagates BUSY.
  4. base.py:get_frame() maps CaptureBusyException → None (normal consumers just retry next frame).
  5. update.py: get_win_graphics_capture() treats BUSY as "keep WGC selected, retry", never close()/cache; _capture_can_produce_frame() passes its remaining budget into get_frame_for_probe().
  6. hwnd_window setter swallows BUSY (defers target refresh; the lock owner validates capture_target_signature).

Invariants to preserve:

  • start_or_stop/do_get_frame acquire get_frame_lock before self.lock.
  • Only one frame request owns frame_requested/frame_event/last_frame.
  • close() waits for get_frame_lock before freeing D3D/GDI resources.
  • BUSY never writes the WGC failure cache nor triggers fallback.
  • WGC first-frame probing cannot exceed the outer deadline.

Full patch (4 files) is prepared; PR to follow.

Interim workaround used by ok-ww users

Revert the 2.0.8 wrapper locally (remove the acquire(timeout=...) in start_or_stop/do_get_frame), which restores WGC but re-exposes the concurrent-request and close()-vs-composite races the lock guarded against. Not recommended as a durable fix.


Downstream report: ok-oldking/ok-wuthering-waves#1736

Dominant language
Python
Stars
876
Forks
254
Avg merge
6h 52m
Merged PRs (30d)
13

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ok-oldking/ok-script

All issues in ok-oldking/ok-script

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.