Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Getting bad PySound handle with threading - Python


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Muzzy A   Members   -  Reputation: 644

Like
0Likes
Like

Posted 05 April 2013 - 09:35 PM

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?



Sponsor:

#2 Kylotan   Moderators   -  Reputation: 3338

Like
0Likes
Like

Posted 08 April 2013 - 09:28 AM

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.



#3 Muzzy A   Members   -  Reputation: 644

Like
0Likes
Like

Posted 10 April 2013 - 06:26 PM

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.



#4 Kylotan   Moderators   -  Reputation: 3338

Like
2Likes
Like

Posted 11 April 2013 - 05:01 AM

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.



#5 Muzzy A   Members   -  Reputation: 644

Like
0Likes
Like

Posted 11 April 2013 - 09:45 PM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS