Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix([issue-952]): dispose DoF passes + harden override guard

Adam Eivydb5c5719c0df
diff --git a/client/src/components/city/CityDepthOfField.jsx b/client/src/components/city/CityDepthOfField.jsx
index cccf6898e2..d11d8fc02c 100644
--- a/client/src/components/city/CityDepthOfField.jsx
+++ b/client/src/components/city/CityDepthOfField.jsx
@@ -77,8 +77,15 @@ export default function CityDepthOfField({ presetId, enabled = true, composerRef
invalidate();
}, [bokehPass, presetId, enabled, invalidate]);
- // Free GPU resources (render targets, materials, full-screen quads) when photo mode exits.
- useEffect(() => () => composer.dispose(), [composer]);
+ // Free GPU resources when photo mode exits. EffectComposer.dispose() only frees the composer's
+ // own read/write targets + internal copy pass — NOT the passes you added — so dispose each pass
+ // (BokehPass owns a depth render target + materials + a full-screen quad; OutputPass owns a
+ // material + quad) before disposing the composer. The Canvas key-remount tears the WebGL context
+ // down on exit too, but disposing explicitly keeps this correct if that remount ever changes.
+ useEffect(() => () => {
+ for (const pass of composer.passes) pass.dispose?.();
+ composer.dispose();
+ }, [composer]);
// Positive priority makes R3F hand the render loop to us: drive the scene through the composer
// instead of the default renderer. In photo mode's frameloop="demand" this runs only when
diff --git a/client/src/utils/cityPhotoMode.js b/client/src/utils/cityPhotoMode.js
index 560d679676..d081fb612d 100644
--- a/client/src/utils/cityPhotoMode.js
+++ b/client/src/utils/cityPhotoMode.js
@@ -51,6 +51,11 @@ export function presetFocusDistance(preset) {
return Number.isFinite(dist) && dist > 0 ? dist : 1;
}
+// Accept a per-preset override only when it's a positive finite number; otherwise fall back to the
+// default. A negative/zero/NaN aperture or maxblur is meaningless to the bokeh shader (blur radius
+// is non-negative), so a malformed hand-edited preset can't push a broken value into the pass.
+const positiveOr = (value, fallback) => (Number.isFinite(value) && value > 0 ? value : fallback);
+
// Resolve the BokehPass parameters for a preset: derived focal distance + (per-preset-overridable)
// aperture/maxblur. Used by CityDepthOfField to build and re-tune the pass when the preset changes.
export function getDofParams(presetId) {
@@ -58,8 +63,8 @@ export function getDofParams(presetId) {
const override = preset?.dof || {};
return {
focus: presetFocusDistance(preset),
- aperture: Number.isFinite(override.aperture) ? override.aperture : DOF_DEFAULTS.aperture,
- maxblur: Number.isFinite(override.maxblur) ? override.maxblur : DOF_DEFAULTS.maxblur,
+ aperture: positiveOr(override.aperture, DOF_DEFAULTS.aperture),
+ maxblur: positiveOr(override.maxblur, DOF_DEFAULTS.maxblur),
};
}
diff --git a/client/src/utils/cityPhotoMode.test.js b/client/src/utils/cityPhotoMode.test.js
index a25f2ee9aa..b6a7a17e2a 100644
--- a/client/src/utils/cityPhotoMode.test.js
+++ b/client/src/utils/cityPhotoMode.test.js
@@ -166,4 +166,14 @@ describe('getDofParams', () => {
expect(params.aperture).toBe(0.09);
expect(params.maxblur).toBe(DOF_DEFAULTS.maxblur); // unspecified → default
});
+ it('always returns positive finite aperture/maxblur and a positive focus', () => {
+ for (const p of PHOTO_PRESETS) {
+ const params = getDofParams(p.id);
+ expect(params.focus).toBeGreaterThan(0);
+ expect(params.aperture).toBeGreaterThan(0);
+ expect(params.maxblur).toBeGreaterThan(0);
+ expect(Number.isFinite(params.aperture)).toBe(true);
+ expect(Number.isFinite(params.maxblur)).toBe(true);
+ }
+ });
});