Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

remove delete[]

Shinya Kitaoka42bfb61883a4
diff --git a/toonz/sources/common/trop/tconvolve.cpp b/toonz/sources/common/trop/tconvolve.cpp
index 909e2d37f..4758b539e 100644
--- a/toonz/sources/common/trop/tconvolve.cpp
+++ b/toonz/sources/common/trop/tconvolve.cpp
@@ -304,8 +304,8 @@ void doConvolve_i(TRasterPT<PIXOUT> rout,
PIXOUT *pixout;
int radiusSquare = sq(radius);
- PIXIN **pixarr = new PIXIN *[radiusSquare];
- long *w = new long[radiusSquare];
+ std::unique_ptr<PIXIN*[]> pixarr(new PIXIN *[radiusSquare]);
+ std::unique_ptr<long[]> w(new long[radiusSquare]);
int pixn;
int wrapin, wrapout;
int x, y, n;
@@ -356,7 +356,7 @@ void doConvolve_i(TRasterPT<PIXOUT> rout,
pixn++;
}
- doConvolve_row_i<PIXOUT, PIXIN>(pixout, n, pixarr, w, pixn);
+ doConvolve_row_i<PIXOUT, PIXIN>(pixout, n, pixarr.get(), w.get(), pixn);
x += n;
pixin += n;
@@ -366,9 +366,6 @@ void doConvolve_i(TRasterPT<PIXOUT> rout,
rin->unlock();
rout->unlock();
-
- delete[] w;
- delete[] pixarr;
}
//------------------------------------------------------------------------------
@@ -465,8 +462,8 @@ void doConvolve_cm32_i(TRasterPT<PIXOUT> rout,
TPixelCM32 *pixin;
PIXOUT *pixout;
int radiusSquare = sq(radius);
- TPixelCM32 **pixarr = new TPixelCM32 *[radiusSquare];
- long *w = new long[radiusSquare];
+ std::unique_ptr<TPixelCM32*[]> pixarr(new TPixelCM32*[radiusSquare]);
+ std::unique_ptr<long[]> w(new long[radiusSquare]);
int pixn;
int wrapin, wrapout;
int x, y, n;
@@ -526,7 +523,7 @@ void doConvolve_cm32_i(TRasterPT<PIXOUT> rout,
pixn++;
}
- doConvolve_cm32_row_i<PIXOUT>(pixout, n, pixarr, w, pixn, paints, inks);
+ doConvolve_cm32_row_i<PIXOUT>(pixout, n, pixarr.get(), w.get(), pixn, paints, inks);
x += n;
pixin += n;
@@ -536,9 +533,6 @@ void doConvolve_cm32_i(TRasterPT<PIXOUT> rout,
rin->unlock();
rout->unlock();
-
- delete[] pixarr;
- delete[] w;
}
} // anonymous namespace
diff --git a/toonz/sources/common/trop/tresample.cpp b/toonz/sources/common/trop/tresample.cpp
index 78d7498ba..4cf97351b 100644
--- a/toonz/sources/common/trop/tresample.cpp
+++ b/toonz/sources/common/trop/tresample.cpp
@@ -2431,26 +2431,26 @@ void rop_resample_rgbm(TRasterPT<T> rout, const TRasterPT<T> &rin,
#ifdef USE_STATIC_VARS
static TRop::ResampleFilterType current_flt_type = TRop::None;
- static short *filter_array = 0;
+ static std::unique_ptr<short[]> filter_array;
static short *filter = 0;
static int min_filter_fg, max_filter_fg;
static int filter_array_size = 0;
static int n_pix = 0;
- static int *pix_ref_u = 0;
- static int *pix_ref_v = 0;
- static int *pix_ref_f = 0;
- static int *pix_ref_g = 0;
+ static std::unique_ptr<int[]> pix_ref_u;
+ static std::unique_ptr<int[]> pix_ref_v;
+ static std::unique_ptr<int[]> pix_ref_f;
+ static std::unique_ptr<int[]> pix_ref_g;
static int current_max_n_pix = 0;
#else
- short *filter_array = 0;
+ std::unique_ptr<short[]> filter_array;
short *filter = 0;
int min_filter_fg, max_filter_fg;
int filter_array_size = 0;
int n_pix = 0;
- int *pix_ref_u = 0;
- int *pix_ref_v = 0;
- int *pix_ref_f = 0;
- int *pix_ref_g = 0;
+ std::unique_ptr<int[]> pix_ref_u;
+ std::unique_ptr<int[]> pix_ref_v;
+ std::unique_ptr<int[]> pix_ref_f;
+ std::unique_ptr<int[]> pix_ref_g;
int current_max_n_pix = 0;
#endif
int filter_st_radius;
@@ -2578,18 +2578,10 @@ void rop_resample_rgbm(TRasterPT<T> rout, const TRasterPT<T> &rin,
if (max_n_pix > current_max_n_pix) {
current_max_n_pix = max_n_pix;
- if (pix_ref_u)
- delete[] pix_ref_u;
- pix_ref_u = new int[current_max_n_pix];
- if (pix_ref_v)
- delete[] pix_ref_v;
- pix_ref_v = new int[current_max_n_pix];
- if (pix_ref_f)
- delete[] pix_ref_f; //These will provide the images of the formers
- pix_ref_f = new int[current_max_n_pix];
- if (pix_ref_g)
- delete[] pix_ref_g;
- pix_ref_g = new int[current_max_n_pix];
+ pix_ref_u.reset(new int[current_max_n_pix]);
+ pix_ref_v.reset(new int[current_max_n_pix]);
+ pix_ref_f.reset(new int[current_max_n_pix]);
+ pix_ref_g.reset(new int[current_max_n_pix]);
assert(pix_ref_u && pix_ref_v && pix_ref_f && pix_ref_g);
}
@@ -2617,16 +2609,6 @@ void rop_resample_rgbm(TRasterPT<T> rout, const TRasterPT<T> &rin,
n_pix = 0;
if (!pix_ref_u || !pix_ref_v || !pix_ref_f || !pix_ref_g) {
-#ifndef USE_STATIC_VARS
- if (pix_ref_u)
- delete[] pix_ref_u;
- if (pix_ref_v)
- delete[] pix_ref_v;
- if (pix_ref_f)
- delete[] pix_ref_f;
- if (pix_ref_g)
- delete[] pix_ref_g;
-#endif
throw TRopException("tresample.cpp line2640 function rop_resample_rgbm() : alloc pix_ref failed");
}
@@ -2684,13 +2666,11 @@ void rop_resample_rgbm(TRasterPT<T> rout, const TRasterPT<T> &rin,
filter_size = max_filter_fg - min_filter_fg + 1;
if (filter_size > filter_array_size) //For the static vars case...
{
- if (filter_array)
- delete[] filter_array;
- filter_array = new short[filter_size];
+ filter_array.reset(new short[filter_size]);
assert(filter_array);
filter_array_size = filter_size;
}
- filter = filter_array - min_filter_fg; //Take the position corresponding to fg's (0,0) in the array
+ filter = filter_array.get() - min_filter_fg; //Take the position corresponding to fg's (0,0) in the array
filter[0] = MAX_FILTER_VAL;
for (f = 1, s_ = 1.0 / FILTER_RESOLUTION;
f < filter_fg_radius;
@@ -2719,14 +2699,12 @@ void rop_resample_rgbm(TRasterPT<T> rout, const TRasterPT<T> &rin,
if (filter_size > filter_array_size) {
//controllare!!
//TREALLOC (filter_array, filter_size)
- if (filter_array)
- delete[] filter_array;
- filter_array = new short[filter_size];
+ filter_array.reset(new short[filter_size]);
assert(filter_array);
filter_array_size = filter_size;
}
- filter = filter_array - min_filter_fg;
+ filter = filter_array.get() - min_filter_fg;
if (min_pix_out_fg < min_filter_fg) {
int delta = min_filter_fg - min_pix_out_fg;
@@ -2750,8 +2728,8 @@ void rop_resample_rgbm(TRasterPT<T> rout, const TRasterPT<T> &rin,
min_pix_ref_u, min_pix_ref_v,
max_pix_ref_u, max_pix_ref_v,
n_pix,
- pix_ref_u, pix_ref_v,
- pix_ref_f, pix_ref_g,
+ pix_ref_u.get(), pix_ref_v.get(),
+ pix_ref_f.get(), pix_ref_g.get(),
filter);
else
#endif
@@ -2761,8 +2739,8 @@ void rop_resample_rgbm(TRasterPT<T> rout, const TRasterPT<T> &rin,
min_pix_ref_u, min_pix_ref_v,
max_pix_ref_u, max_pix_ref_v,
n_pix,
- pix_ref_u, pix_ref_v,
- pix_ref_f, pix_ref_g,
+ pix_ref_u.get(), pix_ref_v.get(),
+ pix_ref_f.get(), pix_ref_g.get(),
filter);
else
resample_main_rgbm<T, TINT32>(
@@ -2770,23 +2748,10 @@ void rop_resample_rgbm(TRasterPT<T> rout, const TRasterPT<T> &rin,
min_pix_ref_u, min_pix_ref_v,
max_pix_ref_u, max_pix_ref_v,
n_pix,
- pix_ref_u, pix_ref_v,
- pix_ref_f, pix_ref_g,
+ pix_ref_u.get(), pix_ref_v.get(),
+ pix_ref_f.get(), pix_ref_g.get(),
filter);
-#ifndef USE_STATIC_VARS
- if (filter_array)
- delete[] filter_array;
- if (pix_ref_u)
- delete[] pix_ref_u;
- if (pix_ref_v)
- delete[] pix_ref_v;
- if (pix_ref_f)
- delete[] pix_ref_f;
- if (pix_ref_g)
- delete[] pix_ref_g;
-#endif
-
/////////////////////////////////////////////////////////
// INIZIO GESTIONE ALTRI TIPI RASTER DA IMPLEMENTARE
/////////////////////////////////////////////////////////
@@ -4829,26 +4794,26 @@ void rop_resample_rgbm_2(TRasterPT<T> rout, const TRasterCM32P &rin,
#ifdef USE_STATIC_VARS
static TRop::ResampleFilterType current_flt_type = TRop::None;
- static short *filter_array = 0;
+ static std::unique_ptr<short[]> filter_array;
static short *filter = 0;
static int min_filter_fg, max_filter_fg;
static int filter_array_size = 0;
static int n_pix = 0;
- static int *pix_ref_u = 0;
- static int *pix_ref_v = 0;
- static int *pix_ref_f = 0;
- static int *pix_ref_g = 0;
+ static std::unique_ptr<int[]> pix_ref_u;
+ static std::unique_ptr<int[]> pix_ref_v;
+ static std::unique_ptr<int[]> pix_ref_f;
+ static std::unique_ptr<int[]> pix_ref_g;
static int current_max_n_pix = 0;
#else
- short *filter_array = 0;
+ std::unique_ptr<short[]> filter_array;
short *filter = 0;
int min_filter_fg, max_filter_fg;
int filter_array_size = 0;
int n_pix = 0;
- int *pix_ref_u = 0;
- int *pix_ref_v = 0;
- int *pix_ref_f = 0;
- int *pix_ref_g = 0;
+ std::unique_ptr<int[]> pix_ref_u;
+ std::unique_ptr<int[]> pix_ref_v;
+ std::unique_ptr<int[]> pix_ref_f;
+ std::unique_ptr<int[]> pix_ref_g;
int current_max_n_pix = 0;
#endif
@@ -4955,18 +4920,10 @@ void rop_resample_rgbm_2(TRasterPT<T> rout, const TRasterCM32P &rin,
if (max_n_pix > current_max_n_pix) {
current_max_n_pix = max_n_pix;
- if (pix_ref_u)
- delete[] pix_ref_u;
- pix_ref_u = new int[current_max_n_pix];
- if (pix_ref_v)
- delete[] pix_ref_v;
- pix_ref_v = new int[current_max_n_pix];
- if (pix_ref_f)
- delete[] pix_ref_f;
- pix_ref_f = new int[current_max_n_pix];
- if (pix_ref_g)
- delete[] pix_ref_g;
- pix_ref_g = new int[current_max_n_pix];
+ pix_ref_u.reset(new int[current_max_n_pix]);
+ pix_ref_v.reset(new int[current_max_n_pix]);
+ pix_ref_f.reset(new int[current_max_n_pix]);
+ pix_ref_g.reset(new int[current_max_n_pix]);
assert(pix_ref_u && pix_ref_v && pix_ref_f && pix_ref_g);
}
@@ -5022,13 +4979,11 @@ void rop_resample_rgbm_2(TRasterPT<T> rout, const TRasterCM32P &rin,
max_filter_fg = filter_fg_radius + FILTER_RESOLUTION * 3 / 2;
filter_size = max_filter_fg - min_filter_fg + 1;
if (filter_size > filter_array_size) {
- if (filter_array)
- delete[] filter_array;
- filter_array = new short[filter_size];
+ filter_array.reset(new short[filter_size]);
assert(filter_array);
filter_array_size = filter_size;
}
- filter = filter_array - min_filter_fg;
+ filter = filter_array.get() - min_filter_fg;
filter[0] = MAX_FILTER_VAL;
for (f = 1, s_ = 1.0 / FILTER_RESOLUTION;
f < filter_fg_radius;
@@ -5054,14 +5009,12 @@ void rop_resample_rgbm_2(TRasterPT<T> rout, const TRasterCM32P &rin,
if (filter_size > filter_array_size) {
//controllare!!
//TREALLOC (filter_array, filter_size)
- if (filter_array)
- delete[] filter_array;
- filter_array = new short[filter_size];
+ filter_array.reset(new short[filter_size]);
assert(filter_array);
filter_array_size = filter_size;
}
- filter = filter_array - min_filter_fg;
+ filter = filter_array.get() - min_filter_fg;
if (min_pix_out_fg < min_filter_fg) {
int delta = min_filter_fg - min_pix_out_fg;
@@ -5086,8 +5039,8 @@ void rop_resample_rgbm_2(TRasterPT<T> rout, const TRasterCM32P &rin,
min_pix_ref_u, min_pix_ref_v,
max_pix_ref_u, max_pix_ref_v,
n_pix,
- pix_ref_u, pix_ref_v,
- pix_ref_f, pix_ref_g,
+ pix_ref_u.get(), pix_ref_v.get(),
+ pix_ref_f.get(), pix_ref_g.get(),
filter, palette);
else
#endif
@@ -5095,23 +5048,10 @@ void rop_resample_rgbm_2(TRasterPT<T> rout, const TRasterCM32P &rin,
min_pix_ref_u, min_pix_ref_v,
max_pix_ref_u, max_pix_ref_v,
n_pix,
- pix_ref_u, pix_ref_v,
- pix_ref_f, pix_ref_g,
+ pix_ref_u.get(), pix_ref_v.get(),
+ pix_ref_f.get(), pix_ref_g.get(),
filter, palette);
-#ifndef USE_STATIC_VARS
- if (filter_array)
- delete[] filter_array;
- if (pix_ref_u)
- delete[] pix_ref_u;
- if (pix_ref_v)
- delete[] pix_ref_v;
- if (pix_ref_f)
- delete[] pix_ref_f;
- if (pix_ref_g)
- delete[] pix_ref_g;
-#endif
-
/////////////////////////////////////////////////////////
// INIZIO GESTIONE ALTRI TIPI RASTER DA IMPLEMENTARE
/////////////////////////////////////////////////////////
diff --git a/toonz/sources/common/tsound/tsound_nt.cpp b/toonz/sources/common/tsound/tsound_nt.cpp
index 80a49084e..bcdb147ec 100644
--- a/toonz/sources/common/tsound/tsound_nt.cpp
+++ b/toonz/sources/common/tsound/tsound_nt.cpp
@@ -2210,13 +2210,13 @@ bool setSrcMixMuxControl(MIXERCONTROL mxc, DWORD componentTypeSrc)
// determino l'indice dell'item corrispondente alla linea sorgente
// di tipo componentTypeSrc
- MIXERCONTROLDETAILS_LISTTEXT *pmxcdSelectText =
- new MIXERCONTROLDETAILS_LISTTEXT[dwMultipleItems];
+ std::unique_ptr<MIXERCONTROLDETAILS_LISTTEXT[]>
+ pmxcdSelectText(new MIXERCONTROLDETAILS_LISTTEXT[dwMultipleItems]);
- if (pmxcdSelectText != NULL) {
+ if (pmxcdSelectText) {
// estraggo le info su tutte le linee associate al controllo
ret = getControlDetails((HMIXEROBJ)0, dwSelectControlID,
- dwMultipleItems, pmxcdSelectText);
+ dwMultipleItems, pmxcdSelectText.get());
if (ret == MMSYSERR_NOERROR) {
for (DWORD dwi = 0; dwi < dwMultipleItems; dwi++) {
@@ -2231,8 +2231,6 @@ bool setSrcMixMuxControl(MIXERCONTROL mxc, DWORD componentTypeSrc)
}
}
- delete[] pmxcdSelectText;
-
if (!found)
return false;
}
@@ -2242,11 +2240,11 @@ bool setSrcMixMuxControl(MIXERCONTROL mxc, DWORD componentTypeSrc)
bool bRetVal = false;
- MIXERCONTROLDETAILS_BOOLEAN *pmxcdSelectValue =
- new MIXERCONTROLDETAILS_BOOLEAN[dwMultipleItems];
+ std::unique_ptr<MIXERCONTROLDETAILS_BOOLEAN[]>
+ pmxcdSelectValue(new MIXERCONTROLDETAILS_BOOLEAN[dwMultipleItems]);
- if (pmxcdSelectValue != NULL) {
- ::ZeroMemory(pmxcdSelectValue, dwMultipleItems * sizeof(MIXERCONTROLDETAILS_BOOLEAN));
+ if (pmxcdSelectValue) {
+ ::ZeroMemory(pmxcdSelectValue.get(), dwMultipleItems * sizeof(MIXERCONTROLDETAILS_BOOLEAN));
// impostazione del valore
pmxcdSelectValue[dwIndexLine].fValue = (TINT32)1; // lVal; //dovrebbe esser uno
@@ -2254,11 +2252,9 @@ bool setSrcMixMuxControl(MIXERCONTROL mxc, DWORD componentTypeSrc)
ret = setControlDetails((HMIXEROBJ)0,
dwSelectControlID,
dwMultipleItems,
- pmxcdSelectValue);
+ pmxcdSelectValue.get());
if (ret == MMSYSERR_NOERROR)
bRetVal = true;
-
- delete[] pmxcdSelectValue;
}
return bRetVal;
}
diff --git a/toonz/sources/common/tsystem/tsystempd.cpp b/toonz/sources/common/tsystem/tsystempd.cpp
index 16b77c527..3a74825fe 100644
--- a/toonz/sources/common/tsystem/tsystempd.cpp
+++ b/toonz/sources/common/tsystem/tsystempd.cpp
@@ -1,11 +1,11 @@
-
-
#ifdef _WIN32
#ifndef UNICODE
#define UNICODE
#endif
#endif
+#include <memory>
+
#include "tsystem.h"
//#include "tunicode.h"
#include "tfilepath_io.h"
@@ -122,12 +122,11 @@ wstring getFormattedMessage(DWORD lastError)
if (!wSize)
return wstring();
- wchar_t *wBuffer = new wchar_t[wSize + 1];
- MultiByteToWideChar(0, 0, (char *)lpMsgBuf, -1, wBuffer, wSize);
+ std::unique_ptr<wchar_t[]> wBuffer(new wchar_t[wSize + 1]);
+ MultiByteToWideChar(0, 0, (char *)lpMsgBuf, -1, wBuffer.get(), wSize);
wBuffer[wSize] = '\0';
- wstring wmsg(wBuffer);
+ wstring wmsg(wBuffer.get());
- delete[] wBuffer;
LocalFree(lpMsgBuf);
return wmsg;
}
diff --git a/toonz/sources/include/ext/plasticdeformerstorage.h b/toonz/sources/include/ext/plasticdeformerstorage.h
index 36cab1b6c..70a0c1e03 100644
--- a/toonz/sources/include/ext/plasticdeformerstorage.h
+++ b/toonz/sources/include/ext/plasticdeformerstorage.h
@@ -35,8 +35,8 @@ class PlasticSkeletonDeformation;
struct DVAPI PlasticDeformerData {
PlasticDeformer m_deformer; //!< The mesh deformer itself
- double *m_so; //!< (owned) Faces' stacking order
- double *m_output; //!< (owned) Output vertex coordinates
+ std::unique_ptr<double[]> m_so; //!< (owned) Faces' stacking order
+ std::unique_ptr<double[]> m_output; //!< (owned) Output vertex coordinates
std::vector<int> m_faceHints; //!< Handles' face hints
@@ -56,7 +56,7 @@ private:
//***********************************************************************************************
struct DVAPI PlasticDeformerDataGroup {
- PlasticDeformerData *m_datas; //!< (owned) The deformer datas array. One per mesh.
+ std::unique_ptr<PlasticDeformerData[]> m_datas; //!< (owned) The deformer datas array. One per mesh.
std::vector<PlasticHandle> m_handles; //!< Source handles (emanated from skeleton vertices).
std::vector<TPointD> m_dstHandles; //!< Corresponding destination handle positions
diff --git a/toonz/sources/stdfx/bodyhighlightfx.cpp b/toonz/sources/stdfx/bodyhighlightfx.cpp
index 766ea639e..8a90bfed0 100644
--- a/toonz/sources/stdfx/bodyhighlightfx.cpp
+++ b/toonz/sources/stdfx/bodyhighlightfx.cpp
@@ -60,16 +60,16 @@ void doBlur(CHANNEL_TYPE *greymap, const TRasterPT<PIXEL> &rin, int blur)
//First, blur each column independently
//We'll need a temporary col for storing sums
- unsigned long *tempCol = new unsigned long[rin->getLy()];
+ std::unique_ptr<unsigned long[]> tempCol(new unsigned long[rin->getLy()]);
int edge = tmin(blur + 1, rin->getLy());
for (i = 0; i < rin->getLx(); ++i) {
PIXEL *lineSrcPix = rin->pixels(0) + i;
CHANNEL_TYPE *lineOutPix = greymap + i;
PIXEL *pixin = lineSrcPix;
- unsigned long *pixsum = tempCol;
+ unsigned long *pixsum = tempCol.get();
- memset(tempCol, 0, rin->getLy() * sizeof(unsigned long));
+ memset(tempCol.get(), 0, rin->getLy() * sizeof(unsigned long));
//Build up to blur with retro-sums
sum = 0;
@@ -88,7 +88,7 @@ void doBlur(CHANNEL_TYPE *greymap, const TRasterPT<PIXEL> &rin, int blur)
//Now, the same in reverse
lineSrcPix = lineSrcPix + (rin->getLy() - 1) * wrapSrc;
pixin = lineSrcPix;
- pixsum = tempCol + rin->getLy() - 1;
+ pixsum = tempCol.get() + rin->getLy() - 1;
sum = 0;
for (j = 0; j < edge; ++j, pixin -= wrapSrc, --pixsum) {
@@ -104,27 +104,25 @@ void doBlur(CHANNEL_TYPE *greymap, const TRasterPT<PIXEL> &rin, int blur)
}
//Finally, transfer sums to the output greymap, divided by the blur.
- pixsum = tempCol;
+ pixsum = tempCol.get();
CHANNEL_TYPE *pixout = lineOutPix;
for (j = 0; j < rin->getLy(); ++j, pixout += wrapOut, ++pixsum)
*pixout = (*pixsum) / blurDiameter;
}
- delete[] tempCol;
-
//Then, the same for all greymap rows
//We'll need a temporary row for sums
- unsigned long *tempRow = new unsigned long[rin->getLx()];
+ std::unique_ptr<unsigned long[]> tempRow(new unsigned long[rin->getLx()]);
edge = tmin(blur + 1, rin->getLx());
for (j = 0; j < rin->getLy(); ++j) {
CHANNEL_TYPE *lineSrcPix = greymap + j * wrapOut;
CHANNEL_TYPE *lineOutPix = lineSrcPix;
- unsigned long *pixsum = tempRow;
+ unsigned long *pixsum = tempRow.get();
CHANNEL_TYPE *pixin = lineSrcPix;
- memset(tempRow, 0, rin->getLx() * sizeof(unsigned long));
+ memset(tempRow.get(), 0, rin->getLx() * sizeof(unsigned long));
//Build up to blur with retro-sums
sum = 0;
@@ -144,7 +142,7 @@ void doBlur(CHANNEL_TYPE *greymap, const TRasterPT<PIXEL> &rin, int blur)
//Now, the same in reverse
lineSrcPix = lineSrcPix + rin->getLx() - 1;
pixin = lineSrcPix;
- pixsum = tempRow + rin->getLx() - 1;
+ pixsum = tempRow.get() + rin->getLx() - 1;
sum = 0;
for (i = 0; i < edge; ++i, --pixin, --pixsum) {
@@ -161,12 +159,10 @@ void doBlur(CHANNEL_TYPE *greymap, const TRasterPT<PIXEL> &rin, int blur)
//Finally, transfer sums to the output greymap, divided by the blur.
CHANNEL_TYPE *pixout = lineOutPix;
- pixsum = tempRow;
+ pixsum = tempRow.get();
for (i = 0; i < rin->getLx(); ++i, ++pixout, ++pixsum)
*pixout = (*pixsum) / blurDiameter;
}
-
- delete[] tempRow;
}
//------------------------------------------------------------------------------
diff --git a/toonz/sources/stdfx/perlinnoise.cpp b/toonz/sources/stdfx/perlinnoise.cpp
index 3fb9f7bf1..3656e7bfa 100644
--- a/toonz/sources/stdfx/perlinnoise.cpp
+++ b/toonz/sources/stdfx/perlinnoise.cpp
@@ -146,9 +146,9 @@ double PerlinNoise::Marble(double u, double v, double k, double grain, double mi
}
PerlinNoise::PerlinNoise()
+ : Noise(new float[Size * Size * TimeSize])
{
TRandom random(1);
- Noise = new float[Size * Size * TimeSize];
for (int i = 0; i < Size; i++) {
for (int j = 0; j < Size; j++) {
for (int k = 0; k < TimeSize; k++) {
diff --git a/toonz/sources/stdfx/perlinnoise.h b/toonz/sources/stdfx/perlinnoise.h
index 9b51d75be..b50f1c9b5 100644
--- a/toonz/sources/stdfx/perlinnoise.h
+++ b/toonz/sources/stdfx/perlinnoise.h
@@ -1,7 +1,8 @@
-
-
#ifndef PERLINNOISE_H
#define PERLINOISE_H
+
+#include <memory>
+
#include "tfxparam.h"
#include "tspectrumparam.h"
@@ -17,12 +18,11 @@ class PerlinNoise
static int TimeSize;
static int Offset;
static double Pixel_size;
- float *Noise;
+ std::unique_ptr<float[]> Noise;
double LinearNoise(double x, double y, double t);
public:
PerlinNoise();
- ~PerlinNoise() { delete[] Noise; };
double Turbolence(double u, double v, double k, double grain);
double Turbolence(double u, double v, double k, double grain, double min, double max);
double Marble(double u, double v, double k, double grain);
diff --git a/toonz/sources/tnzext/meshutils.cpp b/toonz/sources/tnzext/meshutils.cpp
index daf82f014..4580bf25a 100644
--- a/toonz/sources/tnzext/meshutils.cpp
+++ b/toonz/sources/tnzext/meshutils.cpp
@@ -119,7 +119,7 @@ inline void tglDrawFaces(const TMeshImage &meshImage, const PlasticDeformerDataG
m = m_;
mesh = meshes[m].getPointer();
- dstCoords = group->m_datas[m].m_output;
+ dstCoords = group->m_datas[m].m_output.get();
}
mesh->faceVertices(f, v0, v1, v2);
@@ -168,7 +168,7 @@ void tglDrawEdges(const TMeshImage &mi, const PlasticDeformerDataGroup *group)
if (group) {
for (m = 0; m != mCount; ++m)
tglDrawEdges<const TPointD *, TPointD, NoColorFunction>(
- *meshes[m], (const TPointD *)group->m_datas[m].m_output, NoColorFunction());
+ *meshes[m], (const TPointD *)group->m_datas[m].m_output.get(), NoColorFunction());
} else {
for (m = 0; m != mCount; ++m) {
const TTextureMesh &mesh = *meshes[m];
@@ -374,7 +374,7 @@ void tglDraw(const TMeshImage &meshImage,
m = m_;
mesh = meshes[m].getPointer();
- dstCoords = group.m_datas[m].m_output;
+ dstCoords = group.m_datas[m].m_output.get();
}
// Draw each face
diff --git a/toonz/sources/tnzext/plasticdeformerstorage.cpp b/toonz/sources/tnzext/plasticdeformerstorage.cpp
index 572b26690..0bd89810b 100644
--- a/toonz/sources/tnzext/plasticdeformerstorage.cpp
+++ b/toonz/sources/tnzext/plasticdeformerstorage.cpp
@@ -80,7 +80,7 @@ namespace
void initializeSO(PlasticDeformerData &data, const TTextureMeshP &mesh)
{
- data.m_so = new double[mesh->facesCount()];
+ data.m_so.reset(new double[mesh->facesCount()]);
}
//----------------------------------------------------------------------------------
@@ -90,14 +90,14 @@ void initializeDeformerData(PlasticDeformerData &data, const TTextureMeshP &mesh
initializeSO(data, mesh); // Allocates SO data
// Also, allocate suitable input-output arrays for the deformation
- data.m_output = new double[2 * mesh->verticesCount()];
+ data.m_output.reset(new double[2 * mesh->verticesCount()]);
}
//----------------------------------------------------------------------------------
void initializeDeformersData(DataGroup *group, const TMeshImage *meshImage)
{
- group->m_datas = new PlasticDeformerData[meshImage->meshes().size()];
+ group->m_datas.reset(new PlasticDeformerData[meshImage->meshes().size()]);
// Push a PlasticDeformer for each mesh in the image
const std::vector<TTextureMeshP> &meshes = meshImage->meshes();
@@ -269,7 +269,7 @@ void interpolateSO(DataGroup *group, const TMeshImage *meshImage)
const TTextureMesh &mesh = *meshImage->meshes()[m];
PlasticDeformerData &data = group->m_datas[m];
- std::fill(data.m_so, data.m_so + mesh.facesCount(), 0.0);
+ std::fill(data.m_so.get(), data.m_so.get() + mesh.facesCount(), 0.0);
}
return;
@@ -281,9 +281,9 @@ void interpolateSO(DataGroup *group, const TMeshImage *meshImage)
PlasticDeformerData &data = group->m_datas[m];
// Interpolate so values
- double *verticesSO = new double[mesh.verticesCount()];
+ std::unique_ptr<double[]> verticesSO(new double[mesh.verticesCount()]);
- ::buildSO(verticesSO, mesh, group->m_handles, &data.m_faceHints.front());
+ ::buildSO(verticesSO.get(), mesh, group->m_handles, &data.m_faceHints.front());
// Make the mean of each face's vertex values and store that
int f, fCount = mesh.facesCount();
@@ -293,8 +293,6 @@ void interpolateSO(DataGroup *group, const TMeshImage *meshImage)
data.m_so[f] = (verticesSO[v0] + verticesSO[v1] + verticesSO[v2]) / 3.0;
}
-
- delete[] verticesSO;
}
}
@@ -376,7 +374,7 @@ void processMesh(DataGroup *group, double frame, const TMeshImage *meshImage,
for (m = 0; m != mCount; ++m) {
PlasticDeformerData &data = group->m_datas[m];
- data.m_deformer.deform(dstHandlePos, data.m_output);
+ data.m_deformer.deform(dstHandlePos, data.m_output.get());
}
group->m_upToDate |= PlasticDeformerStorage::MESH;
@@ -390,7 +388,6 @@ void processMesh(DataGroup *group, double frame, const TMeshImage *meshImage,
//***********************************************************************************************
PlasticDeformerData::PlasticDeformerData()
- : m_so(), m_output()
{
}
@@ -398,8 +395,6 @@ PlasticDeformerData::PlasticDeformerData()
PlasticDeformerData::~PlasticDeformerData()
{
- delete[] m_so;
- delete[] m_output;
}
//***********************************************************************************************
@@ -407,7 +402,12 @@ PlasticDeformerData::~PlasticDeformerData()
//***********************************************************************************************
PlasticDeformerDataGroup::PlasticDeformerDataGroup()
- : m_datas(), m_compiled(PlasticDeformerStorage::NONE), m_upToDate(PlasticDeformerStorage::NONE), m_outputFrame((std::numeric_limits<double>::max)()), m_soMin(), m_soMax()
+ : m_datas()
+ , m_compiled(PlasticDeformerStorage::NONE)
+ , m_upToDate(PlasticDeformerStorage::NONE)
+ , m_outputFrame((std::numeric_limits<double>::max)())
+ , m_soMin()
+ , m_soMax()
{
}
@@ -415,7 +415,6 @@ PlasticDeformerDataGroup::PlasticDeformerDataGroup()
PlasticDeformerDataGroup::~PlasticDeformerDataGroup()
{
- delete[] m_datas;
}
//***********************************************************************************************