Failure Cases and Shipping Checklist

1. Common failure cases

FailureCauseFix
Null active bufferNo active documentGuard ActiveDocument/Buffer before edit operations.
Cross-thread UI exceptionWorker thread touching controlsUse InvokeRequired + BeginInvoke.
UI stalls while dragging graphDSP on drag eventsMove processing to PointsEditCommitted.
Preview keeps playing after closeNo explicit stop on close/unloadAlways send stop with same PreviewOwnerId.
Wrong document modifiedActive doc changed during dialogueCapture document id at open, re-check before commit.
Presets feel inconsistentPlugin-specific ad-hoc persistenceUse IPresetStore for all plugin presets.

1.1 Fix pattern: UI thread marshal

private void OnPlaybackStateChanged(object? sender, PlaybackState state)
{
    if (_statusLabel is null) return;
    if (_statusLabel.InvokeRequired)
    {
        _statusLabel.BeginInvoke(new Action(() => OnPlaybackStateChanged(sender, state)));
        return;
    }

    _statusLabel.Text = state.IsPlaying
        ? $\"Playing @ {state.CurrentFrame}\"
        : \"Stopped\";
}

1.2 Fix pattern: safe preview stop on close/unload

private const string PreviewOwnerId = \"my-plugin.preview\";

private void StopPreview()
{
    _context.AudioSystemBus.RequestPlayback(new PlaybackCommand(
        PlaybackCommandType.Stop,
        PreviewOwnerId: PreviewOwnerId));
}

protected override void OnFormClosing(FormClosingEventArgs e)
{
    StopPreview();
    base.OnFormClosing(e);
}

public void OnUnload()
{
    StopPreview();
    // unsubscribe handlers here
}

2. Document edit invariants

3. Preview lifecycle checklist

  1. Capture start/end and source buffer once per dialogue open.
  2. Create preview session.
  3. Apply preview buffer to session as settings change.
  4. Play preview with stable owner id.
  5. On Apply: commit session, stop preview playback.
  6. On Cancel/Close: cancel session, stop preview playback.
  7. On plugin unload: stop preview playback and detach event handlers.

4. Menu and pane consistency rules

5. Shipping checklist

Recommended verification: run effect on empty selection, tiny selection, large selection, and full-wave view to catch range bugs.

Back to top