Incorrect values from SDL_GetWindowSafeArea

I have 2 problems with SDL_GetWindowSafeAreareturning wrong results, possibly related.

First on iPadOS when I rotate the iPad from portrait to landscape and my resize event handler calls SDL_GetWindowSafeArea, the values returned are for the unrotated (portrait oriented) device:

resize: w_width = 2752, w_height = 2064, event.width = 2752, event.height = 2064, sRA.w = 2062, sRA.h = 2648, sRA.x = 0, sRA.y = 64

The first width & height are those set for the app by the resize handler. The second are the values in the event. The remainder are the values returned by SDL_GetWindowSafeArea multiplied by the value returned by SDL_GetWindowDisplayScale, except 1 is subtracted from the returned width in an attempt to work around the second problem.

The second problem is that when dragging to resize the app on macOS the returned width and height are a few pixels off from those in the event. In this case, WSA.x = WSA.y = 0 as there is nothing to protect. I have seen as much as 30 pixels difference.

The documentation says the function must be called from the main thread. On macOS I have a main loop calling SDL_PumpEvents() so the handler should be called by the main thread. On iPadOS, there is no main, so I suppose that event handler is called by some other thread and that may be the cause of the problem there.

I need the information at resize time to re-prepare a bunch of Vulkan stuff used by a text overlay renderer which must render in the safe area. If it is invalid to call SDL_GetWindowSafeAreain the event handler, how best to handle this?

Can you try with the latest SDL main code? We recently fixed some orientation issues on iPadOS.

I’m using SDL via vcpkg. Is the latest main available in vcpkg?

@slouken Please answer my question about the latest code and also that about calling from the main thread.

Any idea what is causing the difference between the event sizes and the WindowSafeArea sizes on macOS?

To check your version number:

#include <SDL3/SDL.h>
#include <SDL3/SDL_revision.h>

int main()
{
        SDL_Init(SDL_INIT_VIDEO);
        SDL_Log("SDL Version: %d.%d.%d", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_MICRO_VERSION);
        SDL_Log("-------------- More Specifically -----------------");
        SDL_Log("SDL Version compiled against: %s", SDL_REVISION);
        SDL_Log("SDL Version linked against: %s", SDL_GetRevision());
        SDL_Quit();
}

Thanks but that is not the version I need to check. I need to find out what is the latest version in vcpkg, which I have discovered I can do by using git log on my clone of the vcpkg repo (it’s 3.4.18) and I need to see which version the orientation fixes are in. They are not released yet. They were committed to main last week while 3.4.18 was released 29 days ago so I need to wait a while longer.