Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Fullscreen window but getSize() incorrect (ubuntu)  (Read 4902 times)

0 Members and 1 Guest are viewing this topic.

anaskiee

  • Newbie
  • *
  • Posts: 9
    • View Profile
Fullscreen window but getSize() incorrect (ubuntu)
« on: December 08, 2015, 08:34:34 am »
Hello,

I'm working on a project using SFML with a friend and I have a issue about the value returned by window.getSize().

I'm asking to create a fullscreen window with videoMode set to 800x600 and 32 bits per pixels.
    uint32 style = sf::Style::Fullscreen;
    auto videoMode = sf::VideoMode(800, 600);
    window.create(videoMode, title, style, contextSettings);

The native resolution of my computer is 1600x900.
The problem, is that sometimes, the following call :
    window.getSize()
returns 800x600 instead of 1600x900.

This problem appears randomly when i'm launching the program directly from a command line. But, when i launch it from KDevelop and don't break into the code, the reproduction rate is 100%. However, if I break, i cannot reproduce. It whould have been to easy  :)

I do not any warning messages on stdout except one which is also there when i don't encounter the bug, so I guess, it's not the problem.

I found the following bug on the github repository : https://github.com/SFML/SFML/issues/921
But, it's not exactly the same. I also encountered it, but it does not break the visual display.

Thank you,
anaskiee

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Fullscreen window but getSize() incorrect (ubuntu)
« Reply #1 on: December 08, 2015, 08:51:48 am »
The size is 800x600, since that's what you request. Switching to fullscreen makes your whole monitor change its resolution to 800x600. If sometimes it reports 1600x900, it's probably because you do something that causes the video mode to be restored, like losing focus on your SFML window.
Laurent Gomila - SFML developer

SeriousITGuy

  • Full Member
  • ***
  • Posts: 123
  • Still learning...
    • View Profile
Re: Fullscreen window but getSize() incorrect (ubuntu)
« Reply #2 on: December 08, 2015, 10:18:21 am »
I think you might find sf::VideMode::getDesktopMode() usefull  ;)

anaskiee

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Fullscreen window but getSize() incorrect (ubuntu)
« Reply #3 on: December 08, 2015, 10:27:34 am »
Getting 800x600 as window size is the expected behavior... My monitor resolution should always be changed.
So, I'm going to investigate why I get 1600x900 most of the time.
I was not debugging the right thing ! :)

Another question : is there an event emitted when resolution is changed/forced ?
Since, it's not related to the window, i guess not.

edit: typo
« Last Edit: December 08, 2015, 10:30:56 am by anaskiee »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Fullscreen window but getSize() incorrect (ubuntu)
« Reply #4 on: December 08, 2015, 11:13:27 am »
Quote
Another question : is there an event emitted when resolution is changed/forced ?
Nop, but why would you like to be informed when the monitor resolution changes?
Laurent Gomila - SFML developer

anaskiee

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Fullscreen window but getSize() incorrect (ubuntu)
« Reply #5 on: December 08, 2015, 01:49:54 pm »
I was just wondering, it's not related to my problem (except if I was somehow dropping it).

However, if resolution is cached in the programm, and that some elements are drawn at a relative position
myObject.setPosition(0.5*resolution.x, 0.5*resolution.y)
for instance, then it could be usefull to be notified.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Fullscreen window but getSize() incorrect (ubuntu)
« Reply #6 on: December 08, 2015, 02:31:49 pm »
You always work with window or view size, not screen resolution.
Laurent Gomila - SFML developer

anaskiee

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Fullscreen window but getSize() incorrect (ubuntu)
« Reply #7 on: December 08, 2015, 09:32:35 pm »
I did some other tests.

Actually, my monitor resolution is never changed when I request a VideoMode of 800x600x24 (I discovered that my screen supported only 24 bits per pixels according to nvidia driver). The desktop resolution does not change as it happens with some others games on windows.
So, as you said, it seems that the resolution is quickly set to 1600x900, that's why I get this last one most of the time.

By the way, I displayed
auto videoMode = sf::VideoMode(800, 600, 24);
std::cout << "isValid " << videoMode.isValid() << std::endl;
And the function isValid() returns true (1). So that should be fine, except if for some reasons, it's not really valid...
(I also have this VideoMode listed by sf::VideoMode::getFullscreenModes()).

I also displayed
sf::VideMode::getDesktopMode()
and I always get 1600x900x24.

Now that I'm writing this, I just get that since I always have the problem, and not only times to times. The message I talked about is probably usefull  :o
Failed to set new screen configuration
I will investigate why I get this fail message.

anaskiee

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Fullscreen window but getSize() incorrect (ubuntu)
« Reply #8 on: December 09, 2015, 08:04:34 am »
Hi,

To sum up, the following scenario is happening :
- I'm requesting to create a fullscreen window with a resolution of 800x600 which is valid
- the call setVideoMode(mode) of WindowImplX11 always fail to set this mode properly
Failed to set new screen configuration
- so my resolution is back to the native one
- but sometimes, window.getSize() is still stucked to 800x600. Most of the time, I get 1600x900 as expected thought.

I tried the following fix :
https://github.com/SFML/SFML/commit/81fdc96c135ecb54def973ed42deeb3af3d4f5c1
Actually, it fixes indirectly the problem. I still get the message "Failed to set new screen configuration".
But, my window is not anymore switch to fullscreen. I get a 800x600 window and getSize() is correct (800x600).

Edit: By the way, my window manager is Compiz

anaskiee

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Fullscreen window but getSize() incorrect (ubuntu)
« Reply #9 on: December 10, 2015, 08:36:16 am »
No ideas ?  :(

I have some doubts about the resolutions returned by getFullscreenModes().
I shouldn't get 32 bitsPerPixels since it's not supported by my monitor, right ?

Also, the output of the command xrandr is
Screen 0: minimum 8 x 8, current 1600 x 900, maximum 16384 x 16384
VGA-0 disconnected (normal left inverted right x axis y axis)
LVDS-0 connected primary 1600x900+0+0 (normal left inverted right x axis y axis) 382mm x 214mm
   1600x900      60.12*+
DP-0 disconnected (normal left inverted right x axis y axis)
HDMI-0 disconnected (normal left inverted right x axis y axis)
DP-1 disconnected (normal left inverted right x axis y axis)

I can switch to 800x600 with
xrandr -s 800x600
It's supported, but not listed in the default modes, tho'.

However, in nvidia-settings, all resolutions are well listed in "X Server Display Configuration" tab.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10818
    • View Profile
    • development blog
    • Email
Re: Fullscreen window but getSize() incorrect (ubuntu)
« Reply #10 on: December 10, 2015, 08:41:56 am »
When do you call window.getSize()?
The size is apparently only applied properly once the even pump starts running.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

anaskiee

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Fullscreen window but getSize() incorrect (ubuntu)
« Reply #11 on: December 10, 2015, 10:06:04 am »
I tested this.

I tried to displayed getSize() in the main loop to see if the size returns to the right value after a few seconds.
But, it didn't. The size didn't change after many frames.

Though, it's possible to make it return to its right value by switching virtual desktop window (ctrl+alt+right) or focusing on another program (ctrl+tab or even breaking in IDE).

anaskiee

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Fullscreen window but getSize() incorrect (ubuntu)
« Reply #12 on: December 10, 2015, 11:08:08 pm »
I found out that
switchToFullscreen()
of
WindowImplX11::WindowImplX11(VideoMode mode, const String& title, unsigned long style, const ContextSettings& settings)
is probably linked to my problem.

When I comment it, getSize() is consistent to 800x600. I never get a random size.
Even better, an event resized (to 1600x900) is fired, so my application is switched to fullscreen without this line ! With this line, I never get this event.

But, I still don't get why this function would have a random behavior. I have to learn a bit more about randr.
« Last Edit: December 10, 2015, 11:12:38 pm by anaskiee »

anaskiee

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Fullscreen window but getSize() incorrect (ubuntu)
« Reply #13 on: December 11, 2015, 08:09:37 am »
Actually, I figured out why I'm still switchnig to fullscreen without this call.

In popEvents(), there is an event of type ReparentNotify filtered (not forwarded to my application)
        // Parent window changed
        case ReparentNotify:
        {
            // Catch reparent events to properly apply fullscreen on
            // some "strange" window managers (like Awesome) which
            // seem to make use of temporary parents during mapping
            if (m_fullscreen)
                switchToFullscreen();

            XSync(m_display, True); // Discard remaining events
            break;
        }

And here is the second call to switchToFullscreen.

Edit: By completly ignoring this ReparentNotify event, getSize() is also correct 800x600 until the resize event.
I guess these two switchToFullscreen() call are concurrent and something is going wrong.
« Last Edit: December 11, 2015, 08:15:03 am by anaskiee »