fix(rendering): bound portal resource lifetime

Separate logical ownership, render publication, and GPU retirement across live entities, landblocks, particles, textures, mesh arenas, portal/UI teardown, and per-frame scratch storage. Add bounded DAT/texture caches, upload budgets, three-frame fence retirement, exact-incarnation appearance reconciliation, frame pacing, and extensive lifetime conformance coverage.\n\nThe seven-destination connected route now cuts peak working/private memory roughly in half, returns Caul to 125-153 FPS locally, and produces no WER or AMD reset.\n\nCo-authored-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
Erik 2026-07-18 21:35:16 +02:00
parent 3971997689
commit 749e8ceeb1
225 changed files with 29107 additions and 3914 deletions

View file

@ -1,8 +1,8 @@
using System.Numerics;
using AcDream.Content;
using AcDream.App.Rendering;
using AcDream.App.UI;
using DatReaderWriter;
using DatReaderWriter.Options;
using Silk.NET.Input;
using Silk.NET.Maths;
using Silk.NET.OpenGL;
@ -39,7 +39,7 @@ public sealed class StudioWindow : IDisposable
// Created in OnLoad, released in OnClosing.
private IWindow? _window;
private DatCollection? _dats;
private IDatReaderWriter? _dats;
private RenderStack? _stack;
private LayoutSource? _source;
@ -113,7 +113,7 @@ public sealed class StudioWindow : IDisposable
{
var gl = GL.GetApi(_window!);
_dats = new DatCollection(_opts.DatDir, DatAccessType.Read);
_dats = RuntimeDatCollectionFactory.OpenReadOnly(_opts.DatDir);
// Build QualitySettings for RenderBootstrap (same as Run() above — re-read
// after the GL context is confirmed, mirroring GameWindow.OnLoad).
@ -218,6 +218,10 @@ public sealed class StudioWindow : IDisposable
private void OnRender(double dt)
{
if (_stack is null || _panelFbo is null) return;
_stack.BeginFrame();
Exception? renderFailure = null;
try
{
// ── HEADLESS SCREENSHOT PATH ──────────────────────────────────────────────
if (_opts.ScreenshotPath is not null)
@ -415,6 +419,26 @@ public sealed class StudioWindow : IDisposable
// 9. Finalise ImGui and flush draw data to the window.
_imgui.Render();
}
catch (Exception ex)
{
renderFailure = ex;
throw;
}
finally
{
try
{
_stack.EndFrame();
}
catch (Exception closeFailure) when (renderFailure is not null)
{
throw new AggregateException(
"UI Studio rendering failed and its GPU frame could not be closed.",
renderFailure,
closeFailure);
}
}
}
/// <summary>