Skip to content

Commit

Permalink
fix: fullscreen and game exit windowing crashes (#2274)
Browse files Browse the repository at this point in the history
* fix resizing issues

* Fix exiting crashes

* fix typos

* remove enable fullscreen event

* remove secondary dispose call
  • Loading branch information
Doprez authored Jun 1, 2024
1 parent e1b9c47 commit 0e08dfd
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 11 deletions.
13 changes: 12 additions & 1 deletion sources/engine/Stride.Games/Desktop/GameForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ public GameForm()
/// </summary>
public event EventHandler<EventArgs> FullscreenToggle;

public event EventHandler<EventArgs> DisableFullScreen;

protected bool enableFullscreenToggle = true;

/// <summary>
Expand Down Expand Up @@ -290,6 +292,15 @@ private void OnFullscreenToggle(EventArgs e)
FullscreenToggle?.Invoke(this, e);
}

/// <summary>
/// Raises the DisableFullScreen event
/// <Summary>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void OnDisableFullScreen(EventArgs e)
{
DisableFullScreen?.Invoke(this, e);
}

protected override void OnClientSizeChanged(EventArgs e)
{
base.OnClientSizeChanged(e);
Expand Down Expand Up @@ -371,7 +382,7 @@ protected override void WndProc(ref Message m)
//also remove full screen if this is the case
if (IsFullScreen && !isSwitchingFullScreen) //exit full screen on alt-tab if in fullscreen
{
OnFullscreenToggle(new EventArgs());
OnDisableFullScreen(new EventArgs());
}
}
break;
Expand Down
1 change: 1 addition & 0 deletions sources/engine/Stride.Games/Desktop/GameWindowWinforms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ protected override void Initialize(GameContext<Control> gameContext)
//gameForm.AppDeactivated += OnDeactivated;
gameForm.UserResized += OnClientSizeChanged;
gameForm.FullscreenToggle += OnFullscreenToggle;
gameForm.DisableFullScreen += OnDisableFullScreen;
gameForm.FormClosing += OnClosing;
}
else
Expand Down
7 changes: 5 additions & 2 deletions sources/engine/Stride.Games/GameBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -996,8 +996,11 @@ private void GraphicsDeviceService_DeviceDisposing(object sender, EventArgs e)

private void GraphicsDeviceService_DeviceReset(object sender, EventArgs e)
{
resumeManager.OnReload();
resumeManager.OnRecreate();
if (!IsExiting)
{
resumeManager.OnReload();
resumeManager.OnRecreate();
}
}

private void GraphicsDeviceService_DeviceResetting(object sender, EventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion sources/engine/Stride.Games/GameContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public abstract class GameContext
internal PixelFormat RequestedDepthStencilFormat;

/// <summary>
/// THe requested graphics profiles.
/// The requested graphics profiles.
/// </summary>
internal GraphicsProfile[] RequestedGraphicsProfile;

Expand Down
7 changes: 6 additions & 1 deletion sources/engine/Stride.Games/GameWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public bool IsFullscreen
}

/// <summary>
/// Allow the GraphicsDeviceMagnager to set the actual window state after applying the device changes.
/// Allow the GraphicsDeviceManager to set the actual window state after applying the device changes.
/// </summary>
/// <param name="isReallyFullscreen"></param>
internal void SetIsReallyFullscreen(bool isReallyFullscreen)
Expand Down Expand Up @@ -304,6 +304,11 @@ protected void OnFullscreenToggle(object source, EventArgs e)
IsFullscreen = !IsFullscreen;
}

protected void OnDisableFullScreen(object source, EventArgs e)
{
IsFullscreen = false;
}

protected void OnClosing(object source, EventArgs e)
{
var handler = Closing;
Expand Down
3 changes: 0 additions & 3 deletions sources/engine/Stride.Games/GraphicsDeviceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -591,9 +591,6 @@ protected override void Destroy()
{
if (GraphicsDevice.Presenter != null)
{
// Make sure that the Presenter is reverted to window before shuting down
// otherwise the Direct3D11.Device will generate an exception on Dispose()
GraphicsDevice.Presenter.IsFullScreen = false;
GraphicsDevice.Presenter.Dispose();
GraphicsDevice.Presenter = null;
}
Expand Down
3 changes: 0 additions & 3 deletions sources/engine/Stride.Graphics/ResumeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ public void OnRecreate()

public void OnDestroyed()
{
// Destroy presenter first (so that its backbuffer and render target are destroyed properly before other resources)
graphicsDevice.Presenter?.OnDestroyed();

foreach (var resource in graphicsDevice.Resources)
{
resource.OnDestroyed();
Expand Down

0 comments on commit 0e08dfd

Please sign in to comment.