You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
std is fairly ubiquitous, so it'd be preferable to make this work. I see a few solutions:
Do nothing. Add a caution in the Rustdocs that warns about this exact issue.
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.
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.
The text was updated successfully, but these errors were encountered:
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 ofstd
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:std
is fairly ubiquitous, so it'd be preferable to make this work. I see a few solutions:std::io::Writer
or similar.Option 2 is what I'll try first. I'll update with my findings.
The text was updated successfully, but these errors were encountered: