compositor: replace C++ new/delete with guardedalloc.
authorCampbell Barton <ideasman42@gmail.com>
Thu, 16 Aug 2012 12:32:48 +0000 (12:32 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 16 Aug 2012 12:32:48 +0000 (12:32 +0000)
16 files changed:
source/blender/compositor/intern/COM_ExecutionGroup.cpp
source/blender/compositor/intern/COM_MemoryBuffer.cpp
source/blender/compositor/intern/COM_WorkScheduler.cpp
source/blender/compositor/operations/COM_AntiAliasOperation.cpp
source/blender/compositor/operations/COM_BlurBaseOperation.cpp
source/blender/compositor/operations/COM_ConvolutionFilterOperation.cpp
source/blender/compositor/operations/COM_DilateErodeOperation.cpp
source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cpp
source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp
source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cpp
source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp
source/blender/compositor/operations/COM_GaussianXBlurOperation.cpp
source/blender/compositor/operations/COM_GaussianYBlurOperation.cpp
source/blender/compositor/operations/COM_InpaintOperation.cpp
source/blender/compositor/operations/COM_MovieDistortionOperation.h
source/blender/compositor/operations/COM_VectorBlurOperation.cpp

index 9a80c5e82aedebf6565ed34dc36f944b85e24036..97afb7b6bc3c58143315f83f2ade8a2fe2a8c44a 100644 (file)
@@ -38,6 +38,7 @@
 #include "COM_ChunkOrder.h"
 #include "COM_ExecutionSystemHelper.h"
 
+#include "MEM_guardedalloc.h"
 #include "BLI_math.h"
 #include "PIL_time.h"
 #include "WM_api.h"
@@ -148,14 +149,14 @@ NodeOperation *ExecutionGroup::getOutputNodeOperation() const
 void ExecutionGroup::initExecution()
 {
        if (this->m_chunkExecutionStates != NULL) {
-               delete[] this->m_chunkExecutionStates;
+               MEM_freeN(this->m_chunkExecutionStates);
        }
        unsigned int index;
        determineNumberOfChunks();
 
        this->m_chunkExecutionStates = NULL;
        if (this->m_numberOfChunks != 0) {
-               this->m_chunkExecutionStates = new ChunkExecutionState[this->m_numberOfChunks];
+               this->m_chunkExecutionStates = (ChunkExecutionState *)MEM_mallocN(sizeof(ChunkExecutionState) * this->m_numberOfChunks, __func__);
                for (index = 0; index < this->m_numberOfChunks; index++) {
                        this->m_chunkExecutionStates[index] = COM_ES_NOT_SCHEDULED;
                }
@@ -180,7 +181,7 @@ void ExecutionGroup::initExecution()
 void ExecutionGroup::deinitExecution()
 {
        if (this->m_chunkExecutionStates != NULL) {
-               delete[] this->m_chunkExecutionStates;
+               MEM_freeN(this->m_chunkExecutionStates);
                this->m_chunkExecutionStates = NULL;
        }
        this->m_numberOfChunks = 0;
@@ -227,7 +228,7 @@ void ExecutionGroup::execute(ExecutionSystem *graph)
        this->m_chunksFinished = 0;
        this->m_bTree = bTree;
        unsigned int index;
-       unsigned int *chunkOrder = new unsigned int[this->m_numberOfChunks];
+       unsigned int *chunkOrder = (unsigned int *)MEM_mallocN(sizeof(unsigned int) * this->m_numberOfChunks, __func__);
 
        for (chunkNumber = 0; chunkNumber < this->m_numberOfChunks; chunkNumber++) {
                chunkOrder[chunkNumber] = chunkNumber;
@@ -256,10 +257,10 @@ void ExecutionGroup::execute(ExecutionSystem *graph)
                        break;
                case COM_TO_CENTER_OUT:
                {
-                       ChunkOrderHotspot **hotspots = new ChunkOrderHotspot *[1];
+                       ChunkOrderHotspot *hotspots[1];
                        hotspots[0] = new ChunkOrderHotspot(this->m_width * centerX, this->m_height * centerY, 0.0f);
                        rcti rect;
-                       ChunkOrder *chunkOrders = new ChunkOrder[this->m_numberOfChunks];
+                       ChunkOrder *chunkOrders = (ChunkOrder *)MEM_mallocN(sizeof(ChunkOrder) * this->m_numberOfChunks, __func__);
                        for (index = 0; index < this->m_numberOfChunks; index++) {
                                determineChunkRect(&rect, index);
                                chunkOrders[index].setChunkNumber(index);
@@ -274,13 +275,12 @@ void ExecutionGroup::execute(ExecutionSystem *graph)
                        }
 
                        delete hotspots[0];
-                       delete[] hotspots;
-                       delete[] chunkOrders;
+                       MEM_freeN(chunkOrders);
                }
                break;
                case COM_TO_RULE_OF_THIRDS:
                {
-                       ChunkOrderHotspot **hotspots = new ChunkOrderHotspot *[9];
+                       ChunkOrderHotspot *hotspots[9];
                        unsigned int tx = this->m_width / 6;
                        unsigned int ty = this->m_height / 6;
                        unsigned int mx = this->m_width / 2;
@@ -299,7 +299,7 @@ void ExecutionGroup::execute(ExecutionSystem *graph)
                        hotspots[7] = new ChunkOrderHotspot(mx, ty, addition * 7);
                        hotspots[8] = new ChunkOrderHotspot(mx, by, addition * 8);
                        rcti rect;
-                       ChunkOrder *chunkOrders = new ChunkOrder[this->m_numberOfChunks];
+                       ChunkOrder *chunkOrders = (ChunkOrder *)MEM_mallocN(sizeof(ChunkOrder) * this->m_numberOfChunks, __func__);
                        for (index = 0; index < this->m_numberOfChunks; index++) {
                                determineChunkRect(&rect, index);
                                chunkOrders[index].setChunkNumber(index);
@@ -323,8 +323,7 @@ void ExecutionGroup::execute(ExecutionSystem *graph)
                        delete hotspots[6];
                        delete hotspots[7];
                        delete hotspots[8];
-                       delete[] hotspots;
-                       delete[] chunkOrders;
+                       MEM_freeN(chunkOrders);
                }
                break;
                case COM_TO_TOP_DOWN:
@@ -372,7 +371,7 @@ void ExecutionGroup::execute(ExecutionSystem *graph)
                }
        }
 
-       delete[] chunkOrder;
+       MEM_freeN(chunkOrder);
 }
 
 MemoryBuffer **ExecutionGroup::getInputBuffersOpenCL(int chunkNumber)
@@ -383,10 +382,7 @@ MemoryBuffer **ExecutionGroup::getInputBuffersOpenCL(int chunkNumber)
        determineChunkRect(&rect, chunkNumber);
 
        this->determineDependingMemoryProxies(&memoryproxies);
-       MemoryBuffer **memoryBuffers = new MemoryBuffer *[this->m_cachedMaxReadBufferOffset];
-       for (index = 0; index < this->m_cachedMaxReadBufferOffset; index++) {
-               memoryBuffers[index] = NULL;
-       }
+       MemoryBuffer **memoryBuffers = (MemoryBuffer **)MEM_callocN(sizeof(MemoryBuffer *) * this->m_cachedMaxReadBufferOffset, __func__);
        rcti output;
        for (index = 0; index < this->m_cachedReadOperations.size(); index++) {
                ReadBufferOperation *readOperation = (ReadBufferOperation *)this->m_cachedReadOperations[index];
@@ -422,7 +418,7 @@ void ExecutionGroup::finalizeChunkExecution(int chunkNumber, MemoryBuffer **memo
                                }
                        }
                }
-               delete[] memoryBuffers;
+               MEM_freeN(memoryBuffers);
        }
        if (this->m_bTree) {
                // status report is only performed for top level Execution Groups.
index d227f9cc4bb02302502c8d7ad7afcb2ecd42b1b5..ee1c0320f5f792e275138db8487dec5fcb774119 100644 (file)
@@ -75,7 +75,7 @@ float *MemoryBuffer::convertToValueBuffer()
        const unsigned int size = this->determineBufferSize();
        unsigned int i;
 
-       float *result = new float[size];
+       float *result = (float *)MEM_mallocN(sizeof(float) * size, __func__);
 
        const float *fp_src = this->m_buffer;
        float       *fp_dst = result;
index 61b18a6daf4f1688f0af0a884072d886890113c7..dcec228a6b7ee59d4a10f4c1f9eafa47837b81d6 100644 (file)
@@ -32,6 +32,8 @@
 #include "OCL_opencl.h"
 #include "COM_WriteBufferOperation.h"
 
+#include "MEM_guardedalloc.h"
+
 #include "PIL_time.h"
 #include "BLI_threads.h"
 
@@ -99,20 +101,20 @@ void **g_highlightedNodesRead;
 void COM_startReadHighlights()
 {
        if (g_highlightedNodesRead) {
-               delete [] g_highlightedNodesRead;
+               MEM_freeN(g_highlightedNodesRead);
        }
        
        g_highlightedNodesRead = g_highlightedNodes;
-       g_highlightedNodes = new void *[MAX_HIGHLIGHT];
+       g_highlightedNodes = (void **)MEM_callocN(sizeof(void *) * MAX_HIGHLIGHT, __func__);
        g_highlightIndex = 0;
-       for (int i = 0 ; i < MAX_HIGHLIGHT; i++) {
-               g_highlightedNodes[i] = 0;
-       }
 }
 
 int COM_isHighlightedbNode(bNode *bnode)
 {
-       if (!g_highlightedNodesRead) return false;
+       if (!g_highlightedNodesRead) {
+               return false;
+       }
+
        for (int i = 0 ; i < MAX_HIGHLIGHT; i++) {
                void *p = g_highlightedNodesRead[i];
                if (!p) return false;
@@ -255,8 +257,8 @@ extern void clContextError(const char *errinfo, const void *private_info, size_t
 
 void WorkScheduler::initialize()
 {
-       g_highlightedNodesRead = 0;
-       g_highlightedNodes = 0;
+       g_highlightedNodesRead = NULL;
+       g_highlightedNodes = NULL;
        COM_startReadHighlights();
 #if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE
        int numberOfCPUThreads = BLI_system_thread_count();
@@ -275,7 +277,7 @@ void WorkScheduler::initialize()
                error = clGetPlatformIDs(0, 0, &numberOfPlatforms);
                if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error));  }
                if (G.f & G_DEBUG) printf("%d number of platforms\n", numberOfPlatforms);
-               cl_platform_id *platforms = new cl_platform_id[numberOfPlatforms];
+               cl_platform_id *platforms = (cl_platform_id *)MEM_mallocN(sizeof(cl_platform_id) * numberOfPlatforms, __func__);
                error = clGetPlatformIDs(numberOfPlatforms, platforms, 0);
                unsigned int indexPlatform;
                for (indexPlatform = 0; indexPlatform < numberOfPlatforms; indexPlatform++) {
@@ -283,7 +285,7 @@ void WorkScheduler::initialize()
                        cl_uint numberOfDevices = 0;
                        clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, 0, &numberOfDevices);
                        if (numberOfDevices > 0) {
-                               cl_device_id *cldevices = new cl_device_id[numberOfDevices];
+                               cl_device_id *cldevices = (cl_device_id *)MEM_mallocN(sizeof(cl_device_id) * numberOfDevices, __func__);
                                clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, numberOfDevices, cldevices, 0);
 
                                g_context = clCreateContext(NULL, numberOfDevices, cldevices, clContextError, NULL, &error);
@@ -297,12 +299,12 @@ void WorkScheduler::initialize()
                                        printf("CLERROR[%d]: %s\n", error, clewErrorString(error));     
                                        error2 = clGetProgramBuildInfo(g_program, cldevices[0], CL_PROGRAM_BUILD_LOG, 0, NULL, &ret_val_size);
                                        if (error2 != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); }
-                                       char *build_log =  new char[ret_val_size + 1];
+                                       char *build_log = (char *)MEM_mallocN(sizeof(char) * ret_val_size + 1, __func__);
                                        error2 = clGetProgramBuildInfo(g_program, cldevices[0], CL_PROGRAM_BUILD_LOG, ret_val_size, build_log, NULL);
                                        if (error2 != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); }
                                        build_log[ret_val_size] = '\0';
                                        printf("%s", build_log);
-                                       delete build_log;
+                                       MEM_freeN(build_log);
                                }
                                else {
                                        unsigned int indexDevices;
@@ -316,10 +318,10 @@ void WorkScheduler::initialize()
                                                g_gpudevices.push_back(clDevice);
                                        }
                                }
-                               delete[] cldevices;
+                               MEM_freeN(cldevices);
                        }
                }
-               delete[] platforms;
+               MEM_freeN(platforms);
        }
 #endif
 #endif
index 12bf651992e205259922d79f5ec5bb8ff84557f0..c37830a9d92eab4bb01137f34b2c2093f1eca9d6 100644 (file)
 #include "COM_AntiAliasOperation.h"
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
+#include "BKE_utildefines.h"
+
+#include "MEM_guardedalloc.h"
+
 extern "C" {
        #include "RE_render_ext.h"
 }
@@ -58,7 +62,7 @@ void AntiAliasOperation::deinitExecution()
 {
        this->m_valueReader = NULL;
        if (this->m_buffer) {
-               delete this->m_buffer;
+               MEM_freeN(this->m_buffer);
        }
        NodeOperation::deinitMutex();
 }
@@ -90,12 +94,10 @@ void *AntiAliasOperation::initializeTileData(rcti *rect)
                MemoryBuffer *tile = (MemoryBuffer *)this->m_valueReader->initializeTileData(rect);
                int size = tile->getHeight() * tile->getWidth();
                float *input = tile->getBuffer();
-               char *valuebuffer = new char[size];
+               char *valuebuffer = (char *)MEM_mallocN(sizeof(char) * size, __func__);
                for (int i = 0; i < size; i++) {
                        float in = input[i * COM_NUMBER_OF_CHANNELS];
-                       if (in < 0.0f) { in = 0.0f; }
-                       if (in > 1.0f) {in = 1.0f; }
-                       valuebuffer[i] = in * 255;
+                       valuebuffer[i] = FTOCHAR(in);
                }
                antialias_tagbuf(tile->getWidth(), tile->getHeight(), valuebuffer);
                this->m_buffer = valuebuffer;
index 98aeba41ecbe304bee46889f1777eb57f995d0f6..c527807f8394bd0b0581838a4e417d5fa8282005 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "COM_BlurBaseOperation.h"
 #include "BLI_math.h"
+#include "MEM_guardedalloc.h"
 
 extern "C" {
        #include "RE_pipeline.h"
@@ -74,7 +75,7 @@ float *BlurBaseOperation::make_gausstab(int rad)
 
        n = 2 * rad + 1;
 
-       gausstab = new float[n];
+       gausstab = (float *)MEM_mallocN(sizeof(float) * n, __func__);
 
        sum = 0.0f;
        for (i = -rad; i <= rad; i++) {
@@ -99,7 +100,7 @@ float *BlurBaseOperation::make_dist_fac_inverse(int rad, int falloff)
 
        n = 2 * rad + 1;
 
-       dist_fac_invert = new float[n];
+       dist_fac_invert = (float *)MEM_mallocN(sizeof(float) * n, __func__);
 
        for (i = -rad; i <= rad; i++) {
                val = 1.0f - fabsf(((float)i / (float)rad));
index fd593b39dcdbd8df8cfa71e49ceff595c200ee87..553a9827ffa62e0e6abe354f3ae13da2bac6946d 100644 (file)
@@ -24,6 +24,8 @@
 
 #include "BLI_utildefines.h"
 
+#include "MEM_guardedalloc.h"
+
 ConvolutionFilterOperation::ConvolutionFilterOperation() : NodeOperation()
 {
        this->addInputSocket(COM_DT_COLOR);
@@ -42,7 +44,7 @@ void ConvolutionFilterOperation::initExecution()
 
 void ConvolutionFilterOperation::set3x3Filter(float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9)
 {
-       this->m_filter = new float[9];
+       this->m_filter = (float *)MEM_mallocN(sizeof(float) * 9, __func__);
        this->m_filter[0] = f1;
        this->m_filter[1] = f2;
        this->m_filter[2] = f3;
@@ -61,7 +63,7 @@ void ConvolutionFilterOperation::deinitExecution()
        this->m_inputOperation = NULL;
        this->m_inputValueOperation = NULL;
        if (this->m_filter) {
-               delete[] this->m_filter;
+               MEM_freeN(this->m_filter);
                this->m_filter = NULL;
        }
 }
index 5e70187557b7552cff0913c698cf77a90f48e507..2687fee28ce7773f7c42ddf764ba5e6d42158315 100644 (file)
@@ -24,6 +24,8 @@
 #include "BLI_math.h"
 #include "COM_OpenCLDevice.h"
 
+#include "MEM_guardedalloc.h"
+
 // DilateErode Distance Threshold
 DilateErodeThresholdOperation::DilateErodeThresholdOperation() : NodeOperation()
 {
@@ -384,7 +386,7 @@ void DilateStepOperation::deinitExecution()
        this->m_inputProgram = NULL;
        this->deinitMutex();
        if (this->m_cached_buffer) {
-               delete [] this->m_cached_buffer;
+               MEM_freeN(this->m_cached_buffer);
                this->m_cached_buffer = NULL;
        }
 }
index d5daace059dddc062fe9865dfbd16b5356da7a43..39665b10f4893b5384ff956a49693edf91c7ecb1 100644 (file)
@@ -1269,12 +1269,12 @@ void *DoubleEdgeMaskOperation::initializeTileData(rcti *rect)
        if (this->m_cachedInstance == NULL) {
                MemoryBuffer *innerMask = (MemoryBuffer *)this->m_inputInnerMask->initializeTileData(rect);
                MemoryBuffer *outerMask = (MemoryBuffer *)this->m_inputOuterMask->initializeTileData(rect);
-               float *data = new float[this->getWidth() * this->getHeight()];
+               float *data = (float *)MEM_mallocN(sizeof(float) * this->getWidth() * this->getHeight(), __func__);
                float *imask = innerMask->convertToValueBuffer();
                float *omask = outerMask->convertToValueBuffer();
                doDoubleEdgeMask(imask, omask, data);
-               delete [] imask;
-               delete [] omask;
+               MEM_freeN(imask);
+               MEM_freeN(omask);
                this->m_cachedInstance = data;
        }
        unlockMutex();
@@ -1293,7 +1293,7 @@ void DoubleEdgeMaskOperation::deinitExecution()
        this->m_inputOuterMask = NULL;
        deinitMutex();
        if (this->m_cachedInstance) {
-               delete this->m_cachedInstance;
+               MEM_freeN(this->m_cachedInstance);
                this->m_cachedInstance = NULL;
        }
 }
index 935bfcac6c7f438083fe9a0551d6a1a026a98819..82f38556e823dd1d79b0c9db90fea18d9e14f04f 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "COM_GaussianAlphaXBlurOperation.h"
 #include "BLI_math.h"
+#include "MEM_guardedalloc.h"
 
 extern "C" {
        #include "RE_pipeline.h"
@@ -154,9 +155,9 @@ void GaussianAlphaXBlurOperation::executePixel(float output[4], int x, int y, vo
 void GaussianAlphaXBlurOperation::deinitExecution()
 {
        BlurBaseOperation::deinitExecution();
-       delete [] this->m_gausstab;
+       MEM_freeN(this->m_gausstab);
        this->m_gausstab = NULL;
-       delete [] this->m_distbuf_inv;
+       MEM_freeN(this->m_distbuf_inv);
        this->m_distbuf_inv = NULL;
 
        deinitMutex();
index 375f1bcf07c776c92a32412e17228693994c0200..bfd9564817e4223a291c43541e396ebc0ddc55cf 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "COM_GaussianAlphaYBlurOperation.h"
 #include "BLI_math.h"
+#include "MEM_guardedalloc.h"
 
 extern "C" {
        #include "RE_pipeline.h"
@@ -154,9 +155,9 @@ void GaussianAlphaYBlurOperation::executePixel(float output[4], int x, int y, vo
 void GaussianAlphaYBlurOperation::deinitExecution()
 {
        BlurBaseOperation::deinitExecution();
-       delete [] this->m_gausstab;
+       MEM_freeN(this->m_gausstab);
        this->m_gausstab = NULL;
-       delete [] this->m_distbuf_inv;
+       MEM_freeN(this->m_distbuf_inv);
        this->m_distbuf_inv = NULL;
 
        deinitMutex();
index d97d2f15ded220af536086b2dab18278799f79c2..a9bcb2dd75209a39eddda081ae10e6cf61f1b1fe 100644 (file)
@@ -88,7 +88,7 @@ void GaussianBokehBlurOperation::updateGauss()
                n = (2 * this->m_radx + 1) * (2 * this->m_rady + 1);
        
                /* create a full filter image */
-               ddgauss = new float[n];
+               ddgauss = (float *)MEM_mallocN(sizeof(float) * n, __func__);
                dgauss = ddgauss;
                val = 0.0f;
                for (j = -this->m_rady; j <= this->m_rady; j++) {
@@ -103,8 +103,9 @@ void GaussianBokehBlurOperation::updateGauss()
                }
                if (val != 0.0f) {
                        val = 1.0f / val;
-                       for (j = n - 1; j >= 0; j--)
+                       for (j = n - 1; j >= 0; j--) {
                                ddgauss[j] *= val;
+                       }
                }
                else ddgauss[4] = 1.0f;
                
@@ -158,7 +159,7 @@ void GaussianBokehBlurOperation::executePixel(float output[4], int x, int y, voi
 void GaussianBokehBlurOperation::deinitExecution()
 {
        BlurBaseOperation::deinitExecution();
-       delete [] this->m_gausstab;
+       MEM_freeN(this->m_gausstab);
        this->m_gausstab = NULL;
 
        deinitMutex();
@@ -258,8 +259,9 @@ void GaussianBlurReferenceOperation::updateGauss()
        int i;
        int x = MAX2(m_radx, m_rady);
        this->m_maintabs = (float **)MEM_mallocN(x * sizeof(float *), "gauss array");
-       for (i = 0; i < x; i++)
+       for (i = 0; i < x; i++) {
                m_maintabs[i] = make_gausstab(i + 1);
+       }
 }
 
 void GaussianBlurReferenceOperation::executePixel(float output[4], int x, int y, void *data)
@@ -326,8 +328,9 @@ void GaussianBlurReferenceOperation::deinitExecution()
 {
        int x, i;
        x = MAX2(m_radx, m_rady);
-       for (i = 0; i < x; i++)
-               delete []m_maintabs[i];
+       for (i = 0; i < x; i++) {
+               MEM_freeN(m_maintabs[i]);
+       }
        MEM_freeN(m_maintabs);
        BlurBaseOperation::deinitExecution();
 }
index 01c8573882265778626a494d2949ccfa6574a896..984119b926af305d1e6bcfb99e81d601ed65b217 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "COM_GaussianXBlurOperation.h"
 #include "BLI_math.h"
+#include "MEM_guardedalloc.h"
 
 extern "C" {
        #include "RE_pipeline.h"
@@ -107,7 +108,7 @@ void GaussianXBlurOperation::executePixel(float output[4], int x, int y, void *d
 void GaussianXBlurOperation::deinitExecution()
 {
        BlurBaseOperation::deinitExecution();
-       delete [] this->m_gausstab;
+       MEM_freeN(this->m_gausstab);
        this->m_gausstab = NULL;
 
        deinitMutex();
index 298b4660c6a5b5345445c4bfaa5ad610688a4566..192bc29e1ae4f513b108e86d0d594c1b3e954098 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "COM_GaussianYBlurOperation.h"
 #include "BLI_math.h"
+#include "MEM_guardedalloc.h"
 
 extern "C" {
        #include "RE_pipeline.h"
@@ -108,7 +109,7 @@ void GaussianYBlurOperation::executePixel(float output[4], int x, int y, void *d
 void GaussianYBlurOperation::deinitExecution()
 {
        BlurBaseOperation::deinitExecution();
-       delete [] this->m_gausstab;
+       MEM_freeN(this->m_gausstab);
        this->m_gausstab = NULL;
 
        deinitMutex();
index 9ce682ffe496ed9bbf784ef758fcdbfeeb090332..bfc0ecd1c00e57113eabed688299227e13920fef 100644 (file)
@@ -121,7 +121,7 @@ void InpaintSimpleOperation::calc_manhatten_distance()
 {
        int width = this->getWidth();
        int height = this->getHeight();
-       short *m = this->m_manhatten_distance = new short[width * height];
+       short *m = this->m_manhatten_distance = (short *)MEM_mallocN(sizeof(short) * width * height, __func__);
        int *offsets;
 
        offsets = (int *)MEM_callocN(sizeof(int) * (width + height + 1), "InpaintSimpleOperation offsets");
@@ -163,7 +163,7 @@ void InpaintSimpleOperation::calc_manhatten_distance()
        }
        
        this->m_area_size = offsets[width + height];
-       this->m_pixelorder = new int[this->m_area_size];
+       this->m_pixelorder = (int *)MEM_mallocN(sizeof(int) * this->m_area_size, __func__);
        
        for (int i = 0; i < width * height; i++) {
                if (m[i] > 0) {
@@ -224,9 +224,7 @@ void *InpaintSimpleOperation::initializeTileData(rcti *rect)
        lockMutex();
        if (!this->m_cached_buffer_ready) {
                MemoryBuffer *buf = (MemoryBuffer *)this->m_inputImageProgram->initializeTileData(rect);
-
-               this->m_cached_buffer = new float[this->getWidth() * this->getHeight() * COM_NUMBER_OF_CHANNELS];
-               memcpy(this->m_cached_buffer, buf->getBuffer(), this->getWidth() * this->getHeight() * COM_NUMBER_OF_CHANNELS * sizeof(float));
+               this->m_cached_buffer = (float *)MEM_dupallocN(buf->getBuffer());
 
                this->calc_manhatten_distance();
 
@@ -255,17 +253,17 @@ void InpaintSimpleOperation::deinitExecution()
        this->m_inputImageProgram = NULL;
        this->deinitMutex();
        if (this->m_cached_buffer) {
-               delete [] this->m_cached_buffer;
+               MEM_freeN(this->m_cached_buffer);
                this->m_cached_buffer = NULL;
        }
 
        if (this->m_pixelorder) {
-               delete [] this->m_pixelorder;
+               MEM_freeN(this->m_pixelorder);
                this->m_pixelorder = NULL;
        }
 
        if (this->m_manhatten_distance) {
-               delete [] this->m_manhatten_distance;
+               MEM_freeN(this->m_manhatten_distance);
                this->m_manhatten_distance = NULL;
        }
        this->m_cached_buffer_ready = false;
index 00723d92a840102d1568b5d113f6a8d356772c3e..7e62de7b9f1b9390b427ddc05add4b3c25c9937e 100644 (file)
@@ -25,6 +25,8 @@
 
 #include "COM_NodeOperation.h"
 #include "DNA_movieclip_types.h"
+#include "MEM_guardedalloc.h"
+
 extern "C" {
        #include "BKE_tracking.h"
        #include "PIL_time.h"
@@ -62,22 +64,19 @@ public:
                this->m_calibration_width = calibration_width;
                this->m_calibration_height = calibration_height;
                this->m_inverted = inverted;
-               this->m_bufferCalculated = new int[this->m_width * this->m_height];
-               this->m_buffer = new float[this->m_width * this->m_height * 2];
-               for (int i = 0; i < this->m_width * this->m_height; i++) {
-                       this->m_bufferCalculated[i] = 0;
-               }
+               this->m_bufferCalculated = (int *)MEM_callocN(sizeof(int) * this->m_width * this->m_height, __func__);
+               this->m_buffer = (float *)MEM_mallocN(sizeof(float) * this->m_width * this->m_height * 2, __func__);
                this->updateLastUsage();
        }
        
        ~DistortionCache() {
                if (this->m_buffer) {
-                       delete[] this->m_buffer;
+                       MEM_freeN(this->m_buffer);
                        this->m_buffer = NULL;
                }
                
                if (this->m_bufferCalculated) {
-                       delete[] this->m_bufferCalculated;
+                       MEM_freeN(this->m_bufferCalculated);
                        this->m_bufferCalculated = NULL;
                }
        }
index ebf3b772b3ba7c0bd326b8fe1c6c89891c695f7b..08ef1249a6a22002be992945a96e703ee2bc193b 100644 (file)
@@ -23,6 +23,8 @@
 #include "COM_VectorBlurOperation.h"
 #include "BLI_math.h"
 
+#include "MEM_guardedalloc.h"
+
 // use the implementation of blender internal renderer to calculate the vector blur.
 extern "C" {
        #include "RE_pipeline.h"
@@ -66,7 +68,7 @@ void VectorBlurOperation::deinitExecution()
        this->m_inputSpeedProgram = NULL;
        this->m_inputZProgram = NULL;
        if (this->m_cachedInstance) {
-               delete [] this->m_cachedInstance;
+               MEM_freeN(this->m_cachedInstance);
                this->m_cachedInstance = NULL;
        }
 }
@@ -81,8 +83,7 @@ void *VectorBlurOperation::initializeTileData(rcti *rect)
                MemoryBuffer *tile = (MemoryBuffer *)this->m_inputImageProgram->initializeTileData(rect);
                MemoryBuffer *speed = (MemoryBuffer *)this->m_inputSpeedProgram->initializeTileData(rect);
                MemoryBuffer *z = (MemoryBuffer *)this->m_inputZProgram->initializeTileData(rect);
-               float *data = new float[this->getWidth() * this->getHeight() * COM_NUMBER_OF_CHANNELS];
-               memcpy(data, tile->getBuffer(), this->getWidth() * this->getHeight() * COM_NUMBER_OF_CHANNELS * sizeof(float));
+               float *data = (float *)MEM_dupallocN(tile->getBuffer());
                this->generateVectorBlur(data, tile, speed, z);
                this->m_cachedInstance = data;
        }
@@ -115,6 +116,6 @@ void VectorBlurOperation::generateVectorBlur(float *data, MemoryBuffer *inputIma
        blurdata.curved = this->m_settings->curved;
        blurdata.fac = this->m_settings->fac;
        RE_zbuf_accumulate_vecblur(&blurdata, this->getWidth(), this->getHeight(), data, inputImage->getBuffer(), inputSpeed->getBuffer(), zbuf);
-       delete [] zbuf;
+       MEM_freeN((void *)zbuf);
        return;
 }