E/libOpenSLES: Too many objects

Facing this error after changing audio settings a few times.

It is quite easy to repro. Plumb an AudioDeviceSelectorComponent and keep toggling right channel on and off. After a few times the system starts logging E/libOpenSLES: Too many objects and the audio device completely dies.

Feels to me it is not destroying properly all the SLObjects.

Looks like the ref counting was broken in some of the refactorings?

I never hit the ContainerDeletePolicy bit when restarting the audio device.

Probably there is a more elegant way but adding a dtor to SlObjectRef::ControlBlock with this logic fixes the issue:

~ControlBlock()
 {
     auto obj = ptr.release();
     if (obj)
         destroyObject(obj);
 }

Thanks for reporting! This was an oversight on our part during some old refactoring, should be fixed here:

1 Like