Skip to content

Commit

Permalink
fix: solve potential segfault issue
Browse files Browse the repository at this point in the history
  • Loading branch information
diogomsmiranda committed Nov 24, 2024
1 parent bc50e70 commit c632fe1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion core/src/al/miniaudio_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,26 @@ class MiniaudioBuffer : public impl::Buffer
public:
ma_decoder decoder;

MiniaudioBuffer(const void* data, size_t dataSize)
MiniaudioBuffer(const void* srcData, size_t dataSize)
{
data = operator new(dataSize);
std::memcpy(data, srcData, dataSize);

if (ma_decoder_init_memory(data, dataSize, nullptr, &decoder) != MA_SUCCESS)
{
CUBOS_ERROR("Failed to initialize Decoder from data");
}
else
{
mValid = true;
CUBOS_INFO("Decoder for buffer initialized successfully");
}
}

~MiniaudioBuffer() override
{
ma_decoder_uninit(&decoder);
operator delete(data);
}

float length() override
Expand All @@ -52,6 +57,7 @@ class MiniaudioBuffer : public impl::Buffer

private:
bool mValid = false;
void* data;
};

class MiniaudioListener : public impl::Listener
Expand Down

0 comments on commit c632fe1

Please sign in to comment.