SFML community forums

Help => Window => Topic started by: TDSOJohn on June 28, 2022, 06:56:45 pm

Title: 0 fullscreen modes available on 14inch macbook pro
Post by: TDSOJohn on June 28, 2022, 06:56:45 pm
Hi everyone, not sure if this is the right place to ask, but I'm having a problem with fullscreen mode on the new 14inch macbook pro. If I copy and run the code from the SFML videomode documentation ( https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1VideoMode.php#a6815b9b3b35767d5b4563fbed4bfc67b ) it returns a vector of size 0.
If I try to manually force fullscreen video mode with
mWindow(sf::VideoMode(), "name", sf::Style::Fullscreen)
 
it crashes with error:

The requested video mode is not available, switching to a valid mode

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

I've also tried with a specific VideoMode resolution. Is it possible that no fullscreen videomode is available? Does anyone know how to solve this problem?
Title: Re: 0 fullscreen modes available on 14inch macbook pro
Post by: eXpl0it3r on June 29, 2022, 11:48:37 pm
That seems rather odd. Do you get any Desktop Modes at least?
Title: Re: 0 fullscreen modes available on 14inch macbook pro
Post by: TDSOJohn on June 30, 2022, 12:57:38 pm
That seems rather odd. Do you get any Desktop Modes at least?

I get:

3024x1964 - 32 bpp

by running sf::VideoMode::getDesktopMode() (which is the correct resolution of my screen).

I'm running a minimal example:

#include <vector>
#include <iostream>

#include <SFML/Window.hpp>


int main()
{

    // Display the list of all the video modes available for fullscreen
    std::vector<sf::VideoMode> modes = sf::VideoMode::getFullscreenModes();
    for (std::size_t i = 0; i < modes.size(); ++i)
    {
        sf::VideoMode mode = modes[i];
        std::cout << "Mode #" << i << ": "
                  << mode.width << "x" << mode.height << " - "
                  << mode.bitsPerPixel << " bpp" << std::endl;
    }

    sf::VideoMode defaultMode = sf::VideoMode::getDesktopMode();
    std::cout << defaultMode.width << "x" << defaultMode.height << " - "
              << defaultMode.bitsPerPixel << " bpp" << std::endl;

    sf::Window window(sf::VideoMode(800, 600), "My window");

    // run the program as long as the window is open
    while (window.isOpen())
    {
        // check all the window's events that were triggered since the last iteration of the loop
        sf::Event event;
        while (window.pollEvent(event))
        {
            // "close requested" event: we close the window
            if (event.type == sf::Event::Closed)
                window.close();
        }
    }

    return 0;
}

I'm able to run any window by creating a specific VideoMode, the only thing that doesn't work is fullscreen.
Title: Re: 0 fullscreen modes available on 14inch macbook pro
Post by: nelson on October 30, 2022, 05:41:04 am
I am running into the same problem on an M1 16" MacBook Pro.
Title: Re: 0 fullscreen modes available on 14inch macbook pro
Post by: md81544 on November 18, 2022, 11:46:35 am
I also see exactly the same symptoms on a Macbook Air M2.
Title: Re: 0 fullscreen modes available on 14inch macbook pro
Post by: Jonny on November 18, 2022, 12:46:26 pm
Which versions of macOS are you on?
Title: Re: 0 fullscreen modes available on 14inch macbook pro
Post by: md81544 on November 18, 2022, 12:49:48 pm
I am on the latest, Ventura 13.0.1.
Title: Re: 0 fullscreen modes available on 14inch macbook pro
Post by: eXpl0it3r on November 18, 2022, 01:12:31 pm
If anyone with a debugger could jump into the SFML code and see whether they're getting any values returned from the macOS functions, it could narrow down the problem: https://github.com/SFML/SFML/blob/2.6.x/src/SFML/Window/OSX/VideoModeImpl.cpp

Additionally, it might also be that the [ulr=https://github.com/SFML/SFML/blob/2.6.x/src/SFML/Window/OSX/cg_sf_conversion.mm#L53]deprecated CGDisplayModeCopyPixelEncoding function[/url] got broken and now the BPP isn't calculated correctly.
Title: Re: 0 fullscreen modes available on 14inch macbook pro
Post by: md81544 on November 18, 2022, 03:06:56 pm
I'd be happy to help but cannot step into the call.

I've tried building debug versions of the SFML libraries but cannot seem to get an arm64 build to work.

It's all been a bit trial-and-error by downloading the source running CMake - I can build x86_64 OK, but when I specify arm64 with CMAKE_OSX_ARCHITECTURES it won't work.

If anyone's got any links to notes on how to build SFML correctly on MacOS for arm I'd be grateful - it's likely I've missed some obviously-placed documentation :)
Title: Re: 0 fullscreen modes available on 14inch macbook pro
Post by: md81544 on December 10, 2022, 01:56:42 am
OK, finally got it working (my debugging, that is, not the code!).

in https://github.com/SFML/SFML/blob/2.6.x/src/SFML/Window/OSX/VideoModeImpl.cpp I put some debug output where I suspected the issue was, between lines 64 and 65 (the "continue"). These are the values I see, so it shows all of the modes are skipped because they are being reported as bigger than the desktop.

mode.size.x = 3840, desktop.size.x = 3420, mode.size.y = 2400, desktop.size.y = 2224
mode.size.x = 4096, desktop.size.x = 3420, mode.size.y = 2560, desktop.size.y = 2224
mode.size.x = 4096, desktop.size.x = 3420, mode.size.y = 2664, desktop.size.y = 2224
mode.size.x = 5120, desktop.size.x = 3420, mode.size.y = 3200, desktop.size.y = 2224
mode.size.x = 5120, desktop.size.x = 3420, mode.size.y = 3328, desktop.size.y = 2224
(Empty std::vector of modes returned)

Title: Re: 0 fullscreen modes available on 14inch macbook pro
Post by: md81544 on December 11, 2022, 08:12:53 pm
...and interestingly, if I remove the "continue" in getFullscreenModes() and let it add the "invalid" modes to the return vector, I can successfully get a fullscreen mode going in a test program on MacOS.
Title: Re: 0 fullscreen modes available on 14inch macbook pro
Post by: eXpl0it3r on December 12, 2022, 08:55:06 am
Is your desktop resolution then smaller than what the OS lets you select, i.e. is your resolution 3420x2224?

In your test program, can you also switch to one of the modes?
The comment makes me think that SFML wouldn't be able to change the resolution.
Title: Re: 0 fullscreen modes available on 14inch macbook pro
Post by: md81544 on December 12, 2022, 09:01:59 am
The native resolution of the macbook air M2 I'm using is 2560 x 1664, so is smaller than all the modes reported (I have no external display connected).

In the test program I just let it fall back to an unknown full-screen mode. It did display the "The requested video mode is not available, switching to a valid mode" messge, but it did go to a valid mode. I can experiment later to see which one it lets me select directly, if that helps?
Title: Re: 0 fullscreen modes available on 14inch macbook pro
Post by: md81544 on December 12, 2022, 09:14:55 am
OK, I tried it just now. These are the "invalid" modes I allowed getFullscreenModes() to return with my changes:

Mode #0: 5120x3328 - 32 bpp
Mode #1: 5120x3200 - 32 bpp
Mode #2: 4096x2664 - 32 bpp
Mode #3: 4096x2560 - 32 bpp
Mode #4: 3840x2400 - 32 bpp


and if I select any of these with, e.g.

sf::RenderWindow win(modes[0], "Test", sf::Style::Fullscreen);

then it works fine. The "fallback" I mentioned previously must have been because I chose 800x600 in fullscreen initially, rather than one of the fullscreen modes. So ignore that.

Once in any of those modes, if I do a

sf::CircleShape shape(50.f);

then it displays at the same size, regardless of mode selected, which makes me wonder if I'm getting native resolution, no matter which mode I select.

Title: Re: 0 fullscreen modes available on 14inch macbook pro
Post by: md81544 on December 12, 2022, 09:23:19 am
Actually, if I draw a circle in any of the fullscreen modes with

sf::CircleShape shape(550.f);

then it pretty much fills the vertical space of the fullscreen-ed screen. So does that mean the resolution being used is around 1100 pixels high? Not sure if this sheds any extra light on anything..?
Title: Re: 0 fullscreen modes available on 14inch macbook pro
Post by: eXpl0it3r on December 12, 2022, 11:27:25 am
Checking the specs it seems like 3456x2234 is the native resolution of you mac book: https://support.apple.com/kb/SP858?locale=en_US#:~:text=3456%2Dby%2D2234%20native%20resolution

Which means you may actually be using dome DPI scaling to get a different resolution.
I don't know how that's configured on macOS exactly, but do you have DPI scaling enabled?
Title: Re: 0 fullscreen modes available on 14inch macbook pro
Post by: md81544 on December 12, 2022, 11:49:45 am
Those specs you quote are for the macbook pro (which is what the OP is using). The specs for my M2 air are here: https://www.apple.com/uk/macbook-air-m2/specs/  and confirms 2560x1664 native resolution.

I don't have DPI scaling enabled as far as I am aware. The only option in settings seems to be some vague "Larger Text", "Default", or "More Space" which scales everything up or down. I tried all of them when I initially saw the problem and got the segfault that the OP initially reported on all of those settings.
Title: Re: 0 fullscreen modes available on 14inch macbook pro
Post by: md81544 on December 13, 2022, 07:42:20 am
So if I comment out the line here

https://github.com/SFML/SFML/blob/82b48a7520a2eb83576ec16d68ff9ea6d3d5d5bd/src/SFML/Window/OSX/cg_sf_conversion.mm#L94

then the modes which come back from getFullscreenModes() look more like what I'd expect for my Macbook Air M2:

Mode #0: 2560x1664 - 32 bpp
Mode #1: 2560x1600 - 32 bpp
Mode #2: 2048x1332 - 32 bpp
Mode #3: 2048x1280 - 32 bpp
Mode #4: 1920x1200 - 32 bpp


So the issue is possibly related to whether pixels or points are returned from CGDisplayModeGetWidth() etc ?

Edit:  I've just been looking at this thread https://stackoverflow.com/questions/42024942/cgdisplaymodegetwidth-height-sometimes-returns-pixels-sometimes-points

I wonder whether the comment "The scaling factor for all modes is not the same. Some are 1:1, some are 2:1. A mode of size 1680x1050 points does not imply a pixel size of 3360x2100" is relevant?
Title: Re: 0 fullscreen modes available on 14inch macbook pro
Post by: md81544 on December 15, 2022, 06:12:38 am
As this appears to be a bug, shall I summarise this in a github issue?
Title: Re: 0 fullscreen modes available on 14inch macbook pro
Post by: eXpl0it3r on December 15, 2022, 08:26:43 am
Yes, please do so! Thanks for investigating :)
Title: Re: 0 fullscreen modes available on 14inch macbook pro
Post by: md81544 on December 15, 2022, 10:26:52 am
https://github.com/SFML/SFML/issues/2300