#How to adduse non Sync resource?
23 messages · Page 1 of 1 (latest)
You may be looking for insert_non_send_resource https://docs.rs/bevy/latest/bevy/ecs/world/struct.World.html#method.insert_non_send_resource
Stores and exposes operations on entities, components, resources, and their associated metadata.
init_non_send_resource is for types that impl Default
Thanks, that is what I should have used, but implementing Default was fine! Same error though. Inserting the resource works, but using it as a ResMut in a system doesn't
what exactly does this interface do? is this going to be an audio library for bevy?
you should use NonSend or NonSendMut instead of Res or ResMut
It holds a handle to a JACK client and to the audio graph that is quite unsafe, but pretty fast. Maybe eventually I'll implement a Bevy plugin interface for it, but it's early days 🙂
you probably should not do non send resources
that should be in its own thread, but systems using non send resource will be on the main thread
you will probably get underruns or your sound will probably lag (depends on what your code is)
Non-send resources are fine if you aren't concerned about the reduced parallelism, or if there's no other alternative
The audio stuff is indeed on it's own thread, but the interface for communicating with the audio thread is not Sync
Yeah so that should be just fine
I think so too. Maybe another layer of indirection will be worth it for parallelism at some point, but I'll cross that bridge when I get there
yeah that would be fine i think, but i personally would just use a ring buffer to communicate with the audio thread
plus points for making it sync
Is a ringbuffer Sync though? I'm using rtrb for some stuff which is SPSC, don't think it can be shared.
also shameless self promotion i have two bevy plugins: bevy_fundsp for making dsp graphs and bevy_oddio for a bevy_audio or bevy_kira_audio alternative
i use the ringbuf crate and it is Sync
also i am waiting for https://github.com/rust-lang/rust/issues/98407 to land, so probably you could wrap rtrb types in Exclusive to make it sync