Getting bad PySound handle with threading - Python

Started by
3 comments, last by Muzzy A 11 years ago

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?

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.

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.

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.

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 :).

This topic is closed to new replies.

Advertisement