slighty less C code proposal
This commit is contained in:
@@ -186,17 +186,11 @@ bool SFXBuffer::loadVorbisBuffer(const std::string &name, ALuint buffer)
|
||||
// always 16 bit data
|
||||
long len = (long)ov_pcm_total(&oggFile, -1) * info->channels * 2;
|
||||
|
||||
char *data = (char *) malloc(len);
|
||||
if(!data)
|
||||
{
|
||||
ov_clear(&oggFile);
|
||||
Log::error("SFXBuffer", "[SFXBuffer] Could not allocate decode buffer.");
|
||||
return false;
|
||||
}
|
||||
std::unique_ptr<char []> data = std::unique_ptr<char []>(new char[len]);
|
||||
|
||||
int bs = -1;
|
||||
long todo = len;
|
||||
char *bufpt = data;
|
||||
char *bufpt = data.get();
|
||||
|
||||
while (todo)
|
||||
{
|
||||
@@ -207,11 +201,9 @@ bool SFXBuffer::loadVorbisBuffer(const std::string &name, ALuint buffer)
|
||||
|
||||
alBufferData(buffer, (info->channels == 1) ? AL_FORMAT_MONO16
|
||||
: AL_FORMAT_STEREO16,
|
||||
data, len, info->rate);
|
||||
data.get(), len, info->rate);
|
||||
success = true;
|
||||
|
||||
free(data);
|
||||
|
||||
ov_clear(&oggFile);
|
||||
fclose(file);
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ typedef unsigned int ALuint;
|
||||
#include "utils/leak_check.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
class SFXBase;
|
||||
class XMLNode;
|
||||
|
||||
@@ -35,8 +35,7 @@ STKTexture::STKTexture(const std::string& path, TexConfig* tc, bool no_upload)
|
||||
{
|
||||
if (tc != NULL)
|
||||
{
|
||||
m_tex_config = (TexConfig*)malloc(sizeof(TexConfig));
|
||||
memcpy(m_tex_config, tc, sizeof(TexConfig));
|
||||
m_tex_config = new TexConfig(*tc);
|
||||
}
|
||||
#ifndef SERVER_ONLY
|
||||
if (m_tex_config)
|
||||
@@ -86,7 +85,7 @@ STKTexture::~STKTexture()
|
||||
#endif // !SERVER_ONLY
|
||||
if (m_texture_image != NULL)
|
||||
m_texture_image->drop();
|
||||
free(m_tex_config);
|
||||
delete m_tex_config;
|
||||
} // ~STKTexture
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user