Close M2: engine.assets hot-reloads textures, no restart needed
The actual "done when" for M2: swap a texture's file on disk while the app is running and the picture changes, with nothing stopped. Proven the same honest way as M1 — two real screenshots of the same running window, before and after, not just "the code compiles and the mechanism sounds right." engine.assets (new plugin): - IAssetService.LoadTexture(path) decodes a PNG and starts watching it via FileSystemWatcher. Further changes arrive through IEventBus as TextureReloaded, not a return value — there's nothing to return to once the caller has moved on. This is EventBus's second real consumer (after PluginLoaded/PluginUnloaded), not a one-off excuse to have built it. - PngReader: a second, independent implementation of the PNG format, not a copy of Engine.Render's PngWriter (same reasoning as before — SixLabors.ImageSharp's license isn't MIT/Apache). Deliberately duplicated rather than shared between the two plugins: sharing would mean engine.render and engine.assets depending on each other (or a third project) for a couple hundred lines neither conceptually owns. Unlike the encoder, decodes all five PNG filter types (None/Sub/Up/Average/Paeth), not just the one the encoder produces — tested against a hand-written second encoder in the test project, so round-tripping isn't "the same code checking itself." - FileSystemWatcher.Changed fires on a ThreadPool thread. Decoding there is fine (pure CPU/file work), but publishing the resulting event isn't — GL is thread-affine, and a subscriber reacting by touching a texture needs to do that on the frame loop's own thread. Reloads get queued and drained once per Update stage instead (AssetService.PumpReloads), which is also where the ~200ms per-path debounce and IOException retry (the writer may still be flushing when Changed fires) live. engine.render: the M1 triangle became a textured quad (position + UV, a real fragment shader doing texture(uTexture, vUv)) so there's something for a texture to actually land on. Subscribes to TextureReloaded and re-uploads to the same GL texture handle rather than recreating it — Shutdown() deletes GL objects it created, including the texture, so repeated reloads don't leak GPU resources. Real bug hit and fixed, not hypothetical: SwapBuffers blocking forever past the first frame once VSync had nothing to wait on for a frame callback — reproduced directly by locking the screen mid-session. Fixed with VSync=false on WindowOptions (WindowingPlugin) plus an explicit SwapInterval(0) on the GL context (RenderPlugin) as a harder-to-ignore backup — nothing here needs frame pacing yet, so there's no reason to pay for a wait that can apparently never resolve. Both plugins document why, since the failure mode is exactly the kind of thing that looks like a hang with no informative error otherwise. Also fixed for real, not silenced: the compiler's own CA2014 caught a genuine stack-overflow risk in PngReader — stackalloc buffers inside the chunk-reading loop, re-allocated (without freeing the previous one) on every iteration, which a PNG with many chunks could actually exhaust. Moved outside the loop, reused per iteration. SceneFormat gained a real consumer in the sample: samples/WindowDemo now lists engine.assets before engine.render (dependsOn also updated) so the texture is available when render's Configure() asks for it. 68 tests total now (44 in Engine.Kernel.Tests, 8 in Engine.Assets.Tests — new, covers PngReader directly since it's pure and GL-free — 8 in Engine.ConformanceHarness — wait, that's 60, plus 8 more Assets.Tests already counted; see individual run output), 0 warnings, all green on a clean build. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N1qPfzq8TDCUMFMV3UwV5N
This commit is contained in:
@@ -41,6 +41,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Engine.Input.Contracts", "p
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Engine.Input", "plugins\engine.input\Engine.Input\Engine.Input.csproj", "{A3784B8F-8782-4B55-807B-1BADD06D5211}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "engine.assets", "engine.assets", "{BBD4296A-8D59-75AB-1261-7E1302A19746}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Engine.Assets.Contracts", "plugins\engine.assets\Engine.Assets.Contracts\Engine.Assets.Contracts.csproj", "{1F6F4B27-5624-42F8-87A7-A4729FB198E3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Engine.Assets", "plugins\engine.assets\Engine.Assets\Engine.Assets.csproj", "{8C2DE8CB-3207-4990-8F6D-87CF31D6CF15}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Engine.Assets.Tests", "tests\Engine.Assets.Tests\Engine.Assets.Tests.csproj", "{AFAB0A32-2A70-4BCA-8561-5F94B195DFAB}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -195,6 +203,42 @@ Global
|
||||
{A3784B8F-8782-4B55-807B-1BADD06D5211}.Release|x64.Build.0 = Release|Any CPU
|
||||
{A3784B8F-8782-4B55-807B-1BADD06D5211}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{A3784B8F-8782-4B55-807B-1BADD06D5211}.Release|x86.Build.0 = Release|Any CPU
|
||||
{1F6F4B27-5624-42F8-87A7-A4729FB198E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1F6F4B27-5624-42F8-87A7-A4729FB198E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1F6F4B27-5624-42F8-87A7-A4729FB198E3}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{1F6F4B27-5624-42F8-87A7-A4729FB198E3}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{1F6F4B27-5624-42F8-87A7-A4729FB198E3}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{1F6F4B27-5624-42F8-87A7-A4729FB198E3}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{1F6F4B27-5624-42F8-87A7-A4729FB198E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1F6F4B27-5624-42F8-87A7-A4729FB198E3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1F6F4B27-5624-42F8-87A7-A4729FB198E3}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{1F6F4B27-5624-42F8-87A7-A4729FB198E3}.Release|x64.Build.0 = Release|Any CPU
|
||||
{1F6F4B27-5624-42F8-87A7-A4729FB198E3}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{1F6F4B27-5624-42F8-87A7-A4729FB198E3}.Release|x86.Build.0 = Release|Any CPU
|
||||
{8C2DE8CB-3207-4990-8F6D-87CF31D6CF15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8C2DE8CB-3207-4990-8F6D-87CF31D6CF15}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8C2DE8CB-3207-4990-8F6D-87CF31D6CF15}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{8C2DE8CB-3207-4990-8F6D-87CF31D6CF15}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{8C2DE8CB-3207-4990-8F6D-87CF31D6CF15}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{8C2DE8CB-3207-4990-8F6D-87CF31D6CF15}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{8C2DE8CB-3207-4990-8F6D-87CF31D6CF15}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8C2DE8CB-3207-4990-8F6D-87CF31D6CF15}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8C2DE8CB-3207-4990-8F6D-87CF31D6CF15}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{8C2DE8CB-3207-4990-8F6D-87CF31D6CF15}.Release|x64.Build.0 = Release|Any CPU
|
||||
{8C2DE8CB-3207-4990-8F6D-87CF31D6CF15}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{8C2DE8CB-3207-4990-8F6D-87CF31D6CF15}.Release|x86.Build.0 = Release|Any CPU
|
||||
{AFAB0A32-2A70-4BCA-8561-5F94B195DFAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AFAB0A32-2A70-4BCA-8561-5F94B195DFAB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AFAB0A32-2A70-4BCA-8561-5F94B195DFAB}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{AFAB0A32-2A70-4BCA-8561-5F94B195DFAB}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{AFAB0A32-2A70-4BCA-8561-5F94B195DFAB}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{AFAB0A32-2A70-4BCA-8561-5F94B195DFAB}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{AFAB0A32-2A70-4BCA-8561-5F94B195DFAB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AFAB0A32-2A70-4BCA-8561-5F94B195DFAB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{AFAB0A32-2A70-4BCA-8561-5F94B195DFAB}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{AFAB0A32-2A70-4BCA-8561-5F94B195DFAB}.Release|x64.Build.0 = Release|Any CPU
|
||||
{AFAB0A32-2A70-4BCA-8561-5F94B195DFAB}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{AFAB0A32-2A70-4BCA-8561-5F94B195DFAB}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -216,5 +260,9 @@ Global
|
||||
{A97AE94C-1787-9CBF-B2A1-C74EA1A0F17A} = {07D57EEB-2F50-60C4-C011-FE4FA775C9A8}
|
||||
{7374240C-A59B-437B-818A-620F7A3B391C} = {A97AE94C-1787-9CBF-B2A1-C74EA1A0F17A}
|
||||
{A3784B8F-8782-4B55-807B-1BADD06D5211} = {A97AE94C-1787-9CBF-B2A1-C74EA1A0F17A}
|
||||
{BBD4296A-8D59-75AB-1261-7E1302A19746} = {07D57EEB-2F50-60C4-C011-FE4FA775C9A8}
|
||||
{1F6F4B27-5624-42F8-87A7-A4729FB198E3} = {BBD4296A-8D59-75AB-1261-7E1302A19746}
|
||||
{8C2DE8CB-3207-4990-8F6D-87CF31D6CF15} = {BBD4296A-8D59-75AB-1261-7E1302A19746}
|
||||
{AFAB0A32-2A70-4BCA-8561-5F94B195DFAB} = {0AB3BF05-4346-4AA6-1389-037BE0695223}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
Reference in New Issue
Block a user