RoboMat Posted August 18, 2013 Share Posted August 18, 2013 Heyho,I have stumbled across some sound issues I can't resolve in my Lockpicking mod. What I do is play a looped sound once the player starts a timed action with:----- Starts the Timed Action.-- TODO fix sound issues (looping endlessly)function ISPickLock:start() local door = self.object; self.lockPickingSound = getSoundManager():PlayWorldSound(Lockpicking_Config.soundLockpicking, false, door:getSquare(), 0, 10, 1, true);endI then stop it either when the player aborts the timed action (e.g. by walking away):----- Stops the Timed Action.--function ISPickLock:stop() print(self.lockPickingSound); getSoundManager():StopSound(self.lockPickingSound); ISBaseTimedAction.stop(self);endor when the timed action is completed:function ISPickLock:perform() ... getSoundManager():StopSound(self.lockPickingSound); ISBaseTimedAction.perform(self);endFrom what I have experienced, it works perfectly fine when only one or two sounds are played at the same time, but if the player quickly starts and aborts the timed action the looping sound gets stuck and continues to play endlessly. This usually can only be fixed by restarting the game.Any suggestions? Link to comment Share on other sites More sharing options...
Eggplanticus Posted August 18, 2013 Share Posted August 18, 2013 Is it possible that the cancellation occurs before start() returns? Link to comment Share on other sites More sharing options...
johndough Posted August 18, 2013 Share Posted August 18, 2013 This is very similar to what I'm doing in my Corpse mod. I also experienced issues with looping sounds not stopping. I decided to not use looping sounds, and instead I periodically start new sounds(I have av set of 4-5 sounds that are randomly played) in the :update() method on the TimedAction object. I also make sure to stop the sound that is currently playing, so there are no multiple sounds. Despite this, the getSoundManager():StopSound() will sometimes not work when I call it at the end of :perform(). Link to comment Share on other sites More sharing options...
johndough Posted August 18, 2013 Share Posted August 18, 2013 I also experienced sounds not starting now. It was raining - I don't know if that is relevant. It's not reproducible. Link to comment Share on other sites More sharing options...
RoboMat Posted August 18, 2013 Author Share Posted August 18, 2013 Is it possible that the cancellation occurs before start() returns? I will test this, but then it should work when I start playing the sound in the constructor (new), because it's the first function that is called. IIRC I've tried that and it also didn't work. I also experienced sounds not starting now. It was raining - I don't know if that is relevant. It's not reproducible. To me it "feels" like PZ is getting confused once there are too many sounds played at the same time... Link to comment Share on other sites More sharing options...
johndough Posted August 19, 2013 Share Posted August 19, 2013 Cancellation before start() returns shouldn't be possible, because, unless this is programmed in a very unusal way, both of these functions belong to the same thread. What is possible is that sound is handled on a separate thread, and that cancellation occurs before that thread gets a chance to play the sound. Link to comment Share on other sites More sharing options...
RoboMat Posted August 19, 2013 Author Share Posted August 19, 2013 Cancellation before start() returns shouldn't be possible, because, unless this is programmed in a very unusal way, both of these functions belong to the same thread. What is possible is that sound is handled on a separate thread, and that cancellation occurs before that thread gets a chance to play the sound. Hm... my knowledge about threading is very limited so excuse my ignorance. As far as I understand, it would explain why stopping the sound doesn't work on :stop() occasionally, but you also mentioned problems when trying to stop it at the end of :perform() (which always got called after start() in my tests). Any thoughts on how we could avoid this issue? Link to comment Share on other sites More sharing options...
johndough Posted August 19, 2013 Share Posted August 19, 2013 It could be anything. Both starting and stopping sounds seems slightly unreliable right now. Maybe we should make a thread with functions that are broken. You could do as I did and measure the lenght of your sound and just play it over and over without the loop flag. RoboMat 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now