#How to adduse non Sync resource?

23 messages · Page 1 of 1 (latest)

rancid swallow
#

Hiya! I have this interface to my audio engine which is Send but not Sync and it mustn't be cloned or created more than once. How can I add it to Bevy and use it from a system? As a resource/ResMut doesn't work and init_non_send_resourcedidn't work either.

crude rivet
#

init_non_send_resource is for types that impl Default

rancid swallow
#

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

spiral knoll
#

what exactly does this interface do? is this going to be an audio library for bevy?

spiral knoll
rancid swallow
#

Aha!!

#

That works, thank you very much!

rancid swallow
spiral knoll
#

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)

crude rivet
#

Non-send resources are fine if you aren't concerned about the reduced parallelism, or if there's no other alternative

rancid swallow
#

The audio stuff is indeed on it's own thread, but the interface for communicating with the audio thread is not Sync

crude rivet
#

Yeah so that should be just fine

rancid swallow
#

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

spiral knoll
#

plus points for making it sync

rancid swallow
#

Is a ringbuffer Sync though? I'm using rtrb for some stuff which is SPSC, don't think it can be shared.

spiral knoll
#

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

spiral knoll