barsoosayque / libgdx-oboe

🎶 libGDX audio replacement for Android (API 16+) built on top of Oboe.
MIT License
55 stars 11 forks source link

Limit memory access of music playback to buffer dimensions #21

Closed dasisdormax closed 11 months ago

dasisdormax commented 11 months ago

This fixes a segfault that occurred when playing specific files.

In these cases, the playback would continue even after the file was ended. There, the library would play back the raw memory contents after the buffer, until eventually the app gets killed for illegal memory accesses.

dasisdormax commented 11 months ago

Is there any reason for int32_t instead of unsigned ? Other than that, LGTM

Yep. frames_in_pcm - m_current_frame did end up less than zero.

I'll include your suggestions.

barsoosayque commented 11 months ago

Yep. frames_in_pcm - m_current_frame did end up less than zero.

Hmm. This is weird, but understandable for wacky android audio (or my half-hearted code). If I understand everything correctly,

uint32_t frames_to_process = std::clamp(frames_in_pcm - m_current_frame, 0, frames);

should be a better solution ? We wouldn't want to play a negative amount of frames, but it's been awhile since I touched this code, may be wrong

dasisdormax commented 11 months ago

The latest version works fine in my testing and still fixes the issue.

It uses clamp as suggested with signed integers as input, and uses the result ( > 0 ) as unsigned int.

barsoosayque commented 11 months ago

Okay, looking good. Thank you !