Add assert for buffer

This commit is contained in:
Christian Semmler 2024-12-18 14:11:13 -07:00
parent 61c760d9d4
commit 9546ecbd9e
2 changed files with 4 additions and 1 deletions

View File

@ -96,6 +96,7 @@ class MxWavePresenter : public MxSoundPresenter {
struct { struct {
ma_audio_buffer buffer; ma_audio_buffer buffer;
MxU8* data; MxU8* data;
MxU32 length;
MxU32 offset; MxU32 offset;
} m_ab; } m_ab;

View File

@ -59,6 +59,7 @@ void MxWavePresenter::Destroy(MxBool p_fromDestructor)
MxBool MxWavePresenter::WriteToSoundBuffer(void* p_audioPtr, MxU32 p_length) MxBool MxWavePresenter::WriteToSoundBuffer(void* p_audioPtr, MxU32 p_length)
{ {
if (m_action->IsLooping()) { if (m_action->IsLooping()) {
assert(m_ab.offset + p_length <= m_ab.length);
memcpy(m_ab.data + m_ab.offset, p_audioPtr, p_length); memcpy(m_ab.data + m_ab.offset, p_audioPtr, p_length);
m_ab.offset += p_length; m_ab.offset += p_length;
return TRUE; return TRUE;
@ -136,7 +137,8 @@ void MxWavePresenter::StartingTickle()
sampleRate sampleRate
); );
m_ab.data = new MxU8[ma_get_bytes_per_frame(format, channels) * sizeInFrames]; m_ab.length = ma_get_bytes_per_frame(format, channels) * sizeInFrames;
m_ab.data = new MxU8[m_ab.length];
ma_audio_buffer_config config = ma_audio_buffer_config config =
ma_audio_buffer_config_init(format, channels, sizeInFrames, m_ab.data, NULL); ma_audio_buffer_config_init(format, channels, sizeInFrames, m_ab.data, NULL);