Skip to content

[rcore][GLFW] Fix window centering overflow with unsigned screen size - #6119

Open
nfvelten wants to merge 1 commit into
raysan5:masterfrom
nfvelten:fix-6002-unsigned-overflow
Open

[rcore][GLFW] Fix window centering overflow with unsigned screen size#6119
nfvelten wants to merge 1 commit into
raysan5:masterfrom
nfvelten:fix-6002-unsigned-overflow

Conversation

@nfvelten

@nfvelten nfvelten commented Sep 2, 2026

Copy link
Copy Markdown

Fixes #6002.

Size is { unsigned int width; unsigned int height; } (rcore.c), so in InitPlatform() the centering subtraction is done in unsigned arithmetic. When the window is larger than the monitor workarea on either axis it wraps around instead of going negative, and the division by 2 keeps it positive:

monitor 1366x768, window 5000x3000
before:  pos = (2147481831, 2147482532)
after:   pos = (-1817, -1116)

X11 truncates that to 16 bits, which is where the reported off-screen window comes from (0xF8E7 = -1817). This is also why SetWindowPosition(0, 0) right after InitWindow() works around it.

Casting to int is enough, no extra branches. Tested on Linux/X11:

  • 5000x3000 window on a 1366x768 monitor: before the window landed off-screen at (-1817, -1116), after it is placed at (0, 0) and is visible.
  • 640x480 window on the same monitor: centered at (363, 144) before and after, unchanged.

I could not test the reporter's exact setup (portrait primary monitor on Windows), only the same code path with an oversized window.

CORE.Window.screen/render sizes are unsigned, so the subtraction against
the monitor workarea wraps when the window is larger than the monitor,
producing a huge positive position instead of a negative one.
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.

[rcore][GLFW] Bad window placement with portrait displays

1 participant