From c986921505e2c4897f4a7e4de83e3b262fe8ede6 Mon Sep 17 00:00:00 2001 From: edideaur Date: Fri, 6 Mar 2026 08:56:36 +0000 Subject: [PATCH] bun install in dockerfile and reload page when visualizer switching to avoid issues --- .devcontainer/devcontainer.json | 2 +- js/visualizer.js | 19 ++++++++++++++----- js/visualizers/butterchurn.js | 11 +++++++++-- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 6033fdf..6a08a95 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -14,7 +14,7 @@ } }, - "postCreateCommand": "bun --version && code --version", + "postCreateCommand": "bun install", "remoteEnv": { "SHELL": "/usr/bin/fish" diff --git a/js/visualizer.js b/js/visualizer.js index 2e5809a..e3f5f3d 100644 --- a/js/visualizer.js +++ b/js/visualizer.js @@ -91,9 +91,7 @@ export class Visualizer { // Clone the canvas to get a fresh context when switching context types, // or when the previous preset grabbed its own context (managesOwnContext) - const needsClone = - (this.ctx && currentType !== type) || - (!this.ctx && currentType && currentType !== type); + const needsClone = (this.ctx && currentType !== type) || (!this.ctx && currentType && currentType !== type); if (needsClone) { const parent = this.canvas.parentElement; @@ -287,19 +285,30 @@ export class Visualizer { setPreset(key) { if (!this.presets[key]) return; + const webglPresets = ['butterchurn', 'kawarp']; + const fromPreset = this.activePresetKey; + const toPreset = key; + + if (webglPresets.includes(fromPreset) && webglPresets.includes(toPreset) && fromPreset !== toPreset) { + visualizerSettings.setPreset(key); + window.location.reload(); + return; + } + if (this.activePreset?.destroy) { this.activePreset.destroy(); } + this._currentContextType = undefined; + this.ctx = null; + this.activePresetKey = key; this.initContext(); this.resize(); - // Initialize presets that need lazy init (Butterchurn, Kawarp) if (this.presets[key].lazyInit && this.audioContext) { const sourceNode = audioContextManager.getSourceNode(); this.presets[key].lazyInit(this.canvas, this.audioContext, sourceNode).then(() => { - // Re-resize after async init so framebuffers match canvas size this.resize(); }); } diff --git a/js/visualizers/butterchurn.js b/js/visualizers/butterchurn.js index 8fb8414..333f953 100644 --- a/js/visualizers/butterchurn.js +++ b/js/visualizers/butterchurn.js @@ -493,15 +493,22 @@ export class ButterchurnPreset { * Cleanup resources */ destroy() { - // Unregister graph change listener if (this._unregisterGraphChange) { this._unregisterGraphChange(); this._unregisterGraphChange = null; } - if (this.visualizer) { + if (this.visualizer && this.canvas) { + const gl = this.canvas.getContext('webgl2') || this.canvas.getContext('webgl'); + if (gl) { + const ext = gl.getExtension('WEBGL_lose_context'); + if (ext) { + ext.loseContext(); + } + } this.visualizer = null; } + this.isInitialized = false; this.canvas = null; this.audioContext = null;