audio.stop() killing all sound

When I use audio.dispose( tapSound ) and tapSound = nil, I get these errors:

ALmixer\_FreeData: alDeleteBuffers failed. Invalid Operation

and

malloc: \*\*\* error for object 0x5a61f4: incorrect checksum for freed object - object was probably modified after being freed. \*\*\* set a breakpoint in malloc\_error\_break to debug

After hunting around for an answer, it looked like I had to stop the sound before disposing it and setting it to nil by using audio.stop(). Now, with audio.stop(), the background music is getting snuffed out. Here’s some of the relevant code I’m working with if anyone can help me out:

-- AUDIO intromusic = audio.loadStream( "intromusic.mp3" , true) audio.play( intromusic, { channel=1, loops=-1 } ) local tapSound = audio.loadSound( "button.mp3" )

[code]local onPlayTouch = function( event )
if event.phase == “release” and playBtn.isActive then
audio.play( tapSound, { onComplete=audio.stop( tapSound ) } )
audio.dispose( tapSound )
tapSound = nil
cleanGroup( menuGroup )
menuGroup = nil
director:changeScene( “levelselection” )

isLevelSelection = true
isOFButton = false
isMoreSection = false

end[/code]

The intro music ought to continue into the “levelselection” screen but stops. In the game, I have this same situation going on and when you move on to the next level, all the sound fx are gone.

Also, if you’re taking a looking at this and see that I’m using that ‘cleangroup’ incorrectly, please let me know. I’ll put up another post regarding that issue separately though.

Thanks!

VanDono - Ratatat Graphics [import]uid: 14032 topic_id: 8977 reply_id: 308977[/import]

I think audio.stop requires a channel id to stop, not a sound handle. Using 0 stops sound on all channels, and any other integer stops all sound on that channel. If you want to stop that particular tap sound, I think you could specify a channel when playing the sound and then using that channel when calling audio.stop, or even just pause the sound. [import]uid: 8673 topic_id: 8977 reply_id: 32772[/import]

It works! I had tried doing that earlier but called the channel wrong in the audio.stop. This is how it got it to work:

local onPlayTouch = function( event )  
 if event.phase == "release" and playBtn.isActive then  
 audio.play( tapSound, { channel=2, onComplete=audio.stop( 2 ) } )  
 audio.dispose( tapSound )  
 tapSound = nil  
 cleanGroup( menuGroup )  
 menuGroup = nil  
 director:changeScene( "levelselection" )  
  
 isLevelSelection = true  
 isOFButton = false  
 isMoreSection = false  
  
 end  
end  

Thanks! Now on to that cleangroup… [import]uid: 14032 topic_id: 8977 reply_id: 32773[/import]

Mmm, still getting this:

ALmixer_FreeData: alDeleteBuffers failed. Invalid Operation

…keeps crashing the simulator, too. [import]uid: 14032 topic_id: 8977 reply_id: 32775[/import]

Got it. Had to set the audio.dispose() to the channel as well. [import]uid: 14032 topic_id: 8977 reply_id: 32777[/import]

I’m fighting this issue as well. Build 777. audio.dispose() is suppose to take the sound not the channel, right? [import]uid: 21331 topic_id: 8977 reply_id: 99364[/import]

vandono9: Your code has two different mistakes, each of which will break your audio.

  • The onComplete parameter for audio.play() must take a function. You are not passing it a function, but invoking a function which returns a numeric value which then gets assigned to onComplete.

  • Calling audio.dispose() right when you start playing the sound is wrong. The audio is still playing and you are trying to delete the memory. audio.dispose should probably be in your onComplete function, not immediately after audio.play().
    TheRealTonyK: Yes, audio.dispose() works on handles, not channels. [import]uid: 7563 topic_id: 8977 reply_id: 99697[/import]