Skip to content

Commit

Permalink
fix(audio): fix sound_uninit() segfault
Browse files Browse the repository at this point in the history
Co-Authored-By: João Miguel Nogueira <[email protected]>
  • Loading branch information
diogomsmiranda and Dageus committed Nov 26, 2024
1 parent 6ece7c3 commit 3fd3e5e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion core/src/al/miniaudio_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,23 @@ class MiniaudioSource : public impl::Source
public:
MiniaudioSource(ma_engine& engine)
: mEngine(engine)
, mSoundInitialized(false)

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

View check run for this annotation

Codecov / codecov/patch

core/src/al/miniaudio_context.cpp#L104

Added line #L104 was not covered by tests
{
}

~MiniaudioSource() override
{
ma_sound_uninit(&mSound);
mSoundInitialized = false;

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

View check run for this annotation

Codecov / codecov/patch

core/src/al/miniaudio_context.cpp#L111

Added line #L111 was not covered by tests
}

void setBuffer(Buffer buffer) override
{
ma_sound_uninit(&mSound);
if (mSoundInitialized)
{
ma_sound_uninit(&mSound);
mSoundInitialized = false;

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

View check run for this annotation

Codecov / codecov/patch

core/src/al/miniaudio_context.cpp#L118-L119

Added lines #L118 - L119 were not covered by tests
}

// Try to dynamically cast the Buffer to a MiniaudioBuffer.
auto miniaudioBuffer = std::static_pointer_cast<MiniaudioBuffer>(buffer);
Expand All @@ -121,6 +127,8 @@ class MiniaudioSource : public impl::Source
CUBOS_ERROR("Failed to initialize sound from buffer");
return;
}

mSoundInitialized = true;

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

View check run for this annotation

Codecov / codecov/patch

core/src/al/miniaudio_context.cpp#L131

Added line #L131 was not covered by tests
}

void setPosition(const glm::vec3& position) override
Expand Down Expand Up @@ -211,6 +219,7 @@ class MiniaudioSource : public impl::Source
private:
ma_sound mSound;
ma_engine& mEngine;
bool mSoundInitialized;
};

class MiniaudioDevice : public impl::AudioDevice
Expand Down

0 comments on commit 3fd3e5e

Please sign in to comment.