Search Unity

Screen.SetResolution ignores window dimensions on Linux

Discussion in 'Linux' started by mostlytigerproof, Feb 22, 2017.

  1. mostlytigerproof

    mostlytigerproof

    Joined:
    Jan 8, 2014
    Posts:
    6
    If I use SetResolution in the Linux standalone player to go from fullscreen to a window, the window's dimensions aren't what I pass in. It varies between:
    • A window the size of the display (1680x1050 in my case)
    • A gigantic window that's too big to render anything. xwininfo says it's 1680x65064, but that varies. Sometimes the width is gigantic too.
    I'm seeing this in Ubuntu 16.10 and Kubuntu 16.10. Using editor v5.4.3. I see it both from the Linux editor and cross compiling from the Windows editor.

    (Incidentally, selecting Report a Bug... from the Linux editor doesn't seem to do anything, which is why I'm making a thread here)

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class ToggleWindowed : MonoBehaviour {
    4.     // Toggle between native fullscreen and a 720p window
    5.     // Make window resizeable in player options
    6.     public bool IsFullscreen {
    7.         get { return Screen.fullScreen; }
    8.         set {
    9.             if (value) {
    10.                 var res = Screen.currentResolution;
    11.                 Debug.Log(string.Format("Setting fullscreen resolution to {0}x{1}", res.width, res.height));
    12.                 Screen.SetResolution(res.width, res.height, true);
    13.             }
    14.             else {
    15.                 Debug.Log(string.Format("Setting windowed resolution to {0}x{1}", 1280, 720));
    16.                 Screen.SetResolution(1280, 720, false);
    17.             }
    18.         }
    19.     }
    20.  
    21.     void Update () {
    22.         if (Input.GetMouseButtonUp(0)) {
    23.             IsFullscreen = !IsFullscreen;
    24.         }
    25.     }
    26. }
     
  2. Tak

    Tak

    Joined:
    Mar 8, 2010
    Posts:
    1,001
    I've occasionally seen these kinds of bad interactions with some window managers. Can you send a player log from a session where this occurs?
    Also, could you confirm that this behavior doesn't occur with a 5.6 beta build?

    Hm, maybe there's some missing dependency or library conflict for the bug reporter executable - could you try manually launching Editor/BugReporter/unity.bugreporter from your unity installation and seeing if it gives you more info?
     
  3. mostlytigerproof

    mostlytigerproof

    Joined:
    Jan 8, 2014
    Posts:
    6
    Oops, I didn't have libpng12 installed for the bug reporter (Only libpng16). I've been using a non-deb Unity build because I read the dependencies were busted for 5.4 debs. Works fine now.

    The comment in the code sample I posted is misleading. We haven't had resizeable windows enabled in player settings, but are still programmatically going between fullscreen and windowed. This works on Windows/Mac, so I guess it's a legit thing to do?

    I haven't been able to nail down good repro steps for the gigantic window thing. It seems to involve dragging around or something while it's in a window. I've attached logs and what KWin's debug console says when pointed to the window. They're for dual display, but I've also seen it with one display disabled (via NVidia X Server Settings).

    Will try out the beta shortly.
     

    Attached Files:

  4. Tak

    Tak

    Joined:
    Mar 8, 2010
    Posts:
    1,001
    So looking at this log, it looks like Unity is indeed requesting a window at 1280x720, and the window manager is just denying us. (We also get events when X notifies us that a window size change has occurred, and we log those as well.)
    Is the behavior any different (on 5.4) if you do have window resizing enabled?
     
  5. mostlytigerproof

    mostlytigerproof

    Joined:
    Jan 8, 2014
    Posts:
    6
    The build from the 5.6 linux beta is really well behaved! Any ideas which release fixed this? A cursory search of the build notes isn't turning up anything.

    (In 5.4 there's no change in the symptoms with or without resizeable windows. I figured I should mention it because it might've been a condition for triggering the difficult to repro gigantic windows thing)
     
  6. Tak

    Tak

    Joined:
    Mar 8, 2010
    Posts:
    1,001
    In 5.6, we switched to using SDL for all of the window management, so they may have more workarounds for WM quirks like this (or WMs may be more used to SDL's way of doing things; I'm not sure which way it goes).

    5.5 may also have some more window management workarounds on the Unity side - if nobody reported that it solved a substantial problem for them, these workarounds may not have been backported to 5.4.