audio onComplete bug caused crash

@vlads Hi, I can confirm there is a bug with audio.play onComplete, it caused crashes on some android phones. Even if the function is empty, it will crash.
My previous versions had about a 10% crash rate(more than 800 crashes in less than a week).
My solution is to remove onComplete from all audio, now there are no crashes.
I have an android 11 Samsung phone, but never once encounter this crash, but on some player’s phone(same model) it crashes every few minutes.
The error on android is

signal 11 (SIGSEGV), code 2 (SEGV_ACCERR)
libcorona.so!libcorona.so (offset 0x37e000)
Rtt::ALmixerSoundCompletionEvent::~ALmixerSoundCompletionEvent()) (SourceCode: /Users/runner/work/corona/corona/librtt/Rtt_PlatformOpenALPlayer.cpp:76)

I can replicate this bug on windows, the simulator will force quit with this error

The stdin connection has closed.

the following simple code can replicate this error, and removing onComplete it will not crash.
The sound has to be short to reproduce this crash quickly, I use 0.2 second wave and let it run for a while(30 seconds to a few minutes)

mySound = audio.loadSound("mySound.wav")
soundTesting = function()
end

function checkSound ()
	for j = 1, 30 do
		audio.play(mySound , { onComplete=soundTesting })
	end
end	
Runtime:addEventListener( "enterFrame", checkSound )
1 Like

Just tested this and I get no crashes on sim or device. Maybe your wav file (or simply using wav) is the issue. I only use mp3 and don’t get this.

Also, why are you trying to play 30 wav files every frame? There are only 32 channels for audio so on frame 2 you have run out of available channels!

I just tested with mp3, it crashes too. ​
The sound has to be short because it has to trigger onComplete to cause the bug. If your audio is long, you have to wait for a while for it to crash.

I use for j = 1, 30 do to speed up the testing, for a 1 sec audio, it takes about 30 seconds to crash.

my actual game only use less than 10 channels at anytime.

as to why 10% of the phones has this crash issues for my actual game, I have no idea.
Same phone model, same android version, same game version, some players crash every few minutes, but on my testing devices never once crashed even when I watch youtube or listen to spotify at the same time.
I spent weeks debugging this issue as I can’t replicate it at all. Finally narrow down to audio, and I use the code to stress test onComplete

OK I left a test running for 10 mins and eventually sim crashed. So something is wrong. Best to file a bug on https://github.com/coronalabs/corona/issues

1 Like

I tried different audio, it crashes every time. You have to wait for 30 seconds to a few minutes.
I didn’t test on mac, but on windows and android devices it crashes.

If your app doesn’t have any signal 11 (SIGSEGV), code 2 (SEGV_ACCERR) crashes then it’s great.

for me removing onComplete solved this weird crash completely.

This is a great find, and like SGS said, you should file a bug report about this. :+1:

1 Like

:ok_hand: bug filed.