Testing Error with clearing buffer from source: Invalid OperationWarning: audio error: Failed to clear buffer from source: Invalid Operation

Hi,

We sporadically get that message sporadically in a game we are currently working on. I’m not 100% on the exact steps to reproduce this, but I’ve been able to make it reproduce just by stopping and starting audio on the same channel.

The code below is a pared down example of something similar that happens in the game we’re currently working on. It can be difficult to reproduce, but it does happen. If you make the right sequence of calls with the correct timing, you’ll get the following output:

17dTesting Error with clearing buffer from source: Invalid OperationWarning: audio error: Failed to clear buffer from source: Invalid Operation

Any subsequent attempts to play audio on that channel (source?) fails, with this trace:

Warning: audio error: Could not bind data to source: Invalid OperationWarning: audio error: Could not bind data to source: Invalid

It’s not a Lua error either, so it appears to be coming from within the audio API. What does this message mean, and how do we prevent it from happening? We filed a ticket but haven’t received any comments on progress towards addressing this issue. Is this being addressed? If it can’t be addressed in a timely manner, are there any workarounds that we can use?

Here is sample code:

local audio = require "audio" local sample, channel local sounds = {"drum\_1.wav", "drum\_3.wav"} local currentIndex = 1 function onTouch(event)     if event.phase == "began" then         stopAudio()     end end function replayAudio()     stopAudio()     playAudio() end function stopAudio()     audio.stop(channel) end function playAudio()     if sample then         audio.dispose(sample)         sample = nil     end     currentIndex = currentIndex + 1     if currentIndex \> #sounds then         currentIndex = 1     end     sample = audio.loadSound(sounds[currentIndex])     channel = audio.findFreeChannel()     audio.play(sample, {         loops = 0,         channel = audio.findFreeChannel(),         onComplete = replayAudio,     }) end playAudio() display.getCurrentStage():addEventListener("touch", onTouch)

Hi,

I have the same problem, did you find any solution?

I would like to understand if the problem is the way I use sounds in my code or if it could be a bug of audio library.

Thank you

I encountered the same problem here.

Hi @djighen, d.mach,

I think you’ll need to post some specific code on how you’re handling audio, and what seems to cause this issue for you, since your code is not going to exactly match the original poster’s code.

Thanks,

Brent

Hi,

I have the same problem, did you find any solution?

I would like to understand if the problem is the way I use sounds in my code or if it could be a bug of audio library.

Thank you

is this 17dTesting Error error fixed yet?

Hi @jacques1,

As I responded before, we’ll need to see some code from somebody who’s still experiencing this issue in their app, as the OP’s submission is around 10 months old and we never received a bug submission or any hardware details to help diagnose this.

Thanks,

Brent

I encountered the same problem here.

Hi @djighen, d.mach,

I think you’ll need to post some specific code on how you’re handling audio, and what seems to cause this issue for you, since your code is not going to exactly match the original poster’s code.

Thanks,

Brent

is this 17dTesting Error error fixed yet?

Hi @jacques1,

As I responded before, we’ll need to see some code from somebody who’s still experiencing this issue in their app, as the OP’s submission is around 10 months old and we never received a bug submission or any hardware details to help diagnose this.

Thanks,

Brent

If anyone is interested. I have been recently getting this error. By using audio.loadStream it helps a lot. Almost error free unless you go really crazy.

Oh and all you need to for the error is using a performWithDelay of around 140 milliseconds infinite repeating trigger on an audio.loadSound 

Hi Rob

Could you explain more your solution with some code example?

Thanks!

Best

Olivier

We would still love to have a bug report on this.

Rob

Hi Oliver. All I did was change any loading of sounds which normally go like blah=audio.loadSound to blah=audio.loadStream. I’m not saying it will definitely fix your issue but it fixed the issue I had that was more problematic on Apple systems. It will be interesting to see if this helps you.

Thanks Rob

Olivier

No more errors even if I go really crazy! :slight_smile:

Here my code

local wordsTab = {"word1","word2",....,"wordn"} --your word list, each word has a mp3 file associated local currentIndex = 1 local soundFile local soundHandler local function onNext() audio.stop() audio.dispose(soundFile) soundFile = nil soundHandler = nil local word = wordsTab[currentIndex] local soundFileName = "sounds/words/"..word..".mp3" --your mp3 directory soundFile = audio.loadStream(soundFileName) soundHandler = audio.play(soundFile) currentIndex = currentIndex + 1 end local nextButton = widget.newButton { label = "NEXT", onRelease = onNext, } nextButton.x = display.contentCenterX nextButton.y = display.contentCenterY

Hope this helps :slight_smile:

Thanks again

Olivier

That’s great to hear. On a side note I personally wouldn’t even bother disposing audio unless it’s a game and leaving a level which never uses the audio again. I would have assumed disposing and loading might give a delay but maybe it’s not noticeable enough. I would have stuck all the load.streams in the table then just play the table and index. That’s just me though :slight_smile:

Loading  a stream is great and all, but you can’t play the sound repeatedly at the same time, so it’s useless. I constantly get  “Warning: audio error: Could not bind data to source: Invalid Operation” as I play any random sound and it often loops.  Fortunately this does not occur on iOS or Android devices though and seems to be solely on my Mac (Yosemite), but it gets annoying