Skip to content Skip to sidebar Skip to footer

Openal Application Crashes/hangs When I Pass Non-nullptr To `albufferdata()` From Native Code

I'm trying to play some sound on Android using OpenAL and C/C++. I'm using SDL framework. I keep getting mysterious crashes with alBufferData() even when my code is as simple as: A

Solution 1:

Hello :) for me the line

alBufferData(buf, AL_FORMAT_MONO8, sound_wave, 8000, 8000);

should be part of the issue. From documentation :

voidalBufferData(
       ALuint      buffer,
       ALenum      format,
       const ALvoid *data,
       ALsizei      size,
       ALsizei      freq
      );

size : the size of the audio data in bytes freq : the frequency of the audio data

My first point your freq (8000) is perhaps unsupported by implementation, try 44100 as the context frequency. You'll need to enlarge your sound_wave array. If it's work you'll can get the '8k' frequency effect by having the same sample value for 5/6 samples ;)

My second point is for the size, it may be better to use the type ALubyte from al.h and for the size something like sizeof(sound_wave) or samples_count * sizeof(ALubyte) to be sure and always match code changes.

But for documentation giving NULL in place of data will set AL_INVALID_VALUE error state (as alGetError() returns)

Hope it'll help

Solution 2:

It seems like a bug in OpenAL, which also affects MacOS. It should be already fixed.

Also it crashes only when the library is built in "Release" or "RelWithDebInfo" modes. Switching to any random string or "Debug" fixes the issue.

Post a Comment for "Openal Application Crashes/hangs When I Pass Non-nullptr To `albufferdata()` From Native Code"