Crash with AudioEngine cocos2dx 3.16 on android wave short sounds

Hello,

I have updated my cocos audio folder to use the new sound engine for decoding up to 3.16 i guess.

When I try to play mp3 (short or long) and wave (long), everything works fine. When I try to play short wave sounds (as per the definition in AutioPlayerProvider:

static AudioFileIndicator __audioFileIndicator[] = {
    {"default", 128000}, // If we could not handle the audio format, return default value, the position should be first.
    {".wav",    1024000},
    {".ogg",    128000},
    {".mp3",    160000}
};

The engine crashes with a SIGILL in the AudioDecoderWav.cpp:

int AudioDecoderWav::onWavClose(void* datasource)
{
}

I have tested it in a very very simple project with only the engine and this sound played, and it consistently crash on all the android devices I have tested (google pixel C, galaxy tab s3, oneplus 5)

The first part of the stack is here (because the process is multithreaded)

l 242: AudioEngine->play2d
l 260: AudioEngineImpl->play2d
l 155: AudioPlayerProvider->getAudioPlayer
l 303: AudioPlayerProvider->_threadPool->pushTask

this is done on one thread, then, once the task is executed later, the stack trace is as follow:

l 307:  AudioPlayerProvider: decoder->start()
l 100 AudioDecoder: ret = decodeToPcm()

DecodeToPcm is virtual and the Wav one is implemented in AudioDecoderWav.cpp. When the code reach this function, it goes through all the normal things (the SF_INFO looks good, the SNDFILE* handle looks good too)

It fills the _result with what appears to be good data and then, when trying to execute

if (handle != NULL)
    sf_close(handle);

it crashes with SIGILL in the sf_close(handle), which calls the audioDecodeWav->onWavClose.

Note that when trying to play the sound using the default URLAudioPlayer, the sounds plays well. So I am inclined to think it is a bug in the engine.

Any help would be appreciated.

All right, I have found the problem and the solution to it.

The AudioDecoderWav::onWavClose(void* datasource) implementation doesn’t return a value, even though it is defined as returning an int.

so you just need to add a return 0; in the funciton and the sigill crash disappear:

int AudioDecoderWav::onWavClose(void* datasource)
{
    return 0;
}

Yes, you’re right.
If you search on the github. It’s already fixed a month ago.