Revert "Hide destructor (#13105)" (#13121)

This reverts commit b5804b58c8.
This commit is contained in:
minggo
2022-10-21 18:55:32 +08:00
committed by GitHub
parent 55fc0319d6
commit d77afc3f06
21 changed files with 48 additions and 64 deletions
+3 -3
View File
@@ -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);
}
}
+3 -9
View File
@@ -49,7 +49,7 @@ void UIMeshBuffer::setIData(uint16_t* iData) {
_iData = iData;
}
void UIMeshBuffer::initialize(ccstd::vector<gfx::Attribute>&& attrs, bool needCreateLayout) {
void UIMeshBuffer::initialize(ccstd::vector<gfx::Attribute> &&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);
}
@@ -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();
}
-13
View File
@@ -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(); \
+3 -3
View File
@@ -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;
+3 -3
View File
@@ -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;
}
+3 -3
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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<uint32_t>(_maxVertices * sizeof(DebugVertex)));
}
@@ -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
@@ -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))) {
+4 -4
View File
@@ -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 <typename T>
void write(const T &value, uint32_t offset) const {
write(reinterpret_cast<const uint8_t *>(&value), offset, sizeof(T));
void write(const T& value, uint32_t offset) const {
write(reinterpret_cast<const uint8_t*>(&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<const void *>(data), _size); }
virtual void flush(const uint8_t *data) { update(reinterpret_cast<const void*>(data), _size); }
virtual uint8_t *getStagingAddress() const { return _data.get(); }
BufferUsage _usage = BufferUsageBit::NONE;
@@ -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
@@ -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);
}
@@ -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<uint32_t>(_maxVertices * sizeof(T)));
}
@@ -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);
}
@@ -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,
@@ -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();
@@ -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]);
}
}
@@ -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) {
@@ -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 {