katyo / oboe-rs

Rust bindings for Oboe high-performance audio IO Android library
64 stars 22 forks source link

AudioStream.Close() binding not calling the derived class implementation #45

Closed RLMorley closed 1 year ago

RLMorley commented 2 years ago

Hi there!

I have been noticing an issue where the Oboe API starts returning the "InternalError" code after my app has been running for a while.

To debug this I created a simple test that simply opens an output stream, and then closes it. This showed that after 40 iterations exactly, the API would start failing.

I then implemented the same in C++ and did not encounter this problem. I also noticed that I was getting more Logcat debug from AAudio showing that close() was being called that I was not seeing when running the equivalent Rust code. I then omitted the close call from the C++ test and observed the same bad behaviour (40 open max).

I then modified the oboe-sys dependency on my machine to add extra debug and discovered that only the base class implementation of close() was being called by the Rust binding, and not the function override in AudioStreamAAudio.cpp

This leaks resources and eventually leads to the API returning internal errors.

Finally, adding a close() call to a helper function AudioStreamWrapper.cpp (e.g. AudioStream_delete) does call the correct derived class implementation.

Can someone else have a look and verify this? I can provide a sample project if needed.

Thanks

erikas-taroza commented 1 year ago

@katyo Hello.

Are there any updates regarding this issue? I am using cpal (which uses this crate) to play audio on Android, and I overrode the oboe dependency using the code in this branch. Unfortunatley, this issue persists.

EDIT: I just tested by changing the dependency in cpal and it works fine. I thought it was overriding but it wasn't. So for now, I will have to fork cpal and update the oboe dependency to use the fixed branch.

Thank you.

erikas-taroza commented 1 year ago

This issue is fixed as of v0.5.0 and should be closed.