• Advertisement
Sign in to follow this  

Getting bad PySound handle with threading - Python

This topic is 1745 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm playing some music in python, I want the music to fade in.

 

 

 
 
//I have this function to fade it in
def FadeInMusic( speed,song ):
    while( song.volume < 1):
        song.volume += speed
 

musicHandle = FMOD.playSound( musicPath )
musicHandle.volume = 0
 
# Fade the song in at a given speed
t = Thread(target=FadeInMusic, args=(self.musicFadeSpeed,musicHandle,))
t.start()

 

This works sometimes and then sometimes it gives me a PySound error saying that it's an invalid handle to a PySound object

 

What could I do to make sure it's valid?

Share this post


Link to post
Share on other sites
Advertisement

It's not usually safe to have 2 threads accessing the same object like that. So sometimes the system will work, sometimes it won't, and maybe it'll crash.

 

Could you explain exactly what software and libraries you're using? There is probably a built-in system for handling fade ins and outs.

Share this post


Link to post
Share on other sites

I'm using the BigWorld engine. I know the problems that can occur during threading like that. I'm just starting to learn python and i dont know how to handle threads in Python, or data in other threads. I've looked through their documentation and I can't find anything useful.

 

I've googled how to handle threads in python, but all i can find is stuff that is way more complex than it probably needs to be lol.

Share this post


Link to post
Share on other sites

Threads are complex - whether in Python or anywhere else. It's not something you can just Google to learn how to do properly, because it's essentially concurrent computing which often takes weeks of college classes to fully understand.

 

Basically, you shouldn't be using threads for problems like this. You'll need to find their sound documentation and see what facility they provide for fading sounds in and out.

Share this post


Link to post
Share on other sites

ok, yeah I suppose I'll dig deeper in their docs... Though I've looked before and can't find anything of use. Thanks anyway though :).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement