stride3d / stride

Stride (formerly Xenko), a free and open-source cross-platform C# game engine.
https://stride3d.net
MIT License
6.61k stars 953 forks source link

Window.FullscreenIsBorderlessWindow is ignored and causes "Could not recreate all objects." #1529

Open aybe opened 2 years ago

aybe commented 2 years ago

Release Type: nuget

Version: 4.1.0.1734

Platform(s): Windows

Describe the bug

When you go full screen using Alt-Enter on the following sample, you get "Could not recreate all objects."

Furthermore, the app resolution in full screen doesn't even match desktop resolution.

To Reproduce

using Stride.Core.Mathematics;
using Stride.Engine;
using Stride.Games;
using Stride.Input;

namespace StrideTest;

internal class Game1 : Game
{
    protected override void Update(GameTime gameTime)
    {
        if (Input.IsKeyPressed(Keys.Escape))
            Exit();

        base.Update(gameTime);
    }

    protected override Task LoadContent()
    {
        Window.AllowUserResizing = true;
        Window.FullscreenIsBorderlessWindow = true;
        return base.LoadContent();
    }

    protected override void Draw(GameTime gameTime)
    {
        var color = new Color4((float)(gameTime.Total.TotalSeconds % 1.0f), 0, 0);

        GraphicsContext.CommandList.Clear(GraphicsContext.CommandList.RenderTarget, color);

        base.Draw(gameTime);
    }
}

callstack.txt

System.InvalidOperationException
  HResult=0x80131509
  Message=Could not recreate all objects.
  Source=Stride.Graphics
  StackTrace:
   at Stride.Graphics.ResumeManager.OnRecreate()
   at Stride.Games.GraphicsDeviceManager.CreateDevice(GraphicsDeviceInformation newInfo)
   at Stride.Games.GraphicsDeviceManager.ChangeOrCreateDevice(Boolean forceCreate)
   at Stride.Games.GraphicsDeviceManager.Window_ClientSizeChanged(Object sender, EventArgs e)
   at Stride.Games.GameWindow.OnClientSizeChanged(Object source, EventArgs e)
   at Stride.Games.GameFormSDL.GameForm_ResizeEndActions(WindowEvent e)
   at Stride.Graphics.SDL.Window.ProcessEvent(Event e)
   at Stride.Graphics.SDL.Application.ProcessEvent(Event e)
   at Stride.Games.SDLMessageLoop.NextFrame()
   at Stride.Games.SDLMessageLoop.Run(Window form, RenderCallback renderCallback)
   at Stride.Games.GameWindowSDL.Run()
   at Stride.Games.GameBase.Run(GameContext gameContext)
   at StrideTest.Program.Main(String[] args) in C:\Users\aybe\Documents\Stride Projects\MyGame\StrideTest\Program.cs:line 11
manio143 commented 2 years ago

Related to #1493

aybe commented 2 years ago

I found a temporary workaround, setting the preferred full screen size makes the error vanish actually:

using Stride.Core.Mathematics;
using Stride.Engine;
using Stride.Games;
using Stride.Input;

namespace StrideTest;

internal class Game1 : Game
{
    protected override void Update(GameTime gameTime)
    {
        if (Input.IsKeyPressed(Keys.Escape))
            Exit();

        base.Update(gameTime);
    }

    protected override Task LoadContent()
    {
        var w = GraphicsDevice.Adapter.Outputs[0].CurrentDisplayMode.Width;
        var h = GraphicsDevice.Adapter.Outputs[0].CurrentDisplayMode.Height;
        Window.PreferredFullscreenSize = new Int2(w, h);
        Window.AllowUserResizing = true;
        Window.FullscreenIsBorderlessWindow = true;
        return base.LoadContent();
    }

    protected override void Draw(GameTime gameTime)
    {
        var color = new Color4((float)(gameTime.Total.TotalSeconds % 1.0f), 0, 0);

        GraphicsContext.CommandList.Clear(GraphicsContext.CommandList.RenderTarget, color);

        base.Draw(gameTime);
    }
}
Jklawreszuk commented 6 days ago

I am also interested in the problem because it also occurs in OpenGL on Linux. Interestingly, if you set FullscreenIsBorderlessWindow to true, it is possible to set fullscreen mode but you can no longer exit it.

Jklawreszuk commented 6 days ago

Here is result of trying to exit fullscreen mode.

Unhandled exception. System.Exception: Depth buffer is not the same size as the render target
   at Stride.Graphics.CommandList.SetRenderTargetsImpl(Texture depthStencilBuffer, Int32 renderTargetCount, Texture[] renderTargets)
   at Stride.Graphics.CommandList.SetRenderTargets(Texture depthStencilView, Int32 renderTargetViewCount, Texture[] renderTargetViews)
   at Stride.Rendering.Compositing.ForwardRenderer.ResolveDepthAsSRV(RenderDrawContext context) in ...stride/sources/engine/Stride.Engine/Rendering/Compositing/ForwardRenderer.cs:line 821