raysan5/raylib

[rcore_desktop] Upon entering fullscreen, uses original window size

OilyFishMan opened this issue · 6 comments

Issue description

Upon running the procedure ToggleFullscreen(), raylib reports "GetScreenWidth()" and "GetScreenHeight()" as values set before SetWindowSize(x, y). However, without ToggleFullscreen(), the original values are kept for one frame then immediately restored to correct full resolution.

Environment

Platform backend: DESKTOP (GLFW)
OS: Fedora 39 x86_64
Desktop: Gnome X11
OpenGL version: 4.6
GPU: Integrated

Issue Screenshot

Screencast from 2024-04-22 18-22-46.webm
Screencast from 2024-04-22 18-26-19.webm

Code Example

#include <stdio.h>
#include <raylib.h>

int main(void)
{
    InitWindow(1, 1, "Application");
    int display = GetCurrentMonitor();
    SetWindowSize(GetMonitorWidth(display), GetMonitorHeight(display));
    ToggleFullscreen();
    while (!WindowShouldClose()) {
        BeginDrawing();
        DrawRectangle(0, 0, GetMonitorWidth(display), GetMonitorHeight(display), RAYWHITE);
        printf("%d %d\n", GetScreenWidth(), GetScreenHeight());
        DrawRectangle(0, 0, GetScreenWidth() / 2, GetScreenHeight() / 2, RED);
        EndDrawing();
    }
    CloseWindow();
    return 0;
}

It seems that the actual resizing of the window contents is done in the WindowSizeCallback after the first call to EndDrawing() in the game loop.
However, there is this line that prevents CORE.Window.screen.width and height to be updated in the callback:

if (IsWindowFullscreen()) return;

Commenting this line solved the issue for me, but I presume is there for a reason.

That's really strange. To me this definitely doesn't seem like expected behavior.

Commenting this line solved the issue for me, but I presume is there for a reason.

There should probably be a comment there explaining that reason... I don't know at the moment...

I ran the sample code under msys2 and Fedora.
It worked well in msys2. GetScreenWidth() and GetScreenHeight() would return the correct full resolution at the first frame. However, the same situation like this issue occurred in Fedora.

I found the reason is when WindowSizeCallback() is called.
In msys2, WindowSizeCallback() will be called after calling SetWindowSize() ( just before ToggleFullScreen()), but in Fedora, it will be called after EndDrawing().
Because of that, we can get the correct value after ToggleFullScreen() in msys2 but can't in Fedora.

@archewashi Thanks for the further investigation and provided details! It seems a platform-dependant issue, that's usually difficult to address...

I guess the reason is the glfw commands to X11 are asynchronous (X11 handle commands asynchronously). XFlush may solve this problem, but it should be a bit dangerous.