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 d05104f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions core/src/al/miniaudio_context.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define MINIAUDIO_IMPLEMENTATION
#include <iostream>
#include <cstring>

#include <cubos/core/al/miniaudio_context.hpp>
#include <cubos/core/reflection/external/string.hpp>
Expand All @@ -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)

Check warning on line 16 in core/src/al/miniaudio_context.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/al/miniaudio_context.cpp#L16

Added line #L16 was not covered by tests
{
data = operator new(dataSize);
std::memcpy(data, srcData, dataSize);

Check warning on line 19 in core/src/al/miniaudio_context.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/al/miniaudio_context.cpp#L18-L19

Added lines #L18 - L19 were not covered by tests

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");

Check warning on line 28 in core/src/al/miniaudio_context.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/al/miniaudio_context.cpp#L28

Added line #L28 was not covered by tests
}
}

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

Check warning on line 35 in core/src/al/miniaudio_context.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/al/miniaudio_context.cpp#L35

Added line #L35 was not covered by tests
}

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 d05104f

Please sign in to comment.