After close and stop sound, FMOD failed to initialise again by "FMOD::System_Create(&system)"

After close and stop sound when we quickly initialising FMOD again by using “FMOD::System_Create(&system)”, it gives an error “FMOD_ERR_MEMORY”.

Can you please look into this issue and let me know what is going wrong?

Thanks

FMOD_ERR_MEMORY means not enough memory or resources. In the context of FMOD::System_Create, this error arises if you have run out of physical memory or if you have more than 8 system objects. If you are calling System_Create multiple times then I suspect it’s because you have more than 8 system objects, but on a memory constrained environment such as mobile it’s feasible you could be running out of physical memory.
Are you calling release() on your system objects before attempting to create new systems with FMOD::System_Create?
If you could please provide me with your FMOD version and a reproduction or code sample of what you are doing when the error occurs then I can look into the issue further.

Hi, I am sharing some piece of code below, some time it work and return “FMOD_OK” but when I am quick start sound again after shut down, it doesn’t work.
One more thing I want to add that “releaseSound” and “releaseSystem” doesn’t effect result at all.

Common_Init(&extradriverdata);
/*
 Create a System object and initialize.
*/


[self releaseSound];
[self releaseSystem];
    result = FMOD::System_Create(&system); //This line return “FMOD_ERR_MEMORY”
     if (result == FMOD_OK){
    ERRCHECK(result);

  result = system->getVersion(&version);
  ERRCHECK(result);

FMOD_VERSION 0x00020010

Thanks.

Thank you for the additional information. I haven’t been able to reproduce any errors by emulating your example, can you please include your method definitions for releaseSound and releaseSystem?
One other thing I am curious about- why do you need to release and create a new System object here? Can you continue to use the existing System object without releasing it and immediately creating a new one?

-(void)releaseSound {
    if(sound)
    {
        result = sound->release();
        ERROR_CHECK(result);
        sound = 0;
    }
}

-(void)releaseSystem {
    if(system)
    {
        result = system->close();
        ERROR_CHECK(result);
        
        result = system->release();
        ERROR_CHECK(result);
    }
}

Above is the whole code for releaseSound and releaseSystem functions.

I need to create new system here to play set and play sound again after shut down and close.

Am I doing something wrong here?

Are you creating a new system every time you play a sound? I am just trying to think of why you would need to release the system and then create a new one instead of storing it for the lifetime of the application and releasing it just before the application closes.
Have you tried adding a short call to sleepForTimeInterval before calling FMOD::System_Create and seeing if that affects the result?

I’m experiencing a similar issue, but there are no errors during the initialization of fmod and sound playback. Here’s my code:


JNIEnv *mEnv = env;
int code = 0;
code = System_Create(&system_);
LOGI("playAiSound-%s-%d", "System_Create", code)
bool isPlaying = true;
jclass cls;
jmethodID methodid;
const char *path_cstr = mEnv->GetStringUTFChars(path, nullptr);
LOGI("playAiSound-%s", path_cstr)
try {
    cls = (env)->FindClass("dev/keego/voice/fmodsound/bridge/SoundPlayUtil");
    methodid = (env)->GetStaticMethodID(cls, "onInitSound", "()V");
    (env)->CallStaticVoidMethod(cls, methodid);
    system_->init(32, FMOD_INIT_NORMAL, nullptr);
    // Create sound
    code = system_->createSound(path_cstr, FMOD_LOOP_NORMAL, nullptr, &sound_);
    LOGI("playAiSound-%s-%d", "createSound", code)
    if (path != nullptr) {
        mEnv->ReleaseStringUTFChars(path, path_cstr);
    }
    code = system_->playSound(sound_, nullptr, false, &channel_);
    LOGI("playAiSound-%s-%d", "playSound", code)
    methodid = (env)->GetStaticMethodID(cls, "onPlaySound", "()V");
    (env)->CallStaticVoidMethod(cls, methodid);
    unsigned int length = 0;
    sound_->getLength(&length, FMOD_TIMEUNIT_MS);
    LOGI("playAiSound-%d", length)

} catch (...) {
    LOGE("playAiSound-%s", "play error!")
    code = 1;
    goto end;
}
while (isPlaying) {
    usleep(100);
    channel_->isPlaying(&isPlaying);
}
LOGI("playAiSound-%s", "play over!")
goto end;
end:

code = sound_->release();
LOGI("playAiSound-%s-%d", "release sound!", code);
code = system_->close();
LOGI("playAiSound-%s-%d", "close system!", code);
code = system_->release();
LOGI("playAiSound-%s-%d", "release system!", code);
methodid = (env)->GetStaticMethodID(cls, "onComplete", "()V");
(env)->CallStaticVoidMethod(cls, methodid);
return code;

Here’s the logcat:

2023-03-27 05:57:11.472  3890-4056  FmodSound               dev.keego.voice.changer              I  playAiSound-System_Create-0
2023-03-27 05:57:11.472  3890-4056  FmodSound               dev.keego.voice.changer              I  playAiSound-/storage/emulated/0/Music/VoiceChanger/1679844887938.wav
2023-03-27 05:57:11.522  3890-4056  FmodSound               dev.keego.voice.changer              I  playAiSound-createSound-0
2023-03-27 05:57:11.522  3890-4056  FmodSound               dev.keego.voice.changer              I  playAiSound-playSound-0
2023-03-27 05:57:11.522  3890-4056  FmodSound               dev.keego.voice.changer              I  playAiSound-14293
2023-03-27 05:57:11.586 3890-4056 FmodSound dev.keego.voice.changer I playAiSound-play over!
2023-03-27 05:57:11.586 3890-4056 FmodSound dev.keego.voice.changer I playAiSound-release sound!-0
2023-03-27 05:57:11.598 3890-4056 FmodSound dev.keego.voice.changer I playAiSound-close system!-0
2023-03-27 05:57:11.598 3890-4056 FmodSound dev.keego.voice.changer I playAiSound-release system!-0


Upon closer inspection, my program is getting stuck in the following loop:

```cpp
while (isPlaying) {
    usleep(100);
    channel_->isPlaying(&isPlaying);
}

At this point, no sound is being played by the system.

This questions will be answered in this forum post: https://qa.fmod.com/t/after-closing-and-stopping-sound-fmod-fails-to-play-audio-when-quickly-reinitializing/2002

Hi, @jeff_fmod @Connor_FMOD
In my case, I have a sound card that connects some audio devices those numbers are more than 8. In my previous solution, I created multiple ‘system’ instance that binds a related device, however, I met ‘FMOD_ERR_MEMORY’. The reason you mentioned above(8 is maximum limit that fmod could support).

My question is how to handle my case, if the audio device number is over 8? Any idea?

Hi,

Unfortunately, 8 is a hard limit for FMOD systems.