Skip to content

fix audio device hot-plug - #3

Open
leonardo-spy wants to merge 3 commits into
BlackLabelHQ:masterfrom
leonardo-spy:bugfix/fix-audio-device-hot-plug
Open

fix audio device hot-plug#3
leonardo-spy wants to merge 3 commits into
BlackLabelHQ:masterfrom
leonardo-spy:bugfix/fix-audio-device-hot-plug

Conversation

@leonardo-spy

Copy link
Copy Markdown

No description provided.

Copilot AI review requested due to automatic review settings August 3, 2026 12:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to fix audio device hot-plug handling by wiring SDL audio-device events into the host and adding OpenAL device reconnect logic in the audio mixer loop.

Changes:

  • Initialize SDL’s audio subsystem alongside the game controller subsystem so audio device add/remove events are emitted.
  • Dispatch SDL audio device add/remove events to the Audio subsystem.
  • Add periodic reconnect logic in Audio (including optional ALC_SOFT_reopen_device support and a manual reopen fallback).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
RecompOne.Runtime/Host/InputManager.cs Initializes SDL audio subsystem and forwards SDL audio device hot-plug events to Audio.
RecompOne.Runtime/Host/Audio.cs Adds device-change flagging and reconnect/reopen logic in the mixer loop.
Suppressed comments (2)

RecompOne.Runtime/Host/Audio.cs:127

  • IsDeviceConnected() currently returns true when _device is null (preventing retries after a failed reopen) and queries ALC_CONNECTED unconditionally. If ALC_EXT_disconnect isn't supported, the invalid enum likely leaves 'connected' at 0, causing a forced reopen every second on platforms/backends without that extension.
    static bool IsDeviceConnected()
    {
        if (_alc == null || _device == null) return true;
        int connected = 0;
        _alc.GetContextProperty(_device, (GetContextInteger)AlcConnected, 1, &connected);
        return connected != 0;
    }

RecompOne.Runtime/Host/Audio.cs:145

  • ReopenDevice() deletes the source/buffers but leaves _source and _buffers populated. If OpenDevice() fails, subsequent reopen attempts will operate on stale/deleted IDs (and with _device left null), which can lead to repeated errors and prevent recovery.
            _al.DeleteSource(_source);
            fixed (uint* ptr = _buffers)
                _al.DeleteBuffers(NumBuffers, ptr);

            if (_context != null) { _alc.DestroyContext(_context); _context = null; }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread RecompOne.Runtime/Host/Audio.cs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants