Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug [andQuestion] Screen: DX11 could not switch resolution (1024x768 fs=1 hz=0)

Discussion in 'Editor & General Support' started by fdart, Jan 12, 2023.

  1. fdart

    fdart

    Joined:
    Jan 4, 2019
    Posts:
    17
    We're using various versions of 2021.3. Can confirm for sure this issue occurs on 2021.3.4f1. I'm trying to upgrade to the latest 2021.3.x LTS version now to see if it makes a difference.

    The error we see is Screen: DX11 could not switch resolution (1024x768 fs=1 hz=0)

    This occurs when trying to run the windows standalone player. It only occurs when the app is run through automation via
    start /b /wait "" "MyUnityStandalone.exe"

    If I logon to the machine in question and run this same command, the player runs just fine.

    I've seen other threads on this but no solutions that fixed the issue.
    https://forum.unity.com/threads/couldnt-switch-to-requested-monitor-resolution-in-windows-7.734915/

    I've tried setting various permutations of theses settings to no avail. It seems there is likely a bug where the app seems to always run in fullscreen mode regardless of what's set here.
    PlayerSettings.runInBackground = true;
    PlayerSettings.fullScreenMode = FullScreenMode.Windowed;
    PlayerSettings.resizableWindow = true;
    PlayerSettings.defaultIsNativeResolution = false;
    PlayerSettings.defaultScreenWidth = 1024;
    PlayerSettings.defaultScreenHeight = 768;
    PlayerSettings.defaultWebScreenWidth = 1024;
    PlayerSettings.defaultWebScreenHeight = 768;

    Is there any known workaround for this problem? Please let me know if I can provide any more info. Thanks!
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,644
    Do you have the full player log to share? Do those PlayerSettings API calls happen before the build is made? Do you know if those settings get reflected in the PlayerSettings UI afterwards?

    You could also start the build using "-screen-fullscreen 0" command line argument to force windowed mode.
     
  3. fdart

    fdart

    Joined:
    Jan 4, 2019
    Posts:
    17
    Thanks for the quick response.

    >Do you have the full player log to share?
    Yes, here it is.
    Code (CSharp):
    1. Mono path[0] = 'C:/FreeBuild/GameUnity/Build/Windows/GameUnity_Data/Managed'
    2. Mono config path = 'C:/FreeBuild/GameUnity/Build/Windows/MonoBleedingEdge/etc'
    3. Initialize engine version: 2021.3.4f1 (cb45f9cae8b7)
    4. [Subsystems] Discovering subsystems at path C:/FreeBuild/GameUnity/Build/Windows/GameUnity_Data/UnitySubsystems
    5. GfxDevice: creating device client; threaded=1; jobified=0
    6. Direct3D:
    7.     Version:  Direct3D 11.0 [level 11.1]
    8.     Renderer: Intel(R) UHD Graphics 630 (ID=0x9bc5)
    9.     Vendor:   Intel
    10.     VRAM:     32625 MB
    11.     Driver:   27.20.100.9664
    12. Begin MonoManager ReloadAssembly
    13. - Completed reload, in  0.111 seconds
    14. <RI> Initializing input.
    15.  
    16. <RI> Input initialized.
    17.  
    18. Switching to resolution 1024x768 failed
    19. Screen: DX11 could not switch resolution (1024x768 fs=0 hz=0)

    >Do those PlayerSettings API calls happen before the build is made?
    Yes, here is our custom build function.
    Code (CSharp):
    1. [MenuItem("GameUnity Build/Build Win64")]
    2. static void BuildWin64()
    3. {
    4.     Debug.Log("Building Win64Player");
    5.     if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.StandaloneWindows64 && !Application.isBatchMode)
    6.     {
    7.         EditorUserBuildSettings.SwitchActiveBuildTarget(UnityEditor.Build.NamedBuildTarget.Standalone, BuildTarget.StandaloneWindows64);
    8.     }
    9.     BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
    10.     buildPlayerOptions.scenes = new[] { GameScenePath };
    11.     buildPlayerOptions.locationPathName = "Build/Windows/GameUnity.exe";
    12.     buildPlayerOptions.target = BuildTarget.StandaloneWindows64;
    13.     buildPlayerOptions.options = BuildOptions.None;
    14.     PlayerSettings.runInBackground = true;
    15.     PlayerSettings.fullScreenMode = FullScreenMode.Windowed;
    16.     PlayerSettings.resizableWindow = true;
    17.     PlayerSettings.defaultIsNativeResolution = false;
    18.     PlayerSettings.defaultScreenWidth = 1024;
    19.     PlayerSettings.defaultScreenHeight = 768;
    20.     PlayerSettings.defaultWebScreenWidth = 1024;
    21.     PlayerSettings.defaultWebScreenHeight = 768;
    22.  
    23.     BuildPlayerAndOutputReport(buildPlayerOptions);
    24.  
    25.     BuildReport report = BuildPipeline.BuildPlayer(buildPlayerOptions);
    26.     BuildSummary summary = report.summary;
    27.  
    28.     if (summary.result == BuildResult.Succeeded)
    29.     {
    30.         Debug.Log("Build succeeded: " + summary.totalSize + " bytes");
    31.     }
    32.  
    33.     if (summary.result == BuildResult.Failed)
    34.     {
    35.         Debug.LogError("Build failed");
    36.     }
    37. }
    >Do you know if those settings get reflected in the PlayerSettings UI afterwards?
    I'll have to double check this and can follow up.

    >You could also start the build using "-screen-fullscreen 0" command line argument to force windowed mode.
    I'll try this as well and get back to you. If I pass that as the second argument (we're using the first argument for our own usage), will that still be ok? I will test it out either way.
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,644
    Yes, the order of arguments passed to Unity doesn't matter.

    However, your player log shows that this time fullscreen was set to 0 (fs=0), so this workaround may not work for you. This error would happen if the swapchain creation fails. Given what you told me (that you run it through automation), I suspect that you are accidentally running in Windows session 0 (aka from within a service), which does not support running DirectX applications. The solution here would be to either use the "-nographics" switch, or make sure that your automation launches the build in the interactive (user, non-service) session.
     
  5. fdart

    fdart

    Joined:
    Jan 4, 2019
    Posts:
    17
    That was very helpful, thank you. Indeed, passing -batchmode -nographics as arguments solved the issue.