diff --git a/src/Nazara/Audio/Music.cpp b/src/Nazara/Audio/Music.cpp index 16dfc64ec..f6704bf4d 100644 --- a/src/Nazara/Audio/Music.cpp +++ b/src/Nazara/Audio/Music.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -18,8 +19,8 @@ bool NzMusicParams::IsValid() const struct NzMusicImpl { ALenum audioFormat; + std::unique_ptr stream; std::vector chunkSamples; - NzSoundStream* stream; NzThread thread; bool loop = false; bool paused = false; @@ -50,7 +51,7 @@ bool NzMusic::Create(NzSoundStream* soundStream) m_impl->sampleRate = soundStream->GetSampleRate(); m_impl->audioFormat = NzOpenAL::AudioFormat[format]; m_impl->chunkSamples.resize(format * m_impl->sampleRate); // Une seconde de samples - m_impl->stream = soundStream; + m_impl->stream.reset(soundStream); return true; } @@ -61,7 +62,6 @@ void NzMusic::Destroy() { Stop(); - delete m_impl->stream; delete m_impl; m_impl = nullptr; } diff --git a/src/Nazara/Audio/SoundBuffer.cpp b/src/Nazara/Audio/SoundBuffer.cpp index 7cd831313..7d6dcfe41 100644 --- a/src/Nazara/Audio/SoundBuffer.cpp +++ b/src/Nazara/Audio/SoundBuffer.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -23,7 +24,7 @@ struct NzSoundBufferImpl ALuint buffer; nzAudioFormat format; nzUInt32 duration; - nzInt16* samples; + std::unique_ptr samples; unsigned int sampleCount; unsigned int sampleRate; }; @@ -104,7 +105,7 @@ bool NzSoundBuffer::Create(nzAudioFormat format, unsigned int sampleCount, unsig m_impl->format = format; m_impl->sampleCount = sampleCount; m_impl->sampleRate = sampleRate; - m_impl->samples = new nzInt16[sampleCount]; + m_impl->samples.reset(new nzInt16[sampleCount]); std::memcpy(&m_impl->samples[0], samples, sampleCount*sizeof(nzInt16)); NotifyCreated(); @@ -117,7 +118,6 @@ void NzSoundBuffer::Destroy() { NotifyDestroy(); - delete[] m_impl->samples; delete m_impl; m_impl = nullptr; } @@ -159,7 +159,7 @@ const nzInt16* NzSoundBuffer::GetSamples() const } #endif - return m_impl->samples; + return m_impl->samples.get(); } unsigned int NzSoundBuffer::GetSampleCount() const