diff --git a/native/cocos/2d/renderer/RenderDrawInfo.cpp b/native/cocos/2d/renderer/RenderDrawInfo.cpp index 54441c1263..413217d818 100644 --- a/native/cocos/2d/renderer/RenderDrawInfo.cpp +++ b/native/cocos/2d/renderer/RenderDrawInfo.cpp @@ -85,10 +85,10 @@ void RenderDrawInfo::resetMeshIA() { void RenderDrawInfo::destroy() { _nextFreeIAHandle = 0; if (_iaInfo) { - CC_SAFE_RELEASE_NULL(_iaInfo->indexBuffer); + CC_SAFE_DELETE(_iaInfo->indexBuffer); if (!_iaInfo->vertexBuffers.empty()) { // only one vb - CC_SAFE_RELEASE_NULL(_iaInfo->vertexBuffers[0]); + CC_SAFE_DELETE(_iaInfo->vertexBuffers[0]); _iaInfo->vertexBuffers.clear(); } CC_SAFE_DELETE(_iaInfo); @@ -104,7 +104,7 @@ void RenderDrawInfo::destroy() { if (_localDSBF) { CC_SAFE_DELETE(_localDSBF->ds); - CC_SAFE_RELEASE_NULL(_localDSBF->uboBuf); + CC_SAFE_DELETE(_localDSBF->uboBuf); CC_SAFE_DELETE(_localDSBF); } } diff --git a/native/cocos/2d/renderer/UIMeshBuffer.cpp b/native/cocos/2d/renderer/UIMeshBuffer.cpp index 83aeb5e012..2bf6dc4901 100644 --- a/native/cocos/2d/renderer/UIMeshBuffer.cpp +++ b/native/cocos/2d/renderer/UIMeshBuffer.cpp @@ -49,7 +49,7 @@ void UIMeshBuffer::setIData(uint16_t* iData) { _iData = iData; } -void UIMeshBuffer::initialize(ccstd::vector&& attrs, bool needCreateLayout) { +void UIMeshBuffer::initialize(ccstd::vector &&attrs, bool needCreateLayout) { _attributes = attrs; _vertexFormatBytes = getAttributesStride(attrs); if (needCreateLayout) { @@ -74,29 +74,23 @@ void UIMeshBuffer::resetIA() { void UIMeshBuffer::destroy() { reset(); _attributes.clear(); - for (auto* vb : _iaInfo.vertexBuffers) { - vb->release(); + delete vb; } _iaInfo.vertexBuffers.clear(); - - CC_SAFE_RELEASE_NULL(_iaInfo.indexBuffer); - + CC_SAFE_DELETE(_iaInfo.indexBuffer); if (_needDeleteVData) { delete _vData; delete _iData; } - _vData = nullptr; _iData = nullptr; - // Destroy InputAssemblers for (auto* ia : _iaPool) { ia->destroy(); delete ia; } _iaPool.clear(); - if (_needDeleteLayout) { CC_SAFE_DELETE(_meshBufferLayout); } diff --git a/native/cocos/3d/skeletal-animation/SkeletalAnimationUtils.cpp b/native/cocos/3d/skeletal-animation/SkeletalAnimationUtils.cpp index 75d7fe5b78..ca9f621252 100644 --- a/native/cocos/3d/skeletal-animation/SkeletalAnimationUtils.cpp +++ b/native/cocos/3d/skeletal-animation/SkeletalAnimationUtils.cpp @@ -488,7 +488,7 @@ IAnimInfo JointAnimationInfo::getData(const ccstd::string &nodeID) { void JointAnimationInfo::destroy(const ccstd::string &nodeID) { if (_pool.find(nodeID) != _pool.end()) { - CC_SAFE_DESTROY_AND_RELEASE_NULL(_pool[nodeID].buffer); + CC_SAFE_DESTROY_AND_DELETE(_pool[nodeID].buffer); _pool.erase(nodeID); } } @@ -503,7 +503,7 @@ const IAnimInfo &JointAnimationInfo::switchClip(IAnimInfo &info /*, AnimationCli void JointAnimationInfo::clear() { for (auto pool : _pool) { - CC_SAFE_DESTROY_AND_RELEASE_NULL(pool.second.buffer); + CC_SAFE_DESTROY_AND_DELETE(pool.second.buffer); } _pool.clear(); } diff --git a/native/cocos/base/memory/Memory.h b/native/cocos/base/memory/Memory.h index 7866e06677..ae9407437c 100644 --- a/native/cocos/base/memory/Memory.h +++ b/native/cocos/base/memory/Memory.h @@ -103,19 +103,6 @@ public: (ptr) = nullptr; \ } -#define CC_SAFE_DESTROY_AND_RELEASE(ptr) \ - if (ptr) { \ - (ptr)->destroy(); \ - (ptr)->release(); \ - } - -#define CC_SAFE_DESTROY_AND_RELEASE_NULL(ptr) \ - if (ptr) { \ - (ptr)->destroy(); \ - (ptr)->release(); \ - (ptr) = nullptr; \ - } - #define CC_SAFE_DESTROY_NULL(ptr) \ if (ptr) { \ (ptr)->destroy(); \ diff --git a/native/cocos/bindings/manual/jsb_global.cpp b/native/cocos/bindings/manual/jsb_global.cpp index 94ff162a4b..69be4ead7f 100644 --- a/native/cocos/bindings/manual/jsb_global.cpp +++ b/native/cocos/bindings/manual/jsb_global.cpp @@ -581,7 +581,7 @@ bool jsb_global_load_image(const ccstd::string &path, const se::Value &callbackV auto app = CC_CURRENT_APPLICATION(); if (!app) { delete imgInfo; - img->release(); + delete img; return; } auto engine = app->getEngine(); @@ -606,7 +606,7 @@ bool jsb_global_load_image(const ccstd::string &path, const se::Value &callbackV SE_REPORT_ERROR("initWithImageFile: %s failed!", path.c_str()); } callbackPtr->toObject()->call(seArgs, nullptr); - img->release(); + delete img; }); }); }; @@ -712,7 +712,7 @@ static bool js_saveImageData(se::State &s) { // NOLINT } uint8ArrayObj->unroot(); uint8ArrayObj->decRef(); - img->release(); + delete img; }); }); return true; diff --git a/native/cocos/core/assets/BitmapFont.cpp b/native/cocos/core/assets/BitmapFont.cpp index 509099ddd3..4c7af37cd1 100644 --- a/native/cocos/core/assets/BitmapFont.cpp +++ b/native/cocos/core/assets/BitmapFont.cpp @@ -152,13 +152,13 @@ gfx::Texture *BitmapFontFace::loadTexture(const ccstd::string &path) { bool success = image->initWithImageFile(path); if (!success) { CC_LOG_WARNING("BitmapFontFace initWithImageFile failed, path: %s.", path.c_str()); - image->release(); + delete image; return nullptr; } if (image->getRenderFormat() != gfx::Format::R8 && image->getRenderFormat() != gfx::Format::L8) { CC_LOG_WARNING("BitmapFontFace loadTexture with invalid format, path: %s.", path.c_str()); - image->release(); + delete image; return nullptr; } @@ -181,7 +181,7 @@ gfx::Texture *BitmapFontFace::loadTexture(const ccstd::string &path) { {0U, 0U, 1U}}}; device->copyBuffersToTexture(buffers, texture, regions); - image->release(); + delete image; return texture; } diff --git a/native/cocos/network/HttpRequest.h b/native/cocos/network/HttpRequest.h index 2ed0a83d2b..8180cb7d56 100644 --- a/native/cocos/network/HttpRequest.h +++ b/native/cocos/network/HttpRequest.h @@ -86,6 +86,9 @@ public: HttpRequest() : _callback(nullptr) {} + /** Destructor. */ + ~HttpRequest() override = default; + // setter/getters for properties /** @@ -244,9 +247,6 @@ public: } protected: - /** Destructor. */ - ~HttpRequest() override = default; - // properties Type _requestType{Type::UNKNOWN}; /// kHttpRequestGet, kHttpRequestPost or other enums ccstd::string _url; /// target url that this request is sent to diff --git a/native/cocos/platform/Image.h b/native/cocos/platform/Image.h index 0bbb935a0a..d4937a08cb 100644 --- a/native/cocos/platform/Image.h +++ b/native/cocos/platform/Image.h @@ -36,6 +36,7 @@ namespace cc { class Image : public RefCounted { public: Image(); + ~Image() override; /** Supported formats for Image */ enum class Format { @@ -89,7 +90,6 @@ public: bool saveToFile(const std::string &filename, bool isToRGB = true); protected: - ~Image() override; bool initWithJpgData(const unsigned char *data, uint32_t dataLen); bool initWithPngData(const unsigned char *data, uint32_t dataLen); #if CC_USE_WEBP diff --git a/native/cocos/profiler/DebugRenderer.cpp b/native/cocos/profiler/DebugRenderer.cpp index fbd4030792..4cb6b1abf3 100644 --- a/native/cocos/profiler/DebugRenderer.cpp +++ b/native/cocos/profiler/DebugRenderer.cpp @@ -164,7 +164,7 @@ public: CC_SAFE_DELETE(batch); } - CC_SAFE_DESTROY_AND_RELEASE_NULL(_buffer); + CC_SAFE_DESTROY_AND_DELETE(_buffer); CC_SAFE_DESTROY_AND_DELETE(_inputAssembler); CC_PROFILE_MEMORY_DEC(DebugVertexBuffer, static_cast(_maxVertices * sizeof(DebugVertex))); } diff --git a/native/cocos/renderer/core/TextureBufferPool.h b/native/cocos/renderer/core/TextureBufferPool.h index ba914bccf4..87390c3c17 100644 --- a/native/cocos/renderer/core/TextureBufferPool.h +++ b/native/cocos/renderer/core/TextureBufferPool.h @@ -62,6 +62,7 @@ class TextureBufferPool : public RefCounted { public: TextureBufferPool(); explicit TextureBufferPool(gfx::Device *device); + ~TextureBufferPool() override; void initialize(const ITextureBufferPoolInfo &info); void destroy(); @@ -73,7 +74,6 @@ public: void update(const ITextureBufferHandle &handle, ArrayBuffer *buffer); private: - ~TextureBufferPool() override; index_t findAvailableSpace(uint32_t size, index_t chunkIdx) const; // [McDonald 12] Efficient Buffer Management diff --git a/native/cocos/renderer/gfx-agent/BufferAgent.cpp b/native/cocos/renderer/gfx-agent/BufferAgent.cpp index 6be2cbcd32..ac05640083 100644 --- a/native/cocos/renderer/gfx-agent/BufferAgent.cpp +++ b/native/cocos/renderer/gfx-agent/BufferAgent.cpp @@ -44,7 +44,7 @@ BufferAgent::~BufferAgent() { actor, _actor, stagingBuffer, std::move(_stagingBuffer), { - CC_SAFE_RELEASE(actor); + CC_SAFE_DELETE(actor); }); } @@ -87,7 +87,8 @@ void BufferAgent::doResize(uint32_t size, uint32_t /*count*/) { ENQUEUE_MESSAGE_1( mq, BufferFreeStagingBuffer, stagingBuffer, std::move(_stagingBuffer), - {}); + { + }); } if (hasFlag(_flags, BufferFlagBit::ENABLE_STAGING_WRITE) || (size > STAGING_BUFFER_THRESHOLD && hasFlag(_memUsage, MemoryUsageBit::HOST))) { diff --git a/native/cocos/renderer/gfx-base/GFXBuffer.h b/native/cocos/renderer/gfx-base/GFXBuffer.h index 04b3984e7b..7cbe204578 100644 --- a/native/cocos/renderer/gfx-base/GFXBuffer.h +++ b/native/cocos/renderer/gfx-base/GFXBuffer.h @@ -34,6 +34,7 @@ namespace gfx { class CC_DLL Buffer : public GFXObject, public RefCounted { public: Buffer(); + ~Buffer() override; static ccstd::hash_t computeHash(const BufferInfo &info); @@ -43,8 +44,8 @@ public: void destroy(); template - void write(const T &value, uint32_t offset) const { - write(reinterpret_cast(&value), offset, sizeof(T)); + void write(const T& value, uint32_t offset) const { + write(reinterpret_cast(&value), offset, sizeof(T)); } void write(const uint8_t *value, uint32_t offset, uint32_t size) const; @@ -64,7 +65,6 @@ public: inline bool isBufferView() const { return _isBufferView; } protected: - ~Buffer() override; virtual void doInit(const BufferInfo &info) = 0; virtual void doInit(const BufferViewInfo &info) = 0; virtual void doResize(uint32_t size, uint32_t count) = 0; @@ -73,7 +73,7 @@ protected: static uint8_t *getBufferStagingAddress(Buffer *buffer); static void flushBuffer(Buffer *buffer, const uint8_t *data); - virtual void flush(const uint8_t *data) { update(reinterpret_cast(data), _size); } + virtual void flush(const uint8_t *data) { update(reinterpret_cast(data), _size); } virtual uint8_t *getStagingAddress() const { return _data.get(); } BufferUsage _usage = BufferUsageBit::NONE; diff --git a/native/cocos/renderer/gfx-validator/BufferValidator.cpp b/native/cocos/renderer/gfx-validator/BufferValidator.cpp index 567fc194fa..7b1512b47c 100644 --- a/native/cocos/renderer/gfx-validator/BufferValidator.cpp +++ b/native/cocos/renderer/gfx-validator/BufferValidator.cpp @@ -49,7 +49,7 @@ BufferValidator::~BufferValidator() { view->onExpire(); } - CC_SAFE_RELEASE_NULL(_actor); + CC_SAFE_DELETE(_actor); uint64_t lifeTime = DeviceValidator::getInstance()->currentFrame() - _creationFrame; // skip those that have never been updated @@ -205,5 +205,6 @@ uint8_t *BufferValidator::getStagingAddress() const { return Buffer::getBufferStagingAddress(_actor); } + } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/pipeline/BatchedBuffer.cpp b/native/cocos/renderer/pipeline/BatchedBuffer.cpp index a2f0992edc..468f5f6e31 100644 --- a/native/cocos/renderer/pipeline/BatchedBuffer.cpp +++ b/native/cocos/renderer/pipeline/BatchedBuffer.cpp @@ -45,16 +45,16 @@ BatchedBuffer::~BatchedBuffer() = default; void BatchedBuffer::destroy() { for (auto &batch : _batches) { for (auto *vb : batch.vbs) { - CC_SAFE_DESTROY_AND_RELEASE(vb); + CC_SAFE_DESTROY_AND_DELETE(vb); } for (auto *data : batch.vbDatas) { CC_FREE(data); } - CC_SAFE_DESTROY_AND_RELEASE_NULL(batch.indexBuffer); - CC_SAFE_DESTROY_AND_RELEASE_NULL(batch.ia); - CC_SAFE_DESTROY_AND_RELEASE_NULL(batch.ubo); + CC_SAFE_DESTROY_AND_DELETE(batch.indexBuffer); + CC_SAFE_DESTROY_AND_DELETE(batch.ia); + CC_SAFE_DESTROY_AND_DELETE(batch.ubo); CC_FREE(batch.indexData); } diff --git a/native/cocos/renderer/pipeline/GeometryRenderer.cpp b/native/cocos/renderer/pipeline/GeometryRenderer.cpp index 29fa2e0848..2c1dffd882 100644 --- a/native/cocos/renderer/pipeline/GeometryRenderer.cpp +++ b/native/cocos/renderer/pipeline/GeometryRenderer.cpp @@ -115,7 +115,7 @@ private: inline void destroy() { _vertices.clear(); - CC_SAFE_DESTROY_AND_RELEASE_NULL(_buffer); + CC_SAFE_DESTROY_AND_DELETE(_buffer); CC_SAFE_DESTROY_AND_DELETE(_inputAssembler); CC_PROFILE_MEMORY_DEC(GeometryVertexBuffer, static_cast(_maxVertices * sizeof(T))); } diff --git a/native/cocos/renderer/pipeline/InstancedBuffer.cpp b/native/cocos/renderer/pipeline/InstancedBuffer.cpp index 9049f0a6b7..1f7083b961 100644 --- a/native/cocos/renderer/pipeline/InstancedBuffer.cpp +++ b/native/cocos/renderer/pipeline/InstancedBuffer.cpp @@ -43,7 +43,7 @@ InstancedBuffer::~InstancedBuffer() = default; void InstancedBuffer::destroy() { for (auto &instance : _instances) { - CC_SAFE_DESTROY_AND_RELEASE_NULL(instance.vb); + CC_SAFE_DESTROY_AND_DELETE(instance.vb); CC_SAFE_DESTROY_AND_DELETE(instance.ia); CC_FREE(instance.data); } diff --git a/native/cocos/renderer/pipeline/PipelineUBO.cpp b/native/cocos/renderer/pipeline/PipelineUBO.cpp index 6b1eec1ab2..cf1667fe49 100644 --- a/native/cocos/renderer/pipeline/PipelineUBO.cpp +++ b/native/cocos/renderer/pipeline/PipelineUBO.cpp @@ -474,7 +474,7 @@ void PipelineUBO::activate(gfx::Device *device, RenderPipeline *pipeline) { void PipelineUBO::destroy() { for (auto &ubo : _ubos) { - CC_SAFE_RELEASE(ubo) + CC_SAFE_DELETE(ubo) } _ubos.clear(); } @@ -506,7 +506,7 @@ void PipelineUBO::updateMultiCameraUBO(GlobalDSManager *globalDSMgr, const ccstd if (_cameraBufferView != nullptr) { _ubos.erase(std::remove(_ubos.begin(), _ubos.end(), _cameraBufferView), _ubos.end()); - CC_SAFE_RELEASE_NULL(_cameraBufferView); + CC_SAFE_DELETE(_cameraBufferView); } _cameraBufferView = _device->createBuffer({ _cameraBuffer, diff --git a/native/cocos/renderer/pipeline/RenderPipeline.cpp b/native/cocos/renderer/pipeline/RenderPipeline.cpp index 5a2d5e4651..6997bbd2d2 100644 --- a/native/cocos/renderer/pipeline/RenderPipeline.cpp +++ b/native/cocos/renderer/pipeline/RenderPipeline.cpp @@ -118,14 +118,14 @@ void RenderPipeline::onGlobalPipelineStateChanged() { } void RenderPipeline::destroyQuadInputAssembler() { - CC_SAFE_DESTROY_AND_RELEASE_NULL(_quadIB); + CC_SAFE_DESTROY_AND_DELETE(_quadIB); for (auto *node : _quadVB) { - CC_SAFE_DESTROY_AND_RELEASE(node); + CC_SAFE_DESTROY_AND_DELETE(node); } for (auto node : _quadIA) { - CC_SAFE_DESTROY_AND_RELEASE(node.second); + CC_SAFE_DESTROY_AND_DELETE(node.second); } _quadVB.clear(); _quadIA.clear(); diff --git a/native/cocos/renderer/pipeline/deferred/BloomStage.cpp b/native/cocos/renderer/pipeline/deferred/BloomStage.cpp index ea8af3f333..7e718496f6 100644 --- a/native/cocos/renderer/pipeline/deferred/BloomStage.cpp +++ b/native/cocos/renderer/pipeline/deferred/BloomStage.cpp @@ -106,11 +106,12 @@ void BloomStage::activate(RenderPipeline *pipeline, RenderFlow *flow) { } void BloomStage::destroy() { - CC_SAFE_RELEASE_NULL(_prefilterUBO); - CC_SAFE_RELEASE_NULL(_combineUBO); + CC_SAFE_DELETE(_prefilterUBO); + CC_SAFE_DELETE(_combineUBO); for (int i = 0; i < MAX_BLOOM_FILTER_PASS_NUM; ++i) { - CC_SAFE_RELEASE_NULL(_downsampleUBO[i]); - CC_SAFE_RELEASE_NULL(_upsampleUBO[i]); + CC_SAFE_DELETE(_downsampleUBO[i]); + + CC_SAFE_DELETE(_upsampleUBO[i]); } } diff --git a/native/cocos/renderer/pipeline/deferred/LightingStage.cpp b/native/cocos/renderer/pipeline/deferred/LightingStage.cpp index 221d0ac782..895d12252d 100644 --- a/native/cocos/renderer/pipeline/deferred/LightingStage.cpp +++ b/native/cocos/renderer/pipeline/deferred/LightingStage.cpp @@ -98,8 +98,8 @@ const RenderStageInfo &LightingStage::getInitializeInfo() { return LightingStage LightingStage::LightingStage() = default; LightingStage::~LightingStage() { - CC_SAFE_DESTROY_AND_RELEASE_NULL(_deferredLitsBufs); - CC_SAFE_DESTROY_AND_RELEASE_NULL(_deferredLitsBufView); + CC_SAFE_DESTROY_AND_DELETE(_deferredLitsBufs); + CC_SAFE_DESTROY_AND_DELETE(_deferredLitsBufView); } bool LightingStage::initialize(const RenderStageInfo &info) { diff --git a/native/cocos/renderer/pipeline/deferred/ReflectionComp.cpp b/native/cocos/renderer/pipeline/deferred/ReflectionComp.cpp index f51382aa0b..2178cf4800 100644 --- a/native/cocos/renderer/pipeline/deferred/ReflectionComp.cpp +++ b/native/cocos/renderer/pipeline/deferred/ReflectionComp.cpp @@ -24,7 +24,7 @@ ReflectionComp::~ReflectionComp() { CC_SAFE_DESTROY_AND_DELETE(_localDescriptorSetLayout); - CC_SAFE_DESTROY_AND_RELEASE_NULL(_compConstantsBuffer); + CC_SAFE_DESTROY_AND_DELETE(_compConstantsBuffer); } namespace {