Skip to content

[rcore][sdl] Fix: Ordered monitor indexing for SDL3#5717

Open
somamizobuchi wants to merge 1 commit into
raysan5:masterfrom
somamizobuchi:fix-sdl3-display-indexing
Open

[rcore][sdl] Fix: Ordered monitor indexing for SDL3#5717
somamizobuchi wants to merge 1 commit into
raysan5:masterfrom
somamizobuchi:fix-sdl3-display-indexing

Conversation

@somamizobuchi
Copy link
Copy Markdown
Contributor

Problem

SDL3 changed monitor indexing from ordered to logical IDs which breaks many functions that requires monitor index as input.

Solution

Similar to how gamepads are currently stored, keep an array of displayIDs that are queried and set once during PlatformInit() and indexed during function calls that require them. The event polling does not currently handle display add/remove events so this LUT is only valid if no monitors are added/removed.

Tests

MacOS Tahoe 26.3
MacBook Air M3
SDL 3.4.2
Tested using example/core/monitor_detector with two monitors

Formatting + fix missing ifdef
@somamizobuchi somamizobuchi force-pushed the fix-sdl3-display-indexing branch from 7651d53 to 9400289 Compare April 4, 2026 18:25
@somamizobuchi somamizobuchi marked this pull request as ready for review April 4, 2026 18:25
@somamizobuchi
Copy link
Copy Markdown
Contributor Author

Hi @raysan5 I know this is not the priority for 6.0 but is there a timeline for review on this? Or anything I can do in the meantime?

@raysan5
Copy link
Copy Markdown
Owner

raysan5 commented Apr 22, 2026

@somamizobuchi Just wait a bit more, raylib 6.0 is being released tomorrow and I'm working on it at the moment, I will review it in the following weeks...

}

int numMonitors = 0;
SDL_DisplayID *displays = SDL_GetDisplays(&numMonitors);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an SDL_free(displays) is missing at the end

{
TRACELOG(LOG_FATAL, "PLATFORM: Failed to find monitors");
SDL_free(displays);
return -1;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to avoid ending the program if no monitor connected, maybe CORE.Window.ready = false?

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.

2 participants