dispose method

void dispose()

Releases the render targets this scene keeps across frames: each view's output ring and transient attachment pool, and the history textures of temporal anti-aliasing, global illumination, auto exposure, screen-space indirect light, cached shadows, punctual lights, probe captures, and planar reflections.

The textures become unreachable from the scene at this call, even if the scene object lives on. The GPU memory itself frees once those textures are collected. The scene graph is left as it is.

A pending captureRenderGraph completes with a StateError, and a warmUp in progress stops. A later render, renderViews, warmUp, captureRenderGraph, captureEnvironment, bakeIrradianceField, or a bake stepper taken before the call throws a StateError. Calling dispose again does nothing.

Implementation

void dispose() {
  if (_disposed) {
    return;
  }
  _disposed = true;
  surface.dispose();
  _taaState?.dispose();
  _taaState = null;
  _irradianceField.dispose();
  _punctualLightBuffer.releaseTextures();
  _autoExposureState = null;
  _directionalShadowCache = null;
  _ssgiHistoryColor = null;
  _ssgiHistoryViewProjection = null;
  _probeCapturePool?.clear();
  _probeCapturePool = null;
  for (final reflector in renderScene.planarReflectorComponents) {
    reflector.internalDistributeFrame(null);
  }
  _planarCaptureResources.clear();
  debugLastPlanarCapturePasses = const [];
  final pending = _pendingGraphCapture;
  _pendingGraphCapture = null;
  pending?.completer.completeError(
    StateError('The scene was disposed before a frame was captured'),
  );
}