Skip to content

Install error callback before probing devices in RtAudio constructor - #489

Merged
garyscavone merged 1 commit into
thestk:masterfrom
dime-online:fix-error-callback-install
Oct 1, 2026
Merged

garyscavone merged 1 commit into
thestk:masterfrom
dime-online:fix-error-callback-install

Conversation

@dime-online

Copy link
Copy Markdown
Contributor

The RtAudio(Api, ErrorCallback) constructor only installed the error callback after
openRtApi() returned, but in the UNSPECIFIED fallback path it probes devices
(getDeviceNames()) before the callback exists on the API object, so probing warnings
and errors (e.g. RtApiCore::probeDeviceInfo messages) were printed to stderr even
when a callback was supplied - with no way for the application to intercept them
(#473).

Forward the callback into openRtApi() (a private helper; default argument, so no
public API change) and install it as soon as the API object is created. Errors emitted
by the constructor's own device enumeration are now routed to the user's callback.
Errors raised inside the API constructors themselves are still not capturable; that
would need API constructor signature changes and is out of scope here.

Fixes #473

Testing

Not run: no RtAudio build available here, the change was verified by reading the
sources. Suggested checks:

  • Construct RtAudio(RtAudio::UNSPECIFIED, myCallback) on a machine where a probed
    API emits a warning (no JACK server running, or a CoreAudio device that fails
    probeDeviceInfo): the message must arrive via the callback, not stderr.
  • Constructing with a specific API that has compiled support behaves as before.
  • Constructing with an API that has no compiled support: the "no compiled support for
    ..." message still goes through the callback.
  • showWarnings(false) behavior unchanged.

The RtAudio(Api, ErrorCallback) constructor created each API object with
openRtApi() and only installed the user's error callback afterwards, but
the constructor then enumerates devices itself (getDeviceNames() in the
compiled-API fallback loop), so warnings and errors emitted during that
probing (e.g. RtApiCore::probeDeviceInfo / RtApiJack::probeDevices
messages) fell back to being printed on stderr even though a callback
was supplied.

Forward the callback into openRtApi() and install it on the API object
as soon as the object exists, so all subsequent errors and warnings,
including the constructor's own device probing, are routed to the user's
callback.

Errors raised inside the API constructors themselves (before the object
is returned) are still not capturable; that would require API
constructor changes.

Fixes thestk#473
@garyscavone
garyscavone merged commit ea2c88c into thestk:master Oct 1, 2026
12 checks passed
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.

Impossible to prevent error messages in RtAudio constructor.

2 participants