SFML community forums

Help => Window => Topic started by: meta_leap on December 04, 2023, 08:31:32 pm

Title: Beginner mistake? No video modes listed
Post by: meta_leap on December 04, 2023, 08:31:32 pm
Still a bit new to C++ but years of coding in plenty other langs.

I'm really stumped on this mysterious phenomenon — the brief & simple portion of code:

    auto modes = sf::VideoMode::getFullscreenModes();
    if (modes.empty())
        modes.push_back(sf::VideoMode::getDesktopMode());
    std::printf(">>>>>>>>%d>>>\n", (int)(modes.size()));
    for (auto it = modes.begin(); it != modes.end(); it++)
        std::printf("- %dx%d @ %dbits/px\n", it->width, it->height, it->bitsPerPixel);
    std::printf("<<<<<<<<<\n");
    std::fflush(stdout);


And the baffling output:

>>>>>>>>210>>>
<<<<<<<<<


Not a single iteration with allegedly 210 vector items. Surely this must be some newbie mistake on my part?  =)

Thanks for pointers!

This is Linux with X11 (and tiled window manager i3). Compiling with gcc's g++ and SFML 2.5.1 libs. (My distro lags a bit with that kinda stuff.)
Title: Re: Beginner mistake? No video modes listed
Post by: Hapax on December 05, 2023, 06:44:32 am
I copied, pasted and ran your exact code and I got a sane result (approx. 30 items and they all listed) so I must presume there is some deeper issue.

Have you run just this exact code with nothing else and was that still an issue?

Do you normally have other lines of code too that might affect it?

Does it do this with a vector of other structures? Ints? Some custom structure of your own?
Title: Re: Beginner mistake? No video modes listed
Post by: meta_leap on December 05, 2023, 07:36:48 am
Merci, knowing now that it worked fine for you, I just got the idea to run the executable directly from my terminal, rather than as-usual via gdb (usually only F5-run my code from the editor) and voila, it works fine!  ;D  wonder what's missing under gdb runs but well, it's not mission-critical  =)
Title: Re: Beginner mistake? No video modes listed
Post by: eXpl0it3r on December 05, 2023, 11:13:11 am
If you run it manually via gdb then the application will by default just be loaded and if you want to run it, you have to type r.
Title: Re: Beginner mistake? No video modes listed
Post by: meta_leap on December 05, 2023, 11:31:18 am
Well I run-via-gdb it through a VSCode extension, so I guess it must be doing that part, because the window shows, the main loop enters and works, etc =)