mirror of
https://github.com/yuzu-emu/FasTC.git
synced 2024-11-27 22:34:16 +01:00
Fix a bunch of memory leaks.
This commit is contained in:
parent
aebeb38ad0
commit
771b91b795
@ -110,6 +110,13 @@ ParallelStage &ParallelStage::operator=(const ParallelStage &other) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
ParallelStage::~ParallelStage() {
|
||||
if(m_Blocks) {
|
||||
delete [] m_Blocks;
|
||||
m_Blocks = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ParallelStage::AddBlock(uint32 blockNum) {
|
||||
assert(m_NumBlocks < m_TotalNumBlocks);
|
||||
|
||||
|
@ -64,6 +64,8 @@ class ParallelStage {
|
||||
ParallelStage(const ParallelStage &);
|
||||
ParallelStage &operator=(const ParallelStage &);
|
||||
|
||||
~ParallelStage();
|
||||
|
||||
const BC7ParallelStage m_Stage;
|
||||
|
||||
// Adds the block number to the list of blocks for this parallel stage
|
||||
|
@ -56,6 +56,11 @@ class Image {
|
||||
public:
|
||||
Image(const CompressedImage &);
|
||||
Image(const ImageLoader &);
|
||||
~Image();
|
||||
|
||||
Image(const Image &);
|
||||
Image &operator=(const Image &);
|
||||
|
||||
const uint8 *RawData() const { return m_PixelData; }
|
||||
|
||||
CompressedImage *Compress(const SCompressionSettings &settings) const;
|
||||
|
@ -55,6 +55,42 @@ static inline T sad( const T &a, const T &b ) {
|
||||
return (a > b)? a - b : b - a;
|
||||
}
|
||||
|
||||
Image::Image(const Image &other)
|
||||
: m_Width(other.m_Width)
|
||||
, m_Height(other.m_Height)
|
||||
, m_PixelData(new uint8[m_Width * m_Height * 4])
|
||||
{
|
||||
if(m_PixelData) {
|
||||
memcpy(m_PixelData, other.m_PixelData, m_Width * m_Height * 4);
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "Out of memory!\n");
|
||||
}
|
||||
}
|
||||
|
||||
Image &Image::operator=(const Image &other) {
|
||||
|
||||
m_Width = other.m_Width;
|
||||
m_Height = other.m_Height;
|
||||
|
||||
if(m_PixelData) {
|
||||
delete [] m_PixelData;
|
||||
}
|
||||
|
||||
if(other.m_PixelData) {
|
||||
m_PixelData = new uint8[m_Width * m_Height * 4];
|
||||
if(m_PixelData)
|
||||
memcpy(m_PixelData, other.m_PixelData, m_Width * m_Height * 4);
|
||||
else
|
||||
fprintf(stderr, "Out of memory!\n");
|
||||
}
|
||||
else {
|
||||
m_PixelData = other.m_PixelData;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Image::Image(const CompressedImage &ci)
|
||||
: m_Width(ci.GetWidth())
|
||||
, m_Height(ci.GetHeight())
|
||||
@ -84,6 +120,13 @@ Image::Image(const ImageLoader &loader)
|
||||
}
|
||||
}
|
||||
|
||||
Image::~Image() {
|
||||
if(m_PixelData) {
|
||||
delete [] m_PixelData;
|
||||
m_PixelData = 0;
|
||||
}
|
||||
}
|
||||
|
||||
CompressedImage *Image::Compress(const SCompressionSettings &settings) const {
|
||||
CompressedImage *outImg = NULL;
|
||||
const unsigned int dataSz = GetWidth() * GetHeight() * 4;
|
||||
@ -103,6 +146,8 @@ CompressedImage *Image::Compress(const SCompressionSettings &settings) const {
|
||||
CompressImageData(m_PixelData, dataSz, cmpData, cmpDataSz, settings);
|
||||
|
||||
outImg = new CompressedImage(GetWidth(), GetHeight(), settings.format, cmpData);
|
||||
|
||||
delete [] cmpData;
|
||||
return outImg;
|
||||
}
|
||||
|
||||
@ -111,6 +156,7 @@ double Image::ComputePSNR(const CompressedImage &ci) const {
|
||||
unsigned char *unCompData = new unsigned char[imageSz];
|
||||
if(!(ci.DecompressImage(unCompData, imageSz))) {
|
||||
fprintf(stderr, "%s\n", "Failed to decompress image.");
|
||||
delete [] unCompData;
|
||||
return -1.0f;
|
||||
}
|
||||
|
||||
|
@ -102,6 +102,11 @@ class ImageLoader {
|
||||
delete [] m_AlphaData;
|
||||
m_AlphaData = 0;
|
||||
}
|
||||
|
||||
if(m_PixelData) {
|
||||
delete [] m_PixelData;
|
||||
m_PixelData = 0;
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool ReadData() = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user