refactor(app): harden shutdown per final review
Addresses final code review of phase-1 branch (Important I-1, I-3): - Move plugin Enable() loop inside the same try block as GameWindow.Run, and wrap each Enable() in per-plugin try/catch mirroring the Disable loop. Previously, a plugin Enable() throwing would skip the finally block entirely: plugins that had already enabled would never get disabled, Serilog would never flush, and the exception would escape ungracefully. Now Enable failures are logged and contained, and shutdown always runs. - Add a comment at the Get<LandBlock> call in GameWindow.OnLoad explaining why TryGet was avoided (the [MaybeNullWhen(false)] nullable-generic analysis trips TreatWarningsAsErrors). I-2 (camera aspect doesn't update on window resize) deferred to Phase 2. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
fb83e0bb6f
commit
6a100ef6e7
2 changed files with 10 additions and 4 deletions
|
|
@ -40,11 +40,14 @@ foreach (var result in PluginDiscovery.Scan(pluginsDir))
|
||||||
Log.Information("loaded plugin {Id} ({DisplayName})", result.Manifest!.Id, result.Manifest.DisplayName);
|
Log.Information("loaded plugin {Id} ({DisplayName})", result.Manifest!.Id, result.Manifest.DisplayName);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var plugin in loaded)
|
|
||||||
plugin.Plugin!.Enable();
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
foreach (var plugin in loaded)
|
||||||
|
{
|
||||||
|
try { plugin.Plugin!.Enable(); }
|
||||||
|
catch (Exception ex) { Log.Error(ex, "plugin enable failed: {Id}", plugin.Manifest.Id); }
|
||||||
|
}
|
||||||
|
|
||||||
using var window = new GameWindow(datDir);
|
using var window = new GameWindow(datDir);
|
||||||
window.Run();
|
window.Run();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,10 @@ public sealed class GameWindow : IDisposable
|
||||||
_dats = new DatCollection(_datDir, DatAccessType.Read);
|
_dats = new DatCollection(_datDir, DatAccessType.Read);
|
||||||
|
|
||||||
// Find ANY landblock ending in 0xFFFF. Holtburg 0xA9B4FFFF is a
|
// Find ANY landblock ending in 0xFFFF. Holtburg 0xA9B4FFFF is a
|
||||||
// good default; fall back to the first one we find.
|
// good default; fall back to the first one we find. Using Get<T>
|
||||||
|
// (returns null on miss) rather than TryGet to sidestep
|
||||||
|
// [MaybeNullWhen(false)] nullable-generic analysis under
|
||||||
|
// TreatWarningsAsErrors.
|
||||||
uint landblockId = 0xA9B4FFFFu;
|
uint landblockId = 0xA9B4FFFFu;
|
||||||
var block = _dats.Get<LandBlock>(landblockId);
|
var block = _dats.Get<LandBlock>(landblockId);
|
||||||
if (block is null)
|
if (block is null)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue