fix: Workshop load doesn't stop audio — matches loadPreset pattern

Calling stopAudio() before deserialize+rebuildGraph broke the audio
graph because rebuildGraph needs isRunning=true to work properly.
Now follows the same pattern as loadPreset(): deserialize then
rebuildGraph (which destroys and recreates all nodes internally).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jose Luis
2026-03-21 21:11:02 +01:00
parent acbe4257ae
commit 13612bfa99

View File

@@ -1,8 +1,8 @@
import React, { useState, useEffect, useCallback } from 'react';
import { workshop as workshopApi } from '../services/api.js';
import { useAuth } from '../services/AuthContext.jsx';
import { state, deserialize, emit } from '../engine/state.js';
import { stopAudio, rebuildGraph } from '../engine/audioEngine.js';
import { state, deserialize } from '../engine/state.js';
import { rebuildGraph } from '../engine/audioEngine.js';
import { getPresets } from '../engine/presets.js';
const TAGS = ['ambient', 'bass', 'drums', 'pad', 'lead', 'fx', 'chiptune', 'experimental'];
@@ -171,14 +171,11 @@ export default function Workshop({ onSwitchToSandbox, onSwitchToGame, onSwitchTo
const handleLoad = (patch) => {
if (!patch.data) return;
// Stop audio, clean state, then load
if (state.isRunning) stopAudio();
// Deep clone to avoid reference issues
// Deep clone and load — same pattern as loadPreset()
// Don't stop audio first: rebuildGraph destroys and recreates all nodes
const cleanData = JSON.parse(JSON.stringify(patch.data));
deserialize(cleanData);
rebuildGraph();
emit();
if (state.isRunning) rebuildGraph();
onSwitchToSandbox?.();
};