Fix memory leaks.

2.0
castano 17 years ago
parent 6cdfaaca58
commit ee28a5a37b

@ -29,10 +29,11 @@ class AutoPtr
NV_FORBID_HEAPALLOC();
public:
/** Ctor. */
explicit AutoPtr( T * p ) {
m_ptr = p;
}
/// Default ctor.
AutoPtr() : m_ptr(NULL) { }
/// Ctor.
explicit AutoPtr( T * p ) : m_ptr(p) { }
/** Dtor. Deletes owned pointer. */
~AutoPtr() {
@ -69,13 +70,23 @@ public:
}
/** Const pointer equal comparation. */
bool operator == (const T * const p) const {
return (m_ptr == p);
friend bool operator == (const AutoPtr<T> & ap, const T * const p) {
return (ap.ptr() == p);
}
/** Const pointer nequal comparation. */
friend bool operator != (const AutoPtr<T> & ap, const T * const p) {
return (ap.ptr() != p);
}
/** Const pointer equal comparation. */
friend bool operator == (const T * const p, const AutoPtr<T> & ap) {
return (ap.ptr() == p);
}
/** Const pointer nequal comparation. */
bool operator != (const T * const p) const {
return (m_ptr != p);
friend bool operator != (const T * const p, const AutoPtr<T> & ap) {
return (ap.ptr() != p);
}
private:

@ -843,12 +843,11 @@ bool nv::ImageIO::saveFloatTIFF(const char * fileName, FloatImage *fimage)
TIFFSetField(image, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP);
TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, 32);
uint32 rowsperstrip = TIFFDefaultStripSize(image, -1);
uint32 rowsperstrip = TIFFDefaultStripSize(image, (uint32)-1);
TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, rowsperstrip);
TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_PACKBITS);
TIFFSetField(image, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, -1L);
TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);

@ -24,6 +24,7 @@
#ifndef NV_TT_INPUTOPTIONS_H
#define NV_TT_INPUTOPTIONS_H
#include <nvcore/Ptr.h>
#include <nvmath/Vector.h>
#include <nvimage/Image.h>
#include "nvtt.h"
@ -75,7 +76,6 @@ namespace nvtt
struct InputOptions::Private::Image
{
Image() {}
~Image() { delete data; }
int mipLevel;
int face;
@ -84,7 +84,7 @@ namespace nvtt
int height;
int depth;
nv::Image * data;
nv::AutoPtr<nv::Image> data;
};
} // nvtt namespace

@ -409,11 +409,11 @@ bool nvtt::compress(const InputOptions & inputOptions, const OutputOptions & out
// Convert to normal map.
if (inputOptions.m.convertToNormalMap)
{
floatImage = createNormalMap(mipmap.data, (FloatImage::WrapMode)inputOptions.m.wrapMode, inputOptions.m.heightFactors, inputOptions.m.bumpFrequencyScale);
floatImage = createNormalMap(mipmap.data.ptr(), (FloatImage::WrapMode)inputOptions.m.wrapMode, inputOptions.m.heightFactors, inputOptions.m.bumpFrequencyScale);
}
else
{
lastImage = img = mipmap.data;
lastImage = img = mipmap.data.ptr();
// Delete float image.
floatImage = NULL;

Loading…
Cancel
Save