Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use standard library within audio callback #220

Closed
nukep opened this issue Nov 27, 2014 · 1 comment
Closed

Unable to use standard library within audio callback #220

nukep opened this issue Nov 27, 2014 · 1 comment

Comments

@nukep
Copy link
Contributor

nukep commented Nov 27, 2014

SDL audio callbacks are called from a native thread created by SDL. This has consequences in Rust.

I recently learned that std always assumes it's being used from a Rust task. Use of std from outside of a Rust task is undefined behavior, and can cause crashes. rust-lang/rust#17485 (comment)

Simply using std::sync::Mutex from within the callback will cause a crash:

fatal runtime error:  assertion failed: !ptr.is_null()

std is fairly ubiquitous, so it'd be preferable to make this work. I see a few solutions:

  1. Do nothing. Add a caution in the Rustdocs that warns about this exact issue.
  2. Find a way to run a Rust task on the callback thread. I'm unsure if this is possible, though it seems it might be.
  3. Recommend use of the queued audio API (Rust bindings non-existent so far) over the callback API, which can be implemented as a std::io::Writer or similar.

Option 2 is what I'll try first. I'll update with my findings.

@AngryLawyer
Copy link
Member

You sound like you have a much better handle on this than I do, cheers.

AngryLawyer added a commit that referenced this issue Nov 27, 2014
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

No branches or pull requests

2 participants