Skip to content

Commit

Permalink
Avoid doing full device resets on monitor hotplug events
Browse files Browse the repository at this point in the history
  • Loading branch information
flibitijibibo committed Nov 19, 2024
1 parent d8167d5 commit de17e24
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/FNAPlatform/SDL2_FNAPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1196,9 +1196,8 @@ ref bool textInputSuppress
}
else
{
// Just reset, this is probably a hotplug
game.GraphicsDevice.Reset(
game.GraphicsDevice.PresentationParameters,
// Quietly update, this is probably a hotplug
game.GraphicsDevice.QuietlyUpdateAdapter(
currentAdapter
);
}
Expand Down
5 changes: 2 additions & 3 deletions src/FNAPlatform/SDL3_FNAPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,9 +1084,8 @@ ref bool textInputSuppress
}
else
{
// Just reset, this is probably a hotplug
game.GraphicsDevice.Reset(
game.GraphicsDevice.PresentationParameters,
// Quietly update, this is probably a hotplug
game.GraphicsDevice.QuietlyUpdateAdapter(
currentAdapter
);
}
Expand Down
20 changes: 20 additions & 0 deletions src/Graphics/GraphicsDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,26 @@ internal void RemoveResourceReference(GCHandle resourceReference)

#endregion

#region Internal Adapter Updates

/* This exists because display hotplugging is fragile and can
* cause problems if we try to do a hard Reset(). Even after
* refreshing the static Adapters list you find weird cases
* where a reset on an unrelated display will insist on a 0x0
* window size??? :psyduck:
*
* So instead, just quietly swap the Adapter so that the device
* state is valid, and avoid messing with the window further.
* -flibit
*/

internal void QuietlyUpdateAdapter(GraphicsAdapter adapter)
{
Adapter = adapter;
}

#endregion

#region Public Present Method

public void Present()
Expand Down

0 comments on commit de17e24

Please sign in to comment.