Made use of smart pointers :)

Former-commit-id: 5380752e0da3f4b958a944e41fcde38722e3c4c2
This commit is contained in:
Lynix
2013-05-23 02:13:45 +02:00
parent c934d8ed6b
commit 738788b4c3
6 changed files with 63 additions and 95 deletions

View File

@@ -10,6 +10,7 @@
#include <Nazara/Core/File.hpp>
#include <Nazara/Core/InputStream.hpp>
#include <Nazara/Core/MemoryStream.hpp>
#include <memory>
#include <sndfile/sndfile.h>
#include <Nazara/Audio/Debug.hpp>
@@ -112,29 +113,24 @@ namespace
sf_command(file, SFC_SET_SCALE_FLOAT_INT_READ, nullptr, SF_TRUE);
unsigned int sampleCount = infos.frames*infos.channels;
nzInt16* samples = new nzInt16[sampleCount];
if (sf_read_short(file, samples, sampleCount) != sampleCount)
std::unique_ptr<nzInt16[]> samples(new nzInt16[sampleCount]);
if (sf_read_short(file, samples.get(), sampleCount) != sampleCount)
{
sf_close(file);
NazaraError("Failed to read samples");
delete[] samples;
sf_close(file);
return false;
}
if (!soundBuffer->Create(format, infos.frames*infos.channels, infos.samplerate, samples))
if (!soundBuffer->Create(format, infos.frames*infos.channels, infos.samplerate, samples.get()))
{
sf_close(file);
NazaraError("Failed to create sound buffer");
delete[] samples;
sf_close(file);
return false;
}
delete[] samples;
return true;
}
}