Skip to content

Commit b5e0155

Browse files
committed
add friendly error for NoSuitableGraphicsDeviceException
1 parent a0cea32 commit b5e0155

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

docs/release-notes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
[README](README.md)
22

33
# Release notes
4+
## Upcoming release
5+
* For players:
6+
* Added a friendly error message when the game fails to launch with a `NoSuitableGraphicsDeviceException`.
7+
48
## 4.3.1
59
Released 13 July 2025 for Stardew Valley 1.6.14 or later. See [release highlights](https://www.patreon.com/posts/133992196).
610

src/SMAPI/Framework/SCore.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,17 @@ public void RunInteractively()
319319
this.Game.Run();
320320
this.Dispose(isError: false);
321321
}
322+
catch (NoSuitableGraphicsDeviceException ex)
323+
{
324+
string? graphicsCardName = this.TryGetGraphicsDeviceName();
325+
string suggestedFix = Constants.TargetPlatform == GamePlatform.Windows
326+
? "You can usually fix this by running SMAPI on your dedicated graphics card. See instructions here:"
327+
: "See common fixes here:";
328+
329+
this.Monitor.Log($"Your graphics card{(graphicsCardName != null ? $" ({graphicsCardName})" : "")} isn't compatible with Stardew Valley. {suggestedFix} https://smapi.io/troubleshoot/no-suitable-gpu\n\nTechnical details:\n{ex.GetLogSummary()}", LogLevel.Error);
330+
this.LogManager.PressAnyKeyToExit();
331+
this.Dispose(isError: true);
332+
}
322333
catch (Exception ex)
323334
{
324335
this.LogManager.LogFatalLaunchError(ex);
@@ -525,7 +536,7 @@ private void OnInstanceContentLoaded()
525536

526537
// log GPU info
527538
#if SMAPI_FOR_WINDOWS
528-
this.Monitor.Log($"Running on GPU: {Game1.game1.GraphicsDevice?.Adapter?.Description ?? "<unknown>"}");
539+
this.Monitor.Log($"Running on GPU: {this.TryGetGraphicsDeviceName() ?? "<unknown>"}");
529540
#endif
530541
}
531542

@@ -2440,6 +2451,23 @@ private IDictionary<string, IDictionary<string, string>> ReadTranslationFiles(st
24402451
}
24412452
}
24422453

2454+
/// <summary>Get the display name for the current graphics card, if available.</summary>
2455+
private string? TryGetGraphicsDeviceName()
2456+
{
2457+
#if SMAPI_FOR_WINDOWS
2458+
try
2459+
{
2460+
return Game1.game1.GraphicsDevice?.Adapter?.Description;
2461+
}
2462+
catch
2463+
{
2464+
// return null if unavailable
2465+
}
2466+
#endif
2467+
2468+
return null;
2469+
}
2470+
24432471
/// <summary>Get a file lookup for the given directory.</summary>
24442472
/// <param name="rootDirectory">The root path to scan.</param>
24452473
private IFileLookup GetFileLookup(string rootDirectory)

0 commit comments

Comments
 (0)