Skip to content

Conversation

@dffdeeq
Copy link

@dffdeeq dffdeeq commented Dec 24, 2025

Fix screen capture to default to the game window resolution and correct dxcam region format (fixes #10).

Changes:

  • game_env.py: image_width/image_height default to None, so resolved window dimensions are used automatically
  • game_env.py: move observation_space initialization after window detection so it uses resolved dimensions
  • game_env.py: fix bbox/region format mismatch:
    • dxcam expects (left, top, right, bottom)
    • pyautogui expects (left, top, width, height)
      Previously both were fed the same format, which could result in an invalid region or partial capture.
  • play.py: add --width and --height CLI args for manual override

Usage:
automatically uses window resolution:
python scripts/play.py --process game.exe

override with custom resolution:
python scripts/play.py --process game.exe --width 1920 --height 1080

Testing:

  • Windows display scaling (DPI): 100%, 125%, 150%
  • Tested on multiple window sizes/resolutions (e.g. 1920x1080, 2560x1440)
  • Verified dxcam no longer throws "Invalid Region" and captured frames match the full game window

@dffdeeq dffdeeq force-pushed the fix-window-resolution branch from 73a9e5e to 04c8c5e Compare December 24, 2025 16:58
@heliar-k
Copy link

heliar-k commented Dec 26, 2025

I have found that this PR needs to be combined with this modification to work effectively in different DPI scaling ratios when I run the game in window mode.
ra1nty/DXcam#107 (comment)

@dffdeeq
Copy link
Author

dffdeeq commented Dec 26, 2025

I have found that this PR needs to be combined with this modification to work effectively in different DPI scaling ratios when I run the game in window mode. ra1nty/DXcam#107 (comment)

is dxcam really seeing a scaled output res on your setup, or is the window just slipping a bit off-screen at high DPI?
On my side dxcam still reports the correct output size even at 200% DPI, and the crash happens when the window/client rect goes out of bounds.

Example where the window fits (works) (image 1):

[WIN] GetWindowRect: (474, 68, 2086, 1326)
[WIN] ClientRect->Screen LTRB: (480, 120, 2080, 1320)

Example where it’s shifted a bit and extends past a 2560x1440 output (fails) (image 2):

[WIN] GetWindowRect: (1006, 260, 2618, 1518)
[WIN] ClientRect->Screen LTRB: (1012, 312, 2612, 1512)

then:

ValueError: Invalid Region: Region should be in 2560x1440

And the outer window frame is larger than the working area, so it is easy to go beyond it when using a high DPI

Screenshot 2025-12-26 160217 Screenshot 2025-12-26 154820

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.

ValueError: Invalid Region: Region should be in 2560x1440

2 participants