From 444bfe31c415e78211a64d1d8d8db5984f18f43c Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 21 Apr 2022 16:39:34 +0800 Subject: [PATCH] Refactor CC_NEW/CC_DELETE (#10810) * replace CC_NEW/CC_DELETE with ccnew/delete --- native/cocos/3d/assets/Mesh.cpp | 12 ++-- native/cocos/3d/assets/Morph.cpp | 2 +- native/cocos/3d/assets/MorphRendering.cpp | 24 +++---- native/cocos/3d/misc/CreateMesh.cpp | 8 +-- native/cocos/3d/models/SkinningModel.cpp | 2 +- .../SkeletalAnimationUtils.cpp | 8 +-- .../SkeletalAnimationUtils.h | 2 +- native/cocos/audio/AudioEngine.cpp | 7 +- .../audio/android/AudioDecoderProvider.cpp | 9 +-- .../cocos/audio/android/AudioEngine-inl.cpp | 7 +- native/cocos/audio/android/AudioMixer.cpp | 16 ++--- .../audio/android/AudioMixerController.cpp | 6 +- .../audio/android/AudioPlayerProvider.cpp | 18 ++--- native/cocos/audio/android/AudioResampler.cpp | 9 +-- native/cocos/audio/android/PcmAudioPlayer.cpp | 3 +- native/cocos/audio/apple/AudioEngine-inl.mm | 13 ++-- native/cocos/audio/apple/AudioPlayer.mm | 8 +-- .../audio/oalsoft/AudioDecoderManager.cpp | 7 +- .../cocos/audio/oalsoft/AudioEngine-soft.cpp | 5 +- native/cocos/audio/oalsoft/AudioPlayer.cpp | 9 ++- native/cocos/audio/ohos/FsCallback.cpp | 7 +- native/cocos/base/CachedArray.h | 26 ++++---- native/cocos/base/Ptr.h | 8 +-- native/cocos/base/Scheduler.cpp | 5 +- native/cocos/base/StringPool.h | 3 +- native/cocos/base/ThreadPool.cpp | 11 ++-- native/cocos/base/Value.cpp | 32 ++++----- native/cocos/base/ZipUtils.cpp | 14 ++-- .../job-system-dummy/DummyJobGraph.cpp | 2 +- .../job-system-dummy/DummyJobGraph.h | 7 +- .../job-system-dummy/DummyJobSystem.h | 7 +- .../job-system-taskflow/TFJobSystem.h | 2 +- .../job-system/job-system-tbb/TBBJobSystem.h | 2 +- native/cocos/base/memory/Memory.h | 33 +++------- native/cocos/base/threading/MessageQueue.cpp | 6 +- native/cocos/base/threading/MessageQueue.h | 16 ++--- .../cocos/bindings/event/EventDispatcher.cpp | 2 +- .../cocos/bindings/jswrapper/MappingUtils.cpp | 3 +- .../cocos/bindings/jswrapper/PrivateObject.h | 15 +++-- native/cocos/bindings/jswrapper/Value.cpp | 2 +- native/cocos/bindings/jswrapper/config.cpp | 3 +- native/cocos/bindings/jswrapper/sm/Class.cpp | 2 +- native/cocos/bindings/jswrapper/sm/Object.cpp | 6 +- .../bindings/jswrapper/sm/ScriptEngine.cpp | 6 +- native/cocos/bindings/jswrapper/v8/Class.cpp | 2 +- native/cocos/bindings/jswrapper/v8/Object.cpp | 2 +- .../bindings/jswrapper/v8/ScriptEngine.cpp | 8 +-- .../bindings/manual/JavaScriptJavaBridge.cpp | 10 +-- .../bindings/manual/JavaScriptObjCBridge.mm | 4 +- .../bindings/manual/jsb_cocos_manual.cpp | 2 +- .../cocos/bindings/manual/jsb_conversions.h | 8 +-- .../bindings/manual/jsb_conversions_spec.cpp | 2 +- native/cocos/bindings/manual/jsb_global.cpp | 4 +- native/cocos/bindings/manual/jsb_global.h | 6 +- native/cocos/bindings/manual/jsb_helper.cpp | 7 +- native/cocos/bindings/manual/jsb_helper.h | 2 +- .../bindings/manual/jsb_scene_manual.cpp | 2 +- native/cocos/bindings/manual/jsb_socketio.cpp | 2 +- .../bindings/manual/jsb_spine_manual.cpp | 22 +++---- .../cocos/bindings/manual/jsb_websocket.cpp | 8 +-- .../bindings/manual/jsb_websocket_server.cpp | 4 +- .../bindings/manual/jsb_xmlhttprequest.cpp | 4 +- native/cocos/core/ArrayBuffer.h | 3 +- native/cocos/core/Root.cpp | 11 ++-- native/cocos/core/Root.h | 4 +- native/cocos/core/TypedArray.h | 6 +- .../core/animation/SkeletalAnimationUtils.cpp | 2 +- native/cocos/core/assets/BitmapFont.cpp | 4 +- native/cocos/core/assets/FreeTypeFont.cpp | 4 +- native/cocos/core/assets/Material.cpp | 2 +- native/cocos/core/assets/SceneAsset.cpp | 2 +- native/cocos/core/assets/Texture2D.cpp | 4 +- native/cocos/core/assets/TextureCube.cpp | 16 ++--- native/cocos/core/builtin/BuiltinResMgr.cpp | 62 ++++++++--------- native/cocos/core/geometry/AABB.h | 3 +- native/cocos/core/geometry/Curve.h | 8 +-- native/cocos/core/geometry/Frustum.h | 9 +-- native/cocos/core/geometry/Line.cpp | 7 +- native/cocos/core/geometry/Obb.cpp | 5 +- native/cocos/core/geometry/Plane.cpp | 7 +- native/cocos/core/geometry/Ray.cpp | 7 +- native/cocos/core/geometry/Sphere.cpp | 4 +- native/cocos/core/geometry/Spline.cpp | 5 +- native/cocos/core/geometry/Triangle.cpp | 7 +- native/cocos/core/scene-graph/Node.cpp | 2 +- .../core/scene-graph/NodeEventProcessor.h | 31 ++++----- native/cocos/core/scene-graph/Scene.cpp | 2 +- .../cocos/core/scene-graph/SceneGlobals.cpp | 10 +-- native/cocos/network/Downloader-curl.cpp | 3 +- native/cocos/network/Downloader-java.cpp | 3 +- native/cocos/network/Downloader.cpp | 8 +-- native/cocos/network/DownloaderImpl-apple.mm | 5 +- native/cocos/network/HttpClient-apple.mm | 12 ++-- native/cocos/network/HttpClient-java.cpp | 12 ++-- native/cocos/network/HttpClient.cpp | 12 ++-- native/cocos/network/SocketIO.cpp | 22 +++---- .../cocos/network/WebSocket-libwebsockets.cpp | 26 ++++---- native/cocos/network/WebSocket-okhttp.cpp | 5 +- native/cocos/network/WebSocketServer.cpp | 9 +-- .../cocos/physics/physx/PhysXEventManager.cpp | 4 +- .../cocos/physics/physx/PhysXEventManager.h | 3 +- .../cocos/physics/physx/PhysXSharedBody.cpp | 3 +- native/cocos/physics/physx/PhysXWorld.cpp | 5 +- native/cocos/physics/sdk/Joint.cpp | 3 +- native/cocos/physics/sdk/Shape.cpp | 3 +- native/cocos/platform/FileUtils.cpp | 4 +- .../platform/android/FileUtils-android.cpp | 5 +- .../cocos/platform/apple/FileUtils-apple.mm | 11 ++-- native/cocos/platform/apple/Reachability.cpp | 10 +-- .../canvas/CanvasRenderingContext2D.cpp | 2 +- .../cocos/platform/linux/FileUtils-linux.cpp | 3 +- native/cocos/platform/ohos/FileUtils-ohos.cpp | 16 ++--- native/cocos/platform/qnx/FileUtils-qnx.cpp | 3 +- .../cocos/platform/win32/FileUtils-win32.cpp | 20 +++--- native/cocos/platform/win32/Utils-win32.cpp | 7 +- .../CanvasRenderingContext2DDelegate.cpp | 2 +- .../cocos/platform/win32/modules/System.cpp | 5 +- native/cocos/profiler/DebugRenderer.cpp | 8 +-- native/cocos/profiler/Profiler.cpp | 6 +- native/cocos/renderer/GFXDeviceManager.h | 6 +- .../cocos/renderer/core/MaterialInstance.cpp | 2 +- native/cocos/renderer/core/ProgramLib.cpp | 2 +- .../cocos/renderer/frame-graph/FrameGraph.cpp | 6 +- .../cocos/renderer/frame-graph/FrameGraph.h | 6 +- .../renderer/frame-graph/ResourceAllocator.h | 4 +- .../renderer/gfx-agent/CommandBufferAgent.cpp | 7 +- .../cocos/renderer/gfx-agent/DeviceAgent.cpp | 61 +++++++++-------- .../renderer/gfx-agent/SwapchainAgent.cpp | 4 +- native/cocos/renderer/gfx-base/GFXDevice.h | 8 +-- .../cocos/renderer/gfx-empty/EmptyDevice.cpp | 28 ++++---- .../renderer/gfx-empty/EmptySwapchain.cpp | 4 +- .../gfx-gles-common/GLESCommandPool.h | 12 ++-- .../cocos/renderer/gfx-gles2/GLES2Buffer.cpp | 6 +- .../renderer/gfx-gles2/GLES2CommandBuffer.cpp | 6 +- .../renderer/gfx-gles2/GLES2DescriptorSet.cpp | 7 +- .../gfx-gles2/GLES2DescriptorSetLayout.cpp | 7 +- .../cocos/renderer/gfx-gles2/GLES2Device.cpp | 44 ++++++------- .../renderer/gfx-gles2/GLES2Framebuffer.cpp | 4 +- .../gfx-gles2/GLES2InputAssembler.cpp | 4 +- .../gfx-gles2/GLES2PipelineLayout.cpp | 2 +- .../renderer/gfx-gles2/GLES2PipelineState.cpp | 7 +- .../renderer/gfx-gles2/GLES2RenderPass.cpp | 4 +- .../cocos/renderer/gfx-gles2/GLES2Shader.cpp | 4 +- .../renderer/gfx-gles2/GLES2Swapchain.cpp | 6 +- .../cocos/renderer/gfx-gles2/GLES2Texture.cpp | 6 +- .../gfx-gles2/states/GLES2Sampler.cpp | 4 +- .../cocos/renderer/gfx-gles3/GLES3Buffer.cpp | 6 +- .../renderer/gfx-gles3/GLES3CommandBuffer.cpp | 6 +- .../renderer/gfx-gles3/GLES3DescriptorSet.cpp | 7 +- .../gfx-gles3/GLES3DescriptorSetLayout.cpp | 7 +- .../cocos/renderer/gfx-gles3/GLES3Device.cpp | 44 ++++++------- .../renderer/gfx-gles3/GLES3Framebuffer.cpp | 4 +- .../gfx-gles3/GLES3InputAssembler.cpp | 4 +- .../gfx-gles3/GLES3PipelineLayout.cpp | 7 +- .../renderer/gfx-gles3/GLES3PipelineState.cpp | 7 +- .../renderer/gfx-gles3/GLES3QueryPool.cpp | 4 +- .../renderer/gfx-gles3/GLES3RenderPass.cpp | 4 +- .../cocos/renderer/gfx-gles3/GLES3Shader.cpp | 4 +- .../renderer/gfx-gles3/GLES3Swapchain.cpp | 6 +- .../cocos/renderer/gfx-gles3/GLES3Texture.cpp | 17 ++--- .../gfx-gles3/states/GLES3GeneralBarrier.cpp | 2 +- .../gfx-gles3/states/GLES3Sampler.cpp | 7 +- native/cocos/renderer/gfx-metal/MTLBuffer.mm | 2 +- .../renderer/gfx-metal/MTLCommandBuffer.mm | 9 +-- .../renderer/gfx-metal/MTLDescriptorSet.mm | 2 +- .../gfx-metal/MTLDescriptorSetLayout.mm | 2 +- native/cocos/renderer/gfx-metal/MTLDevice.mm | 38 +++++------ .../renderer/gfx-metal/MTLInputAssembler.mm | 2 +- .../renderer/gfx-metal/MTLPipelineLayout.mm | 2 +- .../renderer/gfx-metal/MTLPipelineState.mm | 4 +- .../cocos/renderer/gfx-metal/MTLQueryPool.mm | 4 +- native/cocos/renderer/gfx-metal/MTLQueue.mm | 2 +- native/cocos/renderer/gfx-metal/MTLSampler.mm | 2 +- native/cocos/renderer/gfx-metal/MTLShader.mm | 2 +- .../cocos/renderer/gfx-metal/MTLSwapchain.mm | 6 +- native/cocos/renderer/gfx-metal/MTLTexture.mm | 2 +- native/cocos/renderer/gfx-metal/MTLUtils.mm | 6 +- .../gfx-validator/DeviceValidator.cpp | 40 +++++------ .../gfx-validator/SwapchainValidator.cpp | 4 +- native/cocos/renderer/gfx-vulkan/VKBuffer.cpp | 10 +-- .../renderer/gfx-vulkan/VKCommandBuffer.cpp | 7 +- .../cocos/renderer/gfx-vulkan/VKCommands.cpp | 16 ++--- .../renderer/gfx-vulkan/VKDescriptorSet.cpp | 4 +- .../gfx-vulkan/VKDescriptorSetLayout.cpp | 2 +- native/cocos/renderer/gfx-vulkan/VKDevice.cpp | 66 +++++++++---------- .../renderer/gfx-vulkan/VKFramebuffer.cpp | 4 +- .../renderer/gfx-vulkan/VKInputAssembler.cpp | 4 +- .../renderer/gfx-vulkan/VKPipelineLayout.cpp | 2 +- .../renderer/gfx-vulkan/VKPipelineState.cpp | 2 +- .../cocos/renderer/gfx-vulkan/VKQueryPool.cpp | 2 +- native/cocos/renderer/gfx-vulkan/VKQueue.cpp | 4 +- .../renderer/gfx-vulkan/VKRenderPass.cpp | 2 +- native/cocos/renderer/gfx-vulkan/VKShader.cpp | 2 +- .../cocos/renderer/gfx-vulkan/VKSwapchain.cpp | 6 +- .../cocos/renderer/gfx-vulkan/VKTexture.cpp | 14 ++-- .../gfx-vulkan/states/VKGeneralBarrier.cpp | 2 +- .../renderer/gfx-vulkan/states/VKSampler.cpp | 2 +- .../gfx-vulkan/states/VKTextureBarrier.cpp | 2 +- native/cocos/renderer/gfx-wgpu/WGPUBuffer.cpp | 10 +-- .../renderer/gfx-wgpu/WGPUCommandBuffer.cpp | 6 +- .../renderer/gfx-wgpu/WGPUDescriptorSet.cpp | 4 +- .../gfx-wgpu/WGPUDescriptorSetLayout.cpp | 4 +- native/cocos/renderer/gfx-wgpu/WGPUDevice.cpp | 40 +++++------ .../renderer/gfx-wgpu/WGPUInputAssembler.cpp | 2 +- .../renderer/gfx-wgpu/WGPUPipelineLayout.cpp | 4 +- .../renderer/gfx-wgpu/WGPUPipelineState.cpp | 4 +- .../cocos/renderer/gfx-wgpu/WGPUQueryPool.cpp | 4 +- native/cocos/renderer/gfx-wgpu/WGPUQueue.cpp | 4 +- .../renderer/gfx-wgpu/WGPURenderPass.cpp | 6 +- .../cocos/renderer/gfx-wgpu/WGPUSampler.cpp | 2 +- native/cocos/renderer/gfx-wgpu/WGPUShader.cpp | 4 +- .../cocos/renderer/gfx-wgpu/WGPUSwapchain.cpp | 12 ++-- .../cocos/renderer/gfx-wgpu/WGPUTexture.cpp | 8 +-- .../cocos/renderer/pipeline/BatchedBuffer.cpp | 2 +- .../renderer/pipeline/GeometryRenderer.cpp | 2 +- .../pipeline/GlobalDescriptorSetManager.cpp | 2 +- .../renderer/pipeline/InstancedBuffer.cpp | 2 +- .../renderer/pipeline/PipelineSceneData.cpp | 16 ++--- .../renderer/pipeline/PlanarShadowQueue.cpp | 2 +- .../pipeline/RenderAdditiveLightQueue.cpp | 4 +- .../renderer/pipeline/RenderPipeline.cpp | 4 +- .../pipeline/ShadowMapBatchedQueue.cpp | 4 +- .../renderer/pipeline/custom/GraphTypes.h | 11 ++-- .../pipeline/custom/NativePipelineImpl.cpp | 2 +- .../pipeline/custom/RenderInterfaceImpl.cpp | 2 +- .../pipeline/deferred/DeferredPipeline.cpp | 8 +-- .../deferred/DeferredPipelineSceneData.cpp | 8 +-- .../pipeline/deferred/GbufferStage.cpp | 8 +-- .../pipeline/deferred/LightingStage.cpp | 8 +-- .../renderer/pipeline/deferred/MainFlow.cpp | 8 +-- .../pipeline/deferred/PostProcessStage.cpp | 4 +- .../renderer/pipeline/forward/ForwardFlow.cpp | 2 +- .../pipeline/forward/ForwardPipeline.cpp | 6 +- .../pipeline/forward/ForwardStage.cpp | 12 ++-- .../renderer/pipeline/shadow/ShadowFlow.cpp | 8 +-- .../renderer/pipeline/shadow/ShadowStage.cpp | 2 +- native/cocos/scene/Camera.cpp | 4 +- native/cocos/scene/Model.cpp | 6 +- native/cocos/scene/Octree.cpp | 6 +- native/cocos/scene/Pass.cpp | 6 +- native/cocos/scene/Shadow.cpp | 4 +- native/cocos/scene/Skybox.cpp | 4 +- native/cocos/scene/SpotLight.cpp | 4 +- native/cocos/ui/webview/WebView-inl.h | 5 +- package-lock.json | 6 +- 245 files changed, 958 insertions(+), 968 deletions(-) diff --git a/native/cocos/3d/assets/Mesh.cpp b/native/cocos/3d/assets/Mesh.cpp index e343ba38d5..27d0698a30 100644 --- a/native/cocos/3d/assets/Mesh.cpp +++ b/native/cocos/3d/assets/Mesh.cpp @@ -262,7 +262,7 @@ void Mesh::initialize() { } } - auto *subMesh = new RenderingSubMesh(subVBs, attributes, primitive.primitiveMode, indexBuffer); + auto *subMesh = ccnew RenderingSubMesh(subVBs, attributes, primitive.primitiveMode, indexBuffer); subMesh->setDrawInfo(gfx::DrawInfo()); subMesh->setMesh(this); subMesh->setSubMeshIdx(static_cast(i)); @@ -313,7 +313,7 @@ void Mesh::initialize() { const uint8_t *ib = buffer.buffer()->getData() + idxView.offset; - // ib = new (getIndexStrideCtor(idxView.stride))(buffer, idxView.offset, idxView.count); + // ib = ccnew (getIndexStrideCtor(idxView.stride))(buffer, idxView.offset, idxView.count); if (idxView.stride != dstStride) { //cjh need in c++? ib = getIndexStrideCtor(dstStride).from(ib); } @@ -338,7 +338,7 @@ void Mesh::initialize() { } } - auto *subMesh = new RenderingSubMesh(vbReference, gfxAttributes, prim.primitiveMode, indexBuffer); + auto *subMesh = ccnew RenderingSubMesh(vbReference, gfxAttributes, prim.primitiveMode, indexBuffer); subMesh->setMesh(this); subMesh->setSubMeshIdx(static_cast(i)); @@ -385,7 +385,7 @@ Mesh::BoneSpaceBounds Mesh::getBoneSpaceBounds(Skeleton *skeleton) { const auto & bindposes = skeleton->getBindposes(); valid.reserve(bindposes.size()); for (size_t i = 0; i < bindposes.size(); i++) { - bounds.emplace_back(new geometry::AABB{ + bounds.emplace_back(ccnew geometry::AABB{ std::numeric_limits::infinity(), std::numeric_limits::infinity(), std::numeric_limits::infinity(), -std::numeric_limits::infinity(), -std::numeric_limits::infinity(), -std::numeric_limits::infinity()}); valid.emplace_back(false); @@ -542,7 +542,7 @@ bool Mesh::merge(Mesh *mesh, const Mat4 *worldMatrix /* = nullptr */, bool valid vertStride = bundle.view.stride; vertCount = bundle.view.count + dstBundle.view.count; - auto * vb = new ArrayBuffer(vertCount * vertStride); + auto * vb = ccnew ArrayBuffer(vertCount * vertStride); Uint8Array vbView(vb); Uint8Array srcVBView = _data.subarray(srcOffset, srcOffset + bundle.view.length); @@ -633,7 +633,7 @@ bool Mesh::merge(Mesh *mesh, const Mat4 *worldMatrix /* = nullptr */, bool valid idxStride = 4; } - auto *ib = new ArrayBuffer(idxCount * idxStride); + auto *ib = ccnew ArrayBuffer(idxCount * idxStride); TypedArray ibView; TypedArray srcIBView; diff --git a/native/cocos/3d/assets/Morph.cpp b/native/cocos/3d/assets/Morph.cpp index d54501052a..7d2e4d929d 100644 --- a/native/cocos/3d/assets/Morph.cpp +++ b/native/cocos/3d/assets/Morph.cpp @@ -29,7 +29,7 @@ namespace cc { MorphRendering *createMorphRendering(Mesh *mesh, gfx::Device *gfxDevice) { - return new StdMorphRendering(mesh, gfxDevice); + return ccnew StdMorphRendering(mesh, gfxDevice); } } // namespace cc diff --git a/native/cocos/3d/assets/MorphRendering.cpp b/native/cocos/3d/assets/MorphRendering.cpp index 4c0ce11be9..e7fa4ebfb4 100644 --- a/native/cocos/3d/assets/MorphRendering.cpp +++ b/native/cocos/3d/assets/MorphRendering.cpp @@ -131,14 +131,14 @@ public: } void initialize(gfx::Device *gfxDevice, uint32_t width, uint32_t height, uint32_t pixelBytes, bool /*useFloat32Array*/, PixelFormat pixelFormat) { - _arrayBuffer = new ArrayBuffer(width * height * pixelBytes); + _arrayBuffer = ccnew ArrayBuffer(width * height * pixelBytes); _valueView = Float32Array(_arrayBuffer); - auto * imageAsset = new ImageAsset(); + auto * imageAsset = ccnew ImageAsset(); IMemoryImageSource source{_arrayBuffer, false, width, height, pixelFormat}; imageAsset->setNativeAsset(source); - _textureAsset = new Texture2D(); + _textureAsset = ccnew Texture2D(); _textureAsset->setFilters(Texture2D::Filter::NEAREST, Texture2D::Filter::NEAREST); _textureAsset->setMipFilter(Texture2D::Filter::NONE); _textureAsset->setWrapMode(Texture2D::WrapMode::CLAMP_TO_EDGE, Texture2D::WrapMode::CLAMP_TO_EDGE, Texture2D::WrapMode::CLAMP_TO_EDGE); @@ -260,7 +260,7 @@ Vec4TextureFactory createVec4TextureFactory(gfx::Device *gfxDevice, uint32_t vec ret.width = width; ret.height = height; ret.create = [=]() -> MorphTexture * { - auto *texture = new MorphTexture(); // texture will be held by IntrusivePtr in GpuMorphAttribute + auto *texture = ccnew MorphTexture(); // texture will be held by IntrusivePtr in GpuMorphAttribute texture->initialize(gfxDevice, width, height, pixelBytes, useFloat32Array, pixelFormat); return texture; }; @@ -275,7 +275,7 @@ class MorphUniforms final : public RefCounted { public: MorphUniforms(gfx::Device *gfxDevice, uint32_t targetCount) { _targetCount = targetCount; - _localBuffer = new DataView(new ArrayBuffer(pipeline::UBOMorph::SIZE)); + _localBuffer = ccnew DataView(ccnew ArrayBuffer(pipeline::UBOMorph::SIZE)); _remoteBuffer = gfxDevice->createBuffer(gfx::BufferInfo{ gfx::BufferUsageBit::UNIFORM | gfx::BufferUsageBit::TRANSFER_DST, @@ -358,7 +358,7 @@ class CpuComputingRenderingInstance final : public SubMeshMorphRenderingInstance public: explicit CpuComputingRenderingInstance(CpuComputing *owner, uint32_t nVertices, gfx::Device *gfxDevice) { _owner = owner; //NOTE: release by mesh`s destroy, it`ll call current instance`s destroy method - _morphUniforms = new MorphUniforms(gfxDevice, 0 /* TODO? */); + _morphUniforms = ccnew MorphUniforms(gfxDevice, 0 /* TODO? */); auto vec4TextureFactory = createVec4TextureFactory(gfxDevice, nVertices); _morphUniforms->setMorphTextureInfo(static_cast(vec4TextureFactory.width), static_cast(vec4TextureFactory.height)); @@ -445,7 +445,7 @@ class GpuComputingRenderingInstance final : public SubMeshMorphRenderingInstance public: explicit GpuComputingRenderingInstance(GpuComputing *owner, gfx::Device *gfxDevice) { _owner = owner; - _morphUniforms = new MorphUniforms(gfxDevice, static_cast(_owner->_subMeshMorph->targets.size())); + _morphUniforms = ccnew MorphUniforms(gfxDevice, static_cast(_owner->_subMeshMorph->targets.size())); _morphUniforms->setMorphTextureInfo(static_cast(_owner->_textureWidth), static_cast(_owner->_textureHeight)); _morphUniforms->setVerticesCount(_owner->_verticesCount); _morphUniforms->commit(); @@ -522,7 +522,7 @@ CpuComputing::CpuComputing(Mesh *mesh, uint32_t subMeshIndex, const Morph *morph } SubMeshMorphRenderingInstance *CpuComputing::createInstance() { - return new CpuComputingRenderingInstance( + return ccnew CpuComputingRenderingInstance( this, _attributes[0].targets[0].displacements.length() / 3, _gfxDevice); @@ -587,7 +587,7 @@ GpuComputing::GpuComputing(Mesh *mesh, uint32_t subMeshIndex, const Morph *morph } SubMeshMorphRenderingInstance *GpuComputing::createInstance() { - return new GpuComputingRenderingInstance(this, _gfxDevice); + return ccnew GpuComputingRenderingInstance(this, _gfxDevice); } void GpuComputing::destroy() { @@ -703,13 +703,13 @@ StdMorphRendering::StdMorphRendering(Mesh *mesh, gfx::Device *gfxDevice) { const auto &subMeshMorph = subMeshMorphHolder.value(); if (PREFER_CPU_COMPUTING || subMeshMorph.targets.size() > pipeline::UBOMorph::MAX_MORPH_TARGET_COUNT) { - _subMeshRenderings[iSubMesh] = new CpuComputing( + _subMeshRenderings[iSubMesh] = ccnew CpuComputing( _mesh, static_cast(iSubMesh), &morph, gfxDevice); } else { - _subMeshRenderings[iSubMesh] = new GpuComputing( + _subMeshRenderings[iSubMesh] = ccnew GpuComputing( _mesh, static_cast(iSubMesh), &morph, @@ -721,7 +721,7 @@ StdMorphRendering::StdMorphRendering(Mesh *mesh, gfx::Device *gfxDevice) { StdMorphRendering::~StdMorphRendering() = default; MorphRenderingInstance *StdMorphRendering::createInstance() { - auto *ret = new StdMorphRenderingInstance(this); + auto *ret = ccnew StdMorphRenderingInstance(this); return ret; } diff --git a/native/cocos/3d/misc/CreateMesh.cpp b/native/cocos/3d/misc/CreateMesh.cpp index 406b9a7a20..06f0743152 100644 --- a/native/cocos/3d/misc/CreateMesh.cpp +++ b/native/cocos/3d/misc/CreateMesh.cpp @@ -20,7 +20,7 @@ gfx::AttributeList defAttrs = { Mesh *MeshUtils::createMesh(const IGeometry &geometry, Mesh *out /*= nullptr*/, const ICreateMeshOptions &options /*= {}*/) { if (!out) { - out = new Mesh(); + out = ccnew Mesh(); } out->reset(createMeshInfo(geometry, options)); @@ -167,7 +167,7 @@ Mesh::ICreateInfo MeshUtils::createMeshInfo(const IGeometry &geometry, const ICr BufferBlob bufferBlob; // Fill vertex buffer. - auto * vertexBuffer = new ArrayBuffer(vertCount * stride); + auto * vertexBuffer = ccnew ArrayBuffer(vertCount * stride); DataView vertexBufferView(vertexBuffer); for (const auto &channel : channels) { writeBuffer(vertexBufferView, channel.data, channel.attribute.format, channel.offset, stride); @@ -192,7 +192,7 @@ Mesh::ICreateInfo MeshUtils::createMeshInfo(const IGeometry &geometry, const ICr if (geometry.indices.has_value()) { const ccstd::vector &indices = geometry.indices.value(); idxCount = static_cast(indices.size()); - indexBuffer = new ArrayBuffer(idxStride * idxCount); + indexBuffer = ccnew ArrayBuffer(idxStride * idxCount); DataView indexBufferView(indexBuffer); writeBuffer(indexBufferView, indices, gfx::Format::R16UI); } @@ -261,7 +261,7 @@ static inline uint32_t getPadding(uint32_t length, uint32_t align) { Mesh *MeshUtils::createDynamicMesh(index_t primitiveIndex, const IDynamicGeometry &geometry, Mesh *out /*= nullptr*/, const ICreateDynamicMeshOptions &options /*= {}*/) { if (!out) { - out = new Mesh(); + out = ccnew Mesh(); } out->reset(MeshUtils::createDynamicMeshInfo(geometry, options)); diff --git a/native/cocos/3d/models/SkinningModel.cpp b/native/cocos/3d/models/SkinningModel.cpp index c9c77b9708..f5858b7fa0 100644 --- a/native/cocos/3d/models/SkinningModel.cpp +++ b/native/cocos/3d/models/SkinningModel.cpp @@ -221,7 +221,7 @@ void SkinningModel::ensureEnoughBuffers(index_t count) { } if (_dataArray[i] == nullptr) { - _dataArray[i] = new ccstd::array; + _dataArray[i] = ccnew ccstd::array; } } } diff --git a/native/cocos/3d/skeletal-animation/SkeletalAnimationUtils.cpp b/native/cocos/3d/skeletal-animation/SkeletalAnimationUtils.cpp index 55ecf34d10..7db20d731c 100644 --- a/native/cocos/3d/skeletal-animation/SkeletalAnimationUtils.cpp +++ b/native/cocos/3d/skeletal-animation/SkeletalAnimationUtils.cpp @@ -140,12 +140,12 @@ JointTexturePool::JointTexturePool(gfx::Device *device) { const auto &format = selectJointsMediumFormat(_device); _formatSize = gfx::GFX_FORMAT_INFOS[static_cast(format)].size; _pixelsPerJoint = 48 / _formatSize; - _pool = new TextureBufferPool(device); + _pool = ccnew TextureBufferPool(device); ITextureBufferPoolInfo poolInfo; poolInfo.format = format; poolInfo.roundUpFn = roundUpType{roundUpTextureSize}; _pool->initialize(poolInfo); - _customPool = new TextureBufferPool(device); + _customPool = ccnew TextureBufferPool(device); ITextureBufferPoolInfo customPoolInfo; customPoolInfo.format = format; customPoolInfo.roundUpFn = roundUpType{roundUpTextureSize}; @@ -409,7 +409,7 @@ void JointTexturePool::releaseSkeleton(Skeleton *skeleton) { // animPath = animPath.substring(0, idx); // source = clipData.joints[animPath]; // if (animNode) { -// if (!downstream) { downstream = new Mat4(); } +// if (!downstream) { downstream = ccnew Mat4(); } // Mat4.fromRTS(m4_1, animNode.rotation, animNode.position, animNode.scale); // Mat4.multiply(downstream, m4_1, downstream); // animNode = animNode.parent; @@ -446,7 +446,7 @@ void JointTexturePool::releaseSkeleton(Skeleton *skeleton) { // for (let t = 0; t < jointCount; t++) { // if (joints[t] === correctionPath) { // bindposeIdx = t; -// bindposeCorrection = new Mat4(); +// bindposeCorrection = ccnew Mat4(); // Mat4.multiply(bindposeCorrection, bindposes[t], skeleton.inverseBindposes[j]); // break; // } diff --git a/native/cocos/3d/skeletal-animation/SkeletalAnimationUtils.h b/native/cocos/3d/skeletal-animation/SkeletalAnimationUtils.h index 3a04336b4e..3e83830ad9 100644 --- a/native/cocos/3d/skeletal-animation/SkeletalAnimationUtils.h +++ b/native/cocos/3d/skeletal-animation/SkeletalAnimationUtils.h @@ -70,7 +70,7 @@ public: cc::optional> animInfos; static IJointTextureHandle *createJoinTextureHandle() { - return new IJointTextureHandle(); + return ccnew IJointTextureHandle(); } private: diff --git a/native/cocos/audio/AudioEngine.cpp b/native/cocos/audio/AudioEngine.cpp index 08d86be32b..6e12b5b0c7 100644 --- a/native/cocos/audio/AudioEngine.cpp +++ b/native/cocos/audio/AudioEngine.cpp @@ -30,6 +30,7 @@ #include #include "base/Log.h" #include "base/Utils.h" +#include "base/memory/Memory.h" #include "base/std/container/queue.h" #include "platform/FileUtils.h" @@ -169,7 +170,7 @@ void AudioEngine::end() { bool AudioEngine::lazyInit() { if (sAudioEngineImpl == nullptr) { - sAudioEngineImpl = new (std::nothrow) AudioEngineImpl(); + sAudioEngineImpl = ccnew AudioEngineImpl(); if (!sAudioEngineImpl || !sAudioEngineImpl->init()) { delete sAudioEngineImpl; sAudioEngineImpl = nullptr; @@ -181,7 +182,7 @@ bool AudioEngine::lazyInit() { #if (CC_PLATFORM != CC_PLATFORM_ANDROID) if (sAudioEngineImpl && sThreadPool == nullptr) { - sThreadPool = new (std::nothrow) AudioEngineThreadPool(); + sThreadPool = ccnew AudioEngineThreadPool(); } #endif @@ -530,7 +531,7 @@ AudioProfile *AudioEngine::getProfile(int audioID) { AudioProfile *AudioEngine::getDefaultProfile() { if (sDefaultProfileHelper == nullptr) { - sDefaultProfileHelper = new (std::nothrow) ProfileHelper(); + sDefaultProfileHelper = ccnew ProfileHelper(); } return &sDefaultProfileHelper->profile; diff --git a/native/cocos/audio/android/AudioDecoderProvider.cpp b/native/cocos/audio/android/AudioDecoderProvider.cpp index 2daab343e8..58d11124c4 100644 --- a/native/cocos/audio/android/AudioDecoderProvider.cpp +++ b/native/cocos/audio/android/AudioDecoderProvider.cpp @@ -30,6 +30,7 @@ #include "audio/android/AudioDecoderOgg.h" #include "audio/android/AudioDecoderSLES.h" #include "audio/android/AudioDecoderWav.h" +#include "base/memory/Memory.h" #include "platform/FileUtils.h" namespace cc { @@ -39,25 +40,25 @@ AudioDecoder *AudioDecoderProvider::createAudioDecoder(SLEngineItf engineItf, co ccstd::string extension = FileUtils::getInstance()->getFileExtension(url); ALOGV("url:%s, extension:%s", url.c_str(), extension.c_str()); if (extension == ".ogg") { - decoder = new AudioDecoderOgg(); + decoder = ccnew AudioDecoderOgg(); if (!decoder->init(url, sampleRate)) { delete decoder; decoder = nullptr; } } else if (extension == ".mp3") { - decoder = new AudioDecoderMp3(); + decoder = ccnew AudioDecoderMp3(); if (!decoder->init(url, sampleRate)) { delete decoder; decoder = nullptr; } } else if (extension == ".wav") { - decoder = new AudioDecoderWav(); + decoder = ccnew AudioDecoderWav(); if (!decoder->init(url, sampleRate)) { delete decoder; decoder = nullptr; } } else { - auto slesDecoder = new AudioDecoderSLES(); + auto slesDecoder = ccnew AudioDecoderSLES(); if (slesDecoder->init(engineItf, url, bufferSizeInFrames, sampleRate, fdGetterCallback)) { decoder = slesDecoder; } else { diff --git a/native/cocos/audio/android/AudioEngine-inl.cpp b/native/cocos/audio/android/AudioEngine-inl.cpp index c3dc88cecd..0b09b31684 100644 --- a/native/cocos/audio/android/AudioEngine-inl.cpp +++ b/native/cocos/audio/android/AudioEngine-inl.cpp @@ -40,6 +40,7 @@ #include "base/Log.h" #include "base/Scheduler.h" #include "base/UTF8.h" +#include "base/memory/Memory.h" #include "platform/android/FileUtils-android.h" #include "platform/java/jni/JniHelper.h" #include "platform/java/jni/JniImp.h" @@ -50,8 +51,8 @@ #include "audio/android/UrlAudioPlayer.h" #include "audio/android/cutils/log.h" -#include "cocos/bindings/event/CustomEventTypes.h" -#include "cocos/bindings/event/EventDispatcher.h" +#include "bindings/event/CustomEventTypes.h" +#include "bindings/event/EventDispatcher.h" using namespace cc; //NOLINT @@ -183,7 +184,7 @@ bool AudioEngineImpl::init() { break; } - _audioPlayerProvider = new AudioPlayerProvider(_engineEngine, _outputMixObject, outputSampleRate, bufferSizeInFrames, fdGetter, &gCallerThreadUtils); + _audioPlayerProvider = ccnew AudioPlayerProvider(_engineEngine, _outputMixObject, outputSampleRate, bufferSizeInFrames, fdGetter, &gCallerThreadUtils); ret = true; } while (false); diff --git a/native/cocos/audio/android/AudioMixer.cpp b/native/cocos/audio/android/AudioMixer.cpp index 39cb8e073c..c784f91d34 100644 --- a/native/cocos/audio/android/AudioMixer.cpp +++ b/native/cocos/audio/android/AudioMixer.cpp @@ -26,9 +26,9 @@ #include "audio/android/audio.h" #include "audio/android/audio_utils/include/audio_utils/primitives.h" - #include "audio/android/AudioMixerOps.h" #include "audio/android/AudioMixer.h" +#include "base/memory/Memory.h" // The FCC_2 macro refers to the Fixed Channel Count of 2 for the legacy integer mixer. #ifndef FCC_2 @@ -316,7 +316,7 @@ status_t AudioMixer::track_t::prepareForDownmix() { //cjh if (audio_channel_mask_get_representation(channelMask) // == AUDIO_CHANNEL_REPRESENTATION_POSITION // && DownmixerBufferProvider::isMultichannelCapable()) { - // DownmixerBufferProvider* pDbp = new DownmixerBufferProvider(channelMask, + // DownmixerBufferProvider* pDbp = ccnew DownmixerBufferProvider(channelMask, // mMixerChannelMask, // AUDIO_FORMAT_PCM_16_BIT /* REFINE: use mMixerInFormat, now only PCM 16 */, // sampleRate, sessionId, kCopyBufferFrameCount); @@ -331,7 +331,7 @@ status_t AudioMixer::track_t::prepareForDownmix() { // } // // // Effect downmixer does not accept the channel conversion. Let's use our remixer. - // RemixBufferProvider* pRbp = new RemixBufferProvider(channelMask, + // RemixBufferProvider* pRbp = ccnew RemixBufferProvider(channelMask, // mMixerChannelMask, mMixerInFormat, kCopyBufferFrameCount); // // Remix always finds a conversion whereas Downmixer effect above may fail. // downmixerBufferProvider = pRbp; @@ -367,7 +367,7 @@ status_t AudioMixer::track_t::prepareForReformat() { : mMixerInFormat; bool requiresReconfigure = false; //cjh if (mFormat != targetFormat) { - // mReformatBufferProvider = new ReformatBufferProvider( + // mReformatBufferProvider = ccnew ReformatBufferProvider( // audio_channel_count_from_out_mask(channelMask), // mFormat, // targetFormat, @@ -375,7 +375,7 @@ status_t AudioMixer::track_t::prepareForReformat() { // requiresReconfigure = true; // } // if (targetFormat != mMixerInFormat) { - // mPostDownmixReformatBufferProvider = new ReformatBufferProvider( + // mPostDownmixReformatBufferProvider = ccnew ReformatBufferProvider( // audio_channel_count_from_out_mask(mMixerChannelMask), // targetFormat, // mMixerInFormat, @@ -785,7 +785,7 @@ bool AudioMixer::track_t::setPlaybackRate(const AudioPlaybackRate &playbackRate) // // but if none exists, it is the channel count (1 for mono). // const int timestretchChannelCount = downmixerBufferProvider != NULL // ? mMixerChannelCount : channelCount; - // mTimestretchBufferProvider = new TimestretchBufferProvider(timestretchChannelCount, + // mTimestretchBufferProvider = ccnew TimestretchBufferProvider(timestretchChannelCount, // mMixerInFormat, sampleRate, playbackRate); // reconfigureBufferProviders(); // } else { @@ -974,10 +974,10 @@ void AudioMixer::process__validate(state_t *state, int64_t pts) { if (countActiveTracks > 0) { if (resampling) { if (!state->outputTemp) { - state->outputTemp = new int32_t[MAX_NUM_CHANNELS * state->frameCount]; + state->outputTemp = ccnew int32_t[MAX_NUM_CHANNELS * state->frameCount]; } if (!state->resampleTemp) { - state->resampleTemp = new int32_t[MAX_NUM_CHANNELS * state->frameCount]; + state->resampleTemp = ccnew int32_t[MAX_NUM_CHANNELS * state->frameCount]; } state->hook = process__genericResampling; } else { diff --git a/native/cocos/audio/android/AudioMixerController.cpp b/native/cocos/audio/android/AudioMixerController.cpp index 52b337b9a8..64b61a74db 100644 --- a/native/cocos/audio/android/AudioMixerController.cpp +++ b/native/cocos/audio/android/AudioMixerController.cpp @@ -25,12 +25,12 @@ THE SOFTWARE. #define LOG_TAG "AudioMixerController" +#include #include "audio/android/AudioMixerController.h" #include "audio/android/AudioMixer.h" #include "audio/android/OpenSLHelper.h" #include "audio/android/Track.h" - -#include +#include "base/memory/Memory.h" namespace cc { @@ -57,7 +57,7 @@ AudioMixerController::~AudioMixerController() { } bool AudioMixerController::init() { - _mixer = new (std::nothrow) AudioMixer(_bufferSizeInFrames, _sampleRate); + _mixer = ccnew AudioMixer(_bufferSizeInFrames, _sampleRate); return _mixer != nullptr; } diff --git a/native/cocos/audio/android/AudioPlayerProvider.cpp b/native/cocos/audio/android/AudioPlayerProvider.cpp index c4295b7f91..50439fb953 100644 --- a/native/cocos/audio/android/AudioPlayerProvider.cpp +++ b/native/cocos/audio/android/AudioPlayerProvider.cpp @@ -25,6 +25,10 @@ THE SOFTWARE. #define LOG_TAG "AudioPlayerProvider" +#include +#include // for std::find_if +#include +#include #include "audio/android/AudioPlayerProvider.h" #include "audio/android/AudioDecoder.h" #include "audio/android/AudioDecoderProvider.h" @@ -34,13 +38,9 @@ THE SOFTWARE. #include "audio/android/PcmAudioService.h" #include "audio/android/UrlAudioPlayer.h" #include "audio/android/utils/Utils.h" +#include "base/memory/Memory.h" #include "base/ThreadPool.h" -#include -#include // for std::find_if -#include -#include - namespace cc { static int getSystemAPILevel() { @@ -77,9 +77,9 @@ AudioPlayerProvider::AudioPlayerProvider(SLEngineItf engineItf, SLObjectItf outp : _engineItf(engineItf), _outputMixObject(outputMixObject), _deviceSampleRate(deviceSampleRate), _bufferSizeInFrames(bufferSizeInFrames), _fdGetterCallback(fdGetterCallback), _callerThreadUtils(callerThreadUtils), _pcmAudioService(nullptr), _mixController(nullptr), _threadPool(LegacyThreadPool::newCachedThreadPool(1, 8, 5, 2, 2)) { ALOGI("deviceSampleRate: %d, bufferSizeInFrames: %d", _deviceSampleRate, _bufferSizeInFrames); if (getSystemAPILevel() >= 17) { - _mixController = new (std::nothrow) AudioMixerController(_bufferSizeInFrames, _deviceSampleRate, 2); + _mixController = ccnew AudioMixerController(_bufferSizeInFrames, _deviceSampleRate, 2); _mixController->init(); - _pcmAudioService = new (std::nothrow) PcmAudioService(engineItf, outputMixObject); + _pcmAudioService = ccnew PcmAudioService(engineItf, outputMixObject); _pcmAudioService->init(_mixController, 2, deviceSampleRate, bufferSizeInFrames * 2); } @@ -400,7 +400,7 @@ PcmAudioPlayer *AudioPlayerProvider::obtainPcmAudioPlayer(const ccstd::string &u const PcmData & pcmData) { PcmAudioPlayer *pcmPlayer = nullptr; if (pcmData.isValid()) { - pcmPlayer = new (std::nothrow) PcmAudioPlayer(_mixController, _callerThreadUtils); + pcmPlayer = ccnew PcmAudioPlayer(_mixController, _callerThreadUtils); if (pcmPlayer != nullptr) { pcmPlayer->prepare(url, pcmData); } @@ -418,7 +418,7 @@ UrlAudioPlayer *AudioPlayerProvider::createUrlAudioPlayer( } SLuint32 locatorType = info.assetFd->getFd() > 0 ? SL_DATALOCATOR_ANDROIDFD : SL_DATALOCATOR_URI; - auto urlPlayer = new (std::nothrow) UrlAudioPlayer(_engineItf, _outputMixObject, _callerThreadUtils); + auto urlPlayer = ccnew UrlAudioPlayer(_engineItf, _outputMixObject, _callerThreadUtils); bool ret = urlPlayer->prepare(info.url, locatorType, info.assetFd, info.start, info.length); if (!ret) { SL_SAFE_DELETE(urlPlayer); diff --git a/native/cocos/audio/android/AudioResampler.cpp b/native/cocos/audio/android/AudioResampler.cpp index 3b6a84e88d..7165ca043f 100644 --- a/native/cocos/audio/android/AudioResampler.cpp +++ b/native/cocos/audio/android/AudioResampler.cpp @@ -29,6 +29,7 @@ #include "audio/android/AudioResampler.h" //#include "audio/android/AudioResamplerSinc.h" #include "audio/android/AudioResamplerCubic.h" +#include "base/memory/Memory.h" //#include "AudioResamplerDyn.h" @@ -209,25 +210,25 @@ AudioResampler *AudioResampler::create(audio_format_t format, int inChannelCount case LOW_QUALITY: ALOGV("Create linear Resampler"); LOG_ALWAYS_FATAL_IF(format != AUDIO_FORMAT_PCM_16_BIT, "invalid pcm format"); - resampler = new (std::nothrow) AudioResamplerOrder1(inChannelCount, sampleRate); + resampler = ccnew AudioResamplerOrder1(inChannelCount, sampleRate); break; case MED_QUALITY: ALOGV("Create cubic Resampler"); LOG_ALWAYS_FATAL_IF(format != AUDIO_FORMAT_PCM_16_BIT, "invalid pcm format"); - resampler = new (std::nothrow) AudioResamplerCubic(inChannelCount, sampleRate); + resampler = ccnew AudioResamplerCubic(inChannelCount, sampleRate); break; case HIGH_QUALITY: ALOGV("Create HIGH_QUALITY sinc Resampler"); LOG_ALWAYS_FATAL_IF(format != AUDIO_FORMAT_PCM_16_BIT, "invalid pcm format"); ALOG_ASSERT(false, "HIGH_QUALITY isn't supported"); // Cocos2d-x only uses MED_QUALITY, so we could remove Sinc relative files - // resampler = new (std::nothrow) AudioResamplerSinc(inChannelCount, sampleRate); + // resampler = ccnew AudioResamplerSinc(inChannelCount, sampleRate); break; case VERY_HIGH_QUALITY: ALOGV("Create VERY_HIGH_QUALITY sinc Resampler = %d", quality); LOG_ALWAYS_FATAL_IF(format != AUDIO_FORMAT_PCM_16_BIT, "invalid pcm format"); // Cocos2d-x only uses MED_QUALITY, so we could remove Sinc relative files - // resampler = new (std::nothrow) AudioResamplerSinc(inChannelCount, sampleRate, quality); + // resampler = ccnew AudioResamplerSinc(inChannelCount, sampleRate, quality); ALOG_ASSERT(false, "VERY_HIGH_QUALITY isn't supported"); break; } diff --git a/native/cocos/audio/android/PcmAudioPlayer.cpp b/native/cocos/audio/android/PcmAudioPlayer.cpp index 0b1ee2d662..054b50b734 100644 --- a/native/cocos/audio/android/PcmAudioPlayer.cpp +++ b/native/cocos/audio/android/PcmAudioPlayer.cpp @@ -29,6 +29,7 @@ THE SOFTWARE. #include "audio/android/AudioMixerController.h" #include "audio/android/ICallerThreadUtils.h" #include "audio/android/cutils/log.h" +#include "base/memory/Memory.h" namespace cc { @@ -46,7 +47,7 @@ bool PcmAudioPlayer::prepare(const ccstd::string &url, const PcmData &decResult) _url = url; _decResult = decResult; - _track = new (std::nothrow) Track(_decResult); + _track = ccnew Track(_decResult); std::thread::id callerThreadId = _callerThreadUtils->getCallerThreadId(); diff --git a/native/cocos/audio/apple/AudioEngine-inl.mm b/native/cocos/audio/apple/AudioEngine-inl.mm index 42a2777afb..b08c8cacbf 100644 --- a/native/cocos/audio/apple/AudioEngine-inl.mm +++ b/native/cocos/audio/apple/AudioEngine-inl.mm @@ -34,10 +34,11 @@ #endif #include "audio/include/AudioEngine.h" -#include "platform/FileUtils.h" #include "application/ApplicationManager.h" #include "base/Scheduler.h" #include "base/Utils.h" +#include "base/memory/Memory.h" +#include "platform/FileUtils.h" using namespace cc; @@ -270,14 +271,14 @@ bool AudioEngineImpl::init() { { if (gOALBufferMap == NULL) // Position 1 { - gOALBufferMap = new OALBufferMap (); // Position 2 + gOALBufferMap = ccnew OALBufferMap (); // Position 2 // Position Gap - gBufferMapLock = new CAGuard("OAL:BufferMapLock"); // Position 3 - gDeadOALBufferMap = new OALBufferMap (); + gBufferMapLock = ccnew CAGuard("OAL:BufferMapLock"); // Position 3 + gDeadOALBufferMap = ccnew OALBufferMap (); - OALBuffer *newBuffer = new OALBuffer (AL_NONE); + OALBuffer *newBuffer = ccnew OALBuffer (AL_NONE); gOALBufferMap->Add(AL_NONE, &newBuffer); } } @@ -365,7 +366,7 @@ int AudioEngineImpl::play2d(const ccstd::string &filePath, bool loop, float volu return AudioEngine::INVALID_AUDIO_ID; } - auto player = new (std::nothrow) AudioPlayer; + auto *player = ccnew AudioPlayer; if (player == nullptr) { return AudioEngine::INVALID_AUDIO_ID; } diff --git a/native/cocos/audio/apple/AudioPlayer.mm b/native/cocos/audio/apple/AudioPlayer.mm index a66c2adeaf..05832048c9 100644 --- a/native/cocos/audio/apple/AudioPlayer.mm +++ b/native/cocos/audio/apple/AudioPlayer.mm @@ -27,11 +27,11 @@ #define LOG_TAG "AudioPlayer" #import - -#include "audio/apple/AudioPlayer.h" #include "audio/apple/AudioCache.h" -#include "platform/FileUtils.h" #include "audio/apple/AudioDecoder.h" +#include "audio/apple/AudioPlayer.h" +#include "base/memory/Memory.h" +#include "platform/FileUtils.h" #ifdef VERY_VERY_VERBOSE_LOGGING #define ALOGVV ALOGV @@ -190,7 +190,7 @@ bool AudioPlayer::play2d() { // To continuously stream audio from a source without interruption, buffer queuing is required. alSourceQueueBuffers(_alSource, QUEUEBUFFER_NUM, _bufferIds); CHECK_AL_ERROR_DEBUG(); - _rotateBufferThread = new std::thread(&AudioPlayer::rotateBufferThread, this, _audioCache->_queBufferFrames * QUEUEBUFFER_NUM + 1); + _rotateBufferThread = ccnew std::thread(&AudioPlayer::rotateBufferThread, this, _audioCache->_queBufferFrames * QUEUEBUFFER_NUM + 1); } else { alSourcei(_alSource, AL_BUFFER, _audioCache->_alBufferId); CHECK_AL_ERROR_DEBUG(); diff --git a/native/cocos/audio/oalsoft/AudioDecoderManager.cpp b/native/cocos/audio/oalsoft/AudioDecoderManager.cpp index 6ff0cc37cd..18e4d6861d 100644 --- a/native/cocos/audio/oalsoft/AudioDecoderManager.cpp +++ b/native/cocos/audio/oalsoft/AudioDecoderManager.cpp @@ -33,6 +33,7 @@ #include "audio/ohos/AudioDecoderWav.h" #endif #include "audio/oalsoft/AudioMacros.h" +#include "base/memory/Memory.h" #include "platform/FileUtils.h" namespace cc { @@ -48,16 +49,16 @@ void AudioDecoderManager::destroy() { AudioDecoder *AudioDecoderManager::createDecoder(const char *path) { ccstd::string suffix = FileUtils::getInstance()->getFileExtension(path); if (suffix == ".ogg") { - return new (std::nothrow) AudioDecoderOgg(); + return ccnew AudioDecoderOgg(); } if (suffix == ".mp3") { - return new (std::nothrow) AudioDecoderMp3(); + return ccnew AudioDecoderMp3(); } #if CC_PLATFORM == CC_PLATFORM_OHOS if (suffix == ".wav") { - return new (std::nothrow) AudioDecoderWav(); + return ccnew AudioDecoderWav(); } #endif diff --git a/native/cocos/audio/oalsoft/AudioEngine-soft.cpp b/native/cocos/audio/oalsoft/AudioEngine-soft.cpp index a6e814edbf..cdbd041ec0 100644 --- a/native/cocos/audio/oalsoft/AudioEngine-soft.cpp +++ b/native/cocos/audio/oalsoft/AudioEngine-soft.cpp @@ -45,6 +45,7 @@ #include "audio/include/AudioEngine.h" #include "audio/oalsoft/AudioDecoderManager.h" #include "base/Scheduler.h" +#include "base/memory/Memory.h" #include "platform/FileUtils.h" #if CC_PLATFORM == CC_PLATFORM_WINDOWS @@ -60,7 +61,7 @@ static void _winLog(const char *format, va_list args) { char * buf = nullptr; do { - buf = new (std::nothrow) char[bufferSize]; + buf = ccnew char[bufferSize]; if (buf == nullptr) return; // not enough memory @@ -220,7 +221,7 @@ int AudioEngineImpl::play2d(const ccstd::string &filePath, bool loop, float volu return AudioEngine::INVALID_AUDIO_ID; } - auto player = new (std::nothrow) AudioPlayer; + auto player = ccnew AudioPlayer; if (player == nullptr) { return AudioEngine::INVALID_AUDIO_ID; } diff --git a/native/cocos/audio/oalsoft/AudioPlayer.cpp b/native/cocos/audio/oalsoft/AudioPlayer.cpp index e330ae19fb..7c4f060320 100644 --- a/native/cocos/audio/oalsoft/AudioPlayer.cpp +++ b/native/cocos/audio/oalsoft/AudioPlayer.cpp @@ -26,16 +26,15 @@ #define LOG_TAG "AudioPlayer" +#include +#include #include "audio/oalsoft/AudioPlayer.h" #include "audio/oalsoft/AudioCache.h" #include "audio/oalsoft/AudioDecoder.h" #include "audio/oalsoft/AudioDecoderManager.h" - +#include "base/memory/Memory.h" #include "base/Log.h" -#include -#include - using namespace cc; //NOLINT namespace { @@ -180,7 +179,7 @@ bool AudioPlayer::play2d() { if (_streamingSource) { alSourceQueueBuffers(_alSource, QUEUEBUFFER_NUM, _bufferIds); CHECK_AL_ERROR_DEBUG(); - _rotateBufferThread = new std::thread(&AudioPlayer::rotateBufferThread, this, + _rotateBufferThread = ccnew std::thread(&AudioPlayer::rotateBufferThread, this, _audioCache->_queBufferFrames * QUEUEBUFFER_NUM + 1); } else { alSourcei(_alSource, AL_BUFFER, _audioCache->_alBufferId); diff --git a/native/cocos/audio/ohos/FsCallback.cpp b/native/cocos/audio/ohos/FsCallback.cpp index 950ce7b37b..559191a173 100644 --- a/native/cocos/audio/ohos/FsCallback.cpp +++ b/native/cocos/audio/ohos/FsCallback.cpp @@ -23,11 +23,12 @@ THE SOFTWARE. ****************************************************************************/ -#include "cocos/audio/ohos/FsCallback.h" +#include "audio/ohos/FsCallback.h" #include #include -#include "cocos/platform/ohos/FileUtils-ohos.h" +#include "platform/ohos/FileUtils-ohos.h" +#include "base/memory/Memory.h" namespace { inline cc::FileUtilsOHOS *getFU() { @@ -48,7 +49,7 @@ namespace cc { void *ohosOpen(const char *path, void *user) { bool isRawfile = false; const auto newPath = getFU()->expandPath(path, &isRawfile); - auto * ret = new FatFd(); + auto * ret = ccnew FatFd(); if (isRawfile) { ret->file.rf = OpenRawFile(cc::FileUtilsOHOS::getResourceManager(), newPath.c_str()); } else { diff --git a/native/cocos/base/CachedArray.h b/native/cocos/base/CachedArray.h index cec7af0dc9..ba9ce19885 100644 --- a/native/cocos/base/CachedArray.h +++ b/native/cocos/base/CachedArray.h @@ -39,7 +39,7 @@ public: explicit CachedArray(uint size = 1U) { _size = 0; _capacity = std::max(size, 1U); - _array = CC_NEW_ARRAY(T, _capacity); + _array = ccnew T[_capacity]; } // The rule of five applies here @@ -48,16 +48,16 @@ public: } CachedArray(const CachedArray &other) - : _size(other._size), _capacity(other._capacity), _array(CC_NEW_ARRAY(T, other._capacity)) { + : _size(other._size), _capacity(other._capacity), _array(ccnew T[other._capacity]) { memcpy(_array, other._array, _size * sizeof(T)); } CachedArray &operator=(const CachedArray &other) { if (this != &other) { - CC_DELETE_ARRAY(_array); + delete[] _array; _size = other._size; _capacity = other._capacity; - _array = CC_NEW_ARRAY(T, _capacity); + _array = ccnew T[_capacity]; memcpy(_array, other._array, _size * sizeof(T)); } return *this; @@ -71,7 +71,7 @@ public: CachedArray &operator=(CachedArray &&other) noexcept { if (this != &other) { - CC_DELETE_ARRAY(_array); + delete[] _array; _size = other._size; _capacity = other._capacity; _array = other._array; @@ -98,20 +98,20 @@ public: void reserve(uint size) { if (size > _capacity) { T *temp = _array; - _array = CC_NEW_ARRAY(T, size); + _array = ccnew T[size]; memcpy(_array, temp, _capacity * sizeof(T)); _capacity = size; - CC_DELETE_ARRAY(temp); + delete[] temp; } } void push(T item) { if (_size >= _capacity) { T *temp = _array; - _array = CC_NEW_ARRAY(T, _capacity * 2); + _array = ccnew T[_capacity * 2]; memcpy(_array, temp, _capacity * sizeof(T)); _capacity *= 2; - CC_DELETE_ARRAY(temp); + delete[] temp; } _array[_size++] = item; } @@ -120,10 +120,10 @@ public: if (_size + array._size > _capacity) { T * temp = _array; uint size = std::max(_capacity * 2, _size + array._size); - _array = CC_NEW_ARRAY(T, size); + _array = ccnew T[size]; memcpy(_array, temp, _size * sizeof(T)); _capacity = size; - CC_DELETE_ARRAY(temp); + delete[] temp; } memcpy(_array + _size, array._array, array._size * sizeof(T)); _size += array._size; @@ -133,10 +133,10 @@ public: if (_size + count > _capacity) { T * temp = _array; uint size = std::max(_capacity * 2, _size + count); - _array = CC_NEW_ARRAY(T, size); + _array = ccnew T[size]; memcpy(_array, temp, _size * sizeof(T)); _capacity = size; - CC_DELETE_ARRAY(temp); + delete[] temp; } memcpy(_array + _size, array, count * sizeof(T)); _size += count; diff --git a/native/cocos/base/Ptr.h b/native/cocos/base/Ptr.h index 55f554174a..3f2b5f196f 100644 --- a/native/cocos/base/Ptr.h +++ b/native/cocos/base/Ptr.h @@ -37,13 +37,13 @@ // }; // // void some_function() { -// IntrusivePtr foo = new MyFoo(); +// IntrusivePtr foo = ccnew MyFoo(); // foo->Method(param); // // `foo` is released when this function returns // } // // void some_other_function() { -// IntrusivePtr foo = new MyFoo(); +// IntrusivePtr foo = ccnew MyFoo(); // ... // foo = nullptr; // explicitly releases `foo` // ... @@ -56,7 +56,7 @@ // references between the two objects, like so: // // { -// IntrusivePtr a = new MyFoo(); +// IntrusivePtr a = ccnew MyFoo(); // IntrusivePtr b; // // b.swap(a); @@ -67,7 +67,7 @@ // object, simply use the assignment operator: // // { -// IntrusivePtr a = new MyFoo(); +// IntrusivePtr a = ccnew MyFoo(); // IntrusivePtr b; // // b = a; diff --git a/native/cocos/base/Scheduler.cpp b/native/cocos/base/Scheduler.cpp index 4af2bf8946..3fa41484ce 100644 --- a/native/cocos/base/Scheduler.cpp +++ b/native/cocos/base/Scheduler.cpp @@ -33,6 +33,7 @@ #include #include "base/Log.h" #include "base/Macros.h" +#include "base/memory/Memory.h" namespace { constexpr unsigned CC_REPEAT_FOREVER{UINT_MAX - 1}; @@ -155,7 +156,7 @@ void Scheduler::schedule(const ccSchedulerFunc &callback, void *target, float in auto iter = _hashForTimers.find(target); HashTimerEntry *element = nullptr; if (iter == _hashForTimers.end()) { - element = new HashTimerEntry(); + element = ccnew HashTimerEntry(); element->target = target; _hashForTimers[target] = element; @@ -180,7 +181,7 @@ void Scheduler::schedule(const ccSchedulerFunc &callback, void *target, float in } } - auto *timer = new (std::nothrow) TimerTargetCallback(); + auto *timer = ccnew TimerTargetCallback(); timer->addRef(); timer->initWithCallback(this, callback, target, key, interval, repeat, delay); element->timers.emplace_back(timer); diff --git a/native/cocos/base/StringPool.h b/native/cocos/base/StringPool.h index 32317d823d..f234141e90 100644 --- a/native/cocos/base/StringPool.h +++ b/native/cocos/base/StringPool.h @@ -30,6 +30,7 @@ #include "base/Macros.h" #include "base/std/container/unordered_map.h" #include "base/std/container/vector.h" +#include "base/memory/Memory.h" #include "boost/functional/hash.hpp" #include "threading/ReadWriteLock.h" @@ -120,7 +121,7 @@ inline StringHandle StringPool::doStringToHandle(const char *str) no if (it == _stringToHandles.end()) { size_t const strLength = strlen(str) + 1; - char *const strCache = new char[strLength]; + char *const strCache = ccnew char[strLength]; strcpy(strCache, str); StringHandle name(static_cast(_handleToStrings.size()), strCache); _handleToStrings.emplace_back(strCache); diff --git a/native/cocos/base/ThreadPool.cpp b/native/cocos/base/ThreadPool.cpp index d02befdf68..ecc7f63aec 100644 --- a/native/cocos/base/ThreadPool.cpp +++ b/native/cocos/base/ThreadPool.cpp @@ -27,6 +27,7 @@ #include "base/ThreadPool.h" #include #include +#include "base/memory/Memory.h" #include "platform/StdC.h" #ifdef __ANDROID__ @@ -68,7 +69,7 @@ void LegacyThreadPool::destroyDefaultThreadPool() { LegacyThreadPool *LegacyThreadPool::newCachedThreadPool(int minThreadNum, int maxThreadNum, int shrinkInterval, int shrinkStep, int stretchStep) { - auto *pool = new (std::nothrow) LegacyThreadPool(minThreadNum, maxThreadNum); + auto *pool = ccnew LegacyThreadPool(minThreadNum, maxThreadNum); if (pool != nullptr) { pool->setFixedSize(false); pool->setShrinkInterval(shrinkInterval); @@ -79,7 +80,7 @@ LegacyThreadPool *LegacyThreadPool::newCachedThreadPool(int minThreadNum, int ma } LegacyThreadPool *LegacyThreadPool::newFixedThreadPool(int threadNum) { - auto *pool = new (std::nothrow) LegacyThreadPool(threadNum, threadNum); + auto *pool = ccnew LegacyThreadPool(threadNum, threadNum); if (pool != nullptr) { pool->setFixedSize(true); } @@ -87,7 +88,7 @@ LegacyThreadPool *LegacyThreadPool::newFixedThreadPool(int threadNum) { } LegacyThreadPool *LegacyThreadPool::newSingleThreadPool() { - auto *pool = new (std::nothrow) LegacyThreadPool(1, 1); + auto *pool = ccnew LegacyThreadPool(1, 1); if (pool != nullptr) { pool->setFixedSize(true); } @@ -229,7 +230,7 @@ void LegacyThreadPool::pushTask(const std::function &runnable, } } - auto callback = new (std::nothrow) std::function([runnable](int tid) { + auto callback = ccnew std::function([runnable](int tid) { runnable(tid); }); @@ -374,7 +375,7 @@ void LegacyThreadPool::setThread(int tid) { } }; _threads[tid].reset( - new (std::nothrow) std::thread(f)); // compiler may not support std::make_unique() + ccnew std::thread(f)); // compiler may not support std::make_unique() } } // namespace cc diff --git a/native/cocos/base/Value.cpp b/native/cocos/base/Value.cpp index cae51bde27..634ed5385c 100644 --- a/native/cocos/base/Value.cpp +++ b/native/cocos/base/Value.cpp @@ -82,7 +82,7 @@ Value::Value(bool v) Value::Value(const char *v) : _type(Type::STRING) { - _field.strVal = new (std::nothrow) ccstd::string(); + _field.strVal = ccnew ccstd::string(); if (v) { *_field.strVal = v; } @@ -90,43 +90,43 @@ Value::Value(const char *v) Value::Value(const ccstd::string &v) : _type(Type::STRING) { - _field.strVal = new (std::nothrow) ccstd::string(); + _field.strVal = ccnew ccstd::string(); *_field.strVal = v; } Value::Value(const ValueVector &v) : _type(Type::VECTOR) { - _field.vectorVal = new (std::nothrow) ValueVector(); + _field.vectorVal = ccnew ValueVector(); *_field.vectorVal = v; } Value::Value(ValueVector &&v) : _type(Type::VECTOR) { - _field.vectorVal = new (std::nothrow) ValueVector(); + _field.vectorVal = ccnew ValueVector(); *_field.vectorVal = std::move(v); } Value::Value(const ValueMap &v) : _type(Type::MAP) { - _field.mapVal = new (std::nothrow) ValueMap(); + _field.mapVal = ccnew ValueMap(); *_field.mapVal = v; } Value::Value(ValueMap &&v) : _type(Type::MAP) { - _field.mapVal = new (std::nothrow) ValueMap(); + _field.mapVal = ccnew ValueMap(); *_field.mapVal = std::move(v); } Value::Value(const ValueMapIntKey &v) : _type(Type::INT_KEY_MAP) { - _field.intKeyMapVal = new (std::nothrow) ValueMapIntKey(); + _field.intKeyMapVal = ccnew ValueMapIntKey(); *_field.intKeyMapVal = v; } Value::Value(ValueMapIntKey &&v) : _type(Type::INT_KEY_MAP) { - _field.intKeyMapVal = new (std::nothrow) ValueMapIntKey(); + _field.intKeyMapVal = ccnew ValueMapIntKey(); *_field.intKeyMapVal = std::move(v); } @@ -169,25 +169,25 @@ Value &Value::operator=(const Value &other) { //NOLINT(misc-no-recursion) break; case Type::STRING: if (_field.strVal == nullptr) { - _field.strVal = new ccstd::string(); + _field.strVal = ccnew ccstd::string(); } *_field.strVal = *other._field.strVal; break; case Type::VECTOR: if (_field.vectorVal == nullptr) { - _field.vectorVal = new (std::nothrow) ValueVector(); + _field.vectorVal = ccnew ValueVector(); } *_field.vectorVal = *other._field.vectorVal; break; case Type::MAP: if (_field.mapVal == nullptr) { - _field.mapVal = new (std::nothrow) ValueMap(); + _field.mapVal = ccnew ValueMap(); } *_field.mapVal = *other._field.mapVal; break; case Type::INT_KEY_MAP: if (_field.intKeyMapVal == nullptr) { - _field.intKeyMapVal = new (std::nothrow) ValueMapIntKey(); + _field.intKeyMapVal = ccnew ValueMapIntKey(); } *_field.intKeyMapVal = *other._field.intKeyMapVal; break; @@ -809,16 +809,16 @@ void Value::reset(Type type) { // Allocate memory for the new value switch (type) { case Type::STRING: - _field.strVal = new (std::nothrow) ccstd::string(); + _field.strVal = ccnew ccstd::string(); break; case Type::VECTOR: - _field.vectorVal = new (std::nothrow) ValueVector(); + _field.vectorVal = ccnew ValueVector(); break; case Type::MAP: - _field.mapVal = new (std::nothrow) ValueMap(); + _field.mapVal = ccnew ValueMap(); break; case Type::INT_KEY_MAP: - _field.intKeyMapVal = new (std::nothrow) ValueMapIntKey(); + _field.intKeyMapVal = ccnew ValueMapIntKey(); break; default: break; diff --git a/native/cocos/base/ZipUtils.cpp b/native/cocos/base/ZipUtils.cpp index 3716a55dd3..05ccef2aa1 100644 --- a/native/cocos/base/ZipUtils.cpp +++ b/native/cocos/base/ZipUtils.cpp @@ -27,7 +27,6 @@ // IDEA: hack, must be included before ziputils #include "base/ZipUtils.h" -#include "base/Log.h" #include @@ -38,16 +37,15 @@ #endif #include -#include "unzip/ioapi_mem.h" - #include #include #include - #include "base/Data.h" #include "base/Locked.h" +#include "base/Log.h" #include "base/memory/Memory.h" #include "platform/FileUtils.h" +#include "unzip/ioapi_mem.h" // minizip 1.2.0 is same with other platforms #ifndef unzGoToFirstFile64 @@ -465,7 +463,7 @@ public: }; ZipFile *ZipFile::createWithBuffer(const void *buffer, uint32_t size) { - auto *zip = new (std::nothrow) ZipFile(); + auto *zip = ccnew ZipFile(); if (zip && zip->initWithBuffer(buffer, size)) { return zip; } @@ -474,13 +472,13 @@ ZipFile *ZipFile::createWithBuffer(const void *buffer, uint32_t size) { } ZipFile::ZipFile() -: _data(new ZipFilePrivate) { +: _data(ccnew ZipFilePrivate) { auto zipFile = _data->zipFile.lock(); *zipFile = nullptr; } ZipFile::ZipFile(const ccstd::string &zipFile, const ccstd::string &filter) -: _data(new ZipFilePrivate) { +: _data(ccnew ZipFilePrivate) { auto zipFileL = _data->zipFile.lock(); *zipFileL = unzOpen(FileUtils::getInstance()->getSuitableFOpen(zipFile).c_str()); setFilter(filter); @@ -647,7 +645,7 @@ bool ZipFile::initWithBuffer(const void *buffer, uint32_t size) { auto zipFile = _data->zipFile.lock(); zlib_filefunc_def memoryFile = {nullptr}; - std::unique_ptr memfs(new (std::nothrow) ourmemory_t{static_cast(const_cast(buffer)), static_cast(size), 0, 0, 0}); + std::unique_ptr memfs(ccnew ourmemory_t{static_cast(const_cast(buffer)), static_cast(size), 0, 0, 0}); if (!memfs) return false; fill_memory_filefunc(&memoryFile, memfs.get()); diff --git a/native/cocos/base/job-system/job-system-dummy/DummyJobGraph.cpp b/native/cocos/base/job-system/job-system-dummy/DummyJobGraph.cpp index 3f8cec8c83..761dda2640 100644 --- a/native/cocos/base/job-system/job-system-dummy/DummyJobGraph.cpp +++ b/native/cocos/base/job-system/job-system-dummy/DummyJobGraph.cpp @@ -60,7 +60,7 @@ void DummyGraphNode::precede(DummyGraphNode *other) { void DummyGraphNode::allocChunk() { assert(freeList == nullptr); - freeList = new (std::nothrow) DummyGraphNode[DUMMY_GRAPH_NODE_CHUNK_SIZE](); + freeList = ccnew DummyGraphNode[DUMMY_GRAPH_NODE_CHUNK_SIZE](); allocatedChunks.emplace_back(freeList); for (auto i = 0; i < DUMMY_GRAPH_NODE_CHUNK_SIZE - 1; i++) { freeList[i]._next = &freeList[i + 1]; diff --git a/native/cocos/base/job-system/job-system-dummy/DummyJobGraph.h b/native/cocos/base/job-system/job-system-dummy/DummyJobGraph.h index 848fac1975..f891141b81 100644 --- a/native/cocos/base/job-system/job-system-dummy/DummyJobGraph.h +++ b/native/cocos/base/job-system/job-system-dummy/DummyJobGraph.h @@ -25,10 +25,11 @@ #pragma once +#include "base/Macros.h" +#include "base/TypeDef.h" +#include "base/memory/Memory.h" #include "base/std/container/unordered_set.h" #include "base/std/container/vector.h" -#include "cocos/base/Macros.h" -#include "cocos/base/TypeDef.h" namespace cc { @@ -113,7 +114,7 @@ DummyGraphNodeTaskImpl::DummyGraphNodeTaskImpl(Fn &&t) noexcept : _task(t) { template size_t DummyGraph::addNode(Fn &&fn) { DummyGraphNode *n = DummyGraphNode::alloc(); - n->_callback = new DummyGraphNodeTaskImpl(std::forward(fn)); + n->_callback = ccnew DummyGraphNodeTaskImpl(std::forward(fn)); n->_generation = _generation; _nodes.emplace_back(n); return _nodes.size() - 1; diff --git a/native/cocos/base/job-system/job-system-dummy/DummyJobSystem.h b/native/cocos/base/job-system/job-system-dummy/DummyJobSystem.h index 107178d08d..6d836aa5c4 100644 --- a/native/cocos/base/job-system/job-system-dummy/DummyJobSystem.h +++ b/native/cocos/base/job-system/job-system-dummy/DummyJobSystem.h @@ -25,8 +25,9 @@ #pragma once -#include "cocos/base/Macros.h" -#include "cocos/base/TypeDef.h" +#include "base/Macros.h" +#include "base/TypeDef.h" +#include "base/memory/Memory.h" namespace cc { @@ -41,7 +42,7 @@ private: public: static DummyJobSystem *getInstance() { if (!instance) { - instance = new DummyJobSystem; + instance = ccnew DummyJobSystem; } return instance; } diff --git a/native/cocos/base/job-system/job-system-taskflow/TFJobSystem.h b/native/cocos/base/job-system/job-system-taskflow/TFJobSystem.h index b64b02726d..1ea49d79a9 100644 --- a/native/cocos/base/job-system/job-system-taskflow/TFJobSystem.h +++ b/native/cocos/base/job-system/job-system-taskflow/TFJobSystem.h @@ -37,7 +37,7 @@ class TFJobSystem final { public: static TFJobSystem *getInstance() { if (!_instance) { - _instance = CC_NEW(TFJobSystem); + _instance = ccnew TFJobSystem; } return _instance; } diff --git a/native/cocos/base/job-system/job-system-tbb/TBBJobSystem.h b/native/cocos/base/job-system/job-system-tbb/TBBJobSystem.h index 7b4331028f..6a8803dd2e 100644 --- a/native/cocos/base/job-system/job-system-tbb/TBBJobSystem.h +++ b/native/cocos/base/job-system/job-system-tbb/TBBJobSystem.h @@ -39,7 +39,7 @@ class TBBJobSystem final { public: static TBBJobSystem *getInstance() { if (!_instance) { - _instance = CC_NEW(TBBJobSystem); + _instance = ccnew TBBJobSystem; } return _instance; } diff --git a/native/cocos/base/memory/Memory.h b/native/cocos/base/memory/Memory.h index a198e4ba07..8fb815bf8b 100644 --- a/native/cocos/base/memory/Memory.h +++ b/native/cocos/base/memory/Memory.h @@ -35,6 +35,8 @@ #include #endif +#include // std::nothrow + #include "base/Macros.h" namespace cc { @@ -62,36 +64,18 @@ public: }; } // namespace cc -#define CC_NEW(T) new T -#define CC_NEW_ALIGN(T, align) new (::cc::MemoryAllocDealloc::allocateBytesAligned(align, sizeof(T))) T -#define CC_NEW_ALIGN_ARGS(T, align, ...) new (::cc::MemoryAllocDealloc::allocateBytesAligned(align, sizeof(T))) T(__VA_ARGS__) -#define CC_NEW_ARRAY(T, count) new T[count] -#define CC_DELETE(ptr) delete (ptr) -#define CC_DELETE_ARRAY(ptr) delete[](ptr) - -#define CC_DELETE_ALIGN(ptr, T, align) \ - if (ptr) { \ - (ptr)->~T(); \ - ::cc::MemoryAllocDealloc::deallocateBytesAligned((void *)ptr); \ - } - -#define CC_DELETE_ARRAY_ALIGN(ptr, T, count, align) \ - if (ptr) { \ - for (size_t _b = 0; _b < (size_t)count; ++_b) { \ - (ptr)[_b].~T(); \ - } \ - ::cc::MemoryAllocDealloc::deallocateBytesAligned((void *)ptr); \ - } +#define ccnew new (std::nothrow) +#define ccnew_placement(...) new (__VA_ARGS__) #define CC_SAFE_DELETE(ptr) \ if (ptr) { \ - CC_DELETE(ptr); \ + delete ptr; \ (ptr) = nullptr; \ } #define CC_SAFE_DELETE_ARRAY(ptr) \ if (ptr) { \ - CC_DELETE_ARRAY(ptr); \ + delete[] ptr; \ (ptr) = nullptr; \ } @@ -100,6 +84,7 @@ public: #define CC_REALLOC(ptr, bytes) realloc(ptr, bytes) #define CC_FREE(ptr) free((void *)ptr) #define CC_FREE_ALIGN(ptr) ::cc::MemoryAllocDealloc::deallocateBytesAligned(ptr) + #define CC_SAFE_FREE(ptr) \ if (ptr) { \ CC_FREE(ptr); \ @@ -114,8 +99,8 @@ public: #define CC_SAFE_DESTROY_AND_DELETE(ptr) \ if (ptr) { \ (ptr)->destroy(); \ - CC_DELETE(ptr); \ - ptr = nullptr; \ + delete ptr; \ + (ptr) = nullptr; \ } #define CC_SAFE_DESTROY_NULL(ptr) \ diff --git a/native/cocos/base/threading/MessageQueue.cpp b/native/cocos/base/threading/MessageQueue.cpp index 8d548a597f..aa0600df78 100644 --- a/native/cocos/base/threading/MessageQueue.cpp +++ b/native/cocos/base/threading/MessageQueue.cpp @@ -137,7 +137,7 @@ void MessageQueue::terminateConsumerThread() noexcept { ReaderContext *const pR = &_reader; - new (allocate(1)) TerminateConsumerThreadMessage(pEvent, pR); + ccnew_placement (allocate(1)) TerminateConsumerThreadMessage(pEvent, pR); kick(); event.wait(); @@ -180,7 +180,7 @@ uint8_t *MessageQueue::allocateImpl(uint32_t allocatedSize, uint32_t const reque } uint8_t *const newChunk = MessageQueue::MemoryAllocator::getInstance().request(); auto *const switchMessage = reinterpret_cast(_writer.currentMemoryChunk + _writer.offset); - new (switchMessage) MemoryChunkSwitchMessage(this, newChunk, _writer.currentMemoryChunk); + ccnew_placement (switchMessage) MemoryChunkSwitchMessage(this, newChunk, _writer.currentMemoryChunk); switchMessage->_next = reinterpret_cast(newChunk); // point to start position _writer.lastMessage = switchMessage; ++_writer.pendingMessageCount; @@ -188,7 +188,7 @@ uint8_t *MessageQueue::allocateImpl(uint32_t allocatedSize, uint32_t const reque _writer.offset = 0; DummyMessage *const head = allocate(1); - new (head) DummyMessage; + ccnew_placement (head) DummyMessage; if (_immediateMode) { pushMessages(); diff --git a/native/cocos/base/threading/MessageQueue.h b/native/cocos/base/threading/MessageQueue.h index 7be159c6f9..f1a918a76b 100644 --- a/native/cocos/base/threading/MessageQueue.h +++ b/native/cocos/base/threading/MessageQueue.h @@ -253,14 +253,14 @@ T *MessageQueue::allocateAndZero(uint32_t const count) noexcept { // utility macros for the producer thread to enqueue messages -#define WRITE_MESSAGE(queue, MessageName, Params) \ - { \ - if (!queue->isImmediateMode()) { \ - new (queue->allocate(1)) MessageName Params; \ - } else { \ - MessageName msg Params; \ - msg.execute(); \ - } \ +#define WRITE_MESSAGE(queue, MessageName, Params) \ + { \ + if (!queue->isImmediateMode()) { \ + ccnew_placement(queue->allocate(1)) MessageName Params; \ + } else { \ + MessageName msg Params; \ + msg.execute(); \ + } \ } #define ENQUEUE_MESSAGE_0(queue, MessageName, Code) \ diff --git a/native/cocos/bindings/event/EventDispatcher.cpp b/native/cocos/bindings/event/EventDispatcher.cpp index 638f36088a..0df4881f8b 100644 --- a/native/cocos/bindings/event/EventDispatcher.cpp +++ b/native/cocos/bindings/event/EventDispatcher.cpp @@ -347,7 +347,7 @@ void EventDispatcher::doDispatchEvent(const char *eventName, const char *jsFunct } uint32_t EventDispatcher::addCustomEventListener(const ccstd::string &eventName, const CustomEventListener &listener) { - Node *newNode = new Node(); + Node *newNode = ccnew Node(); newNode->listener = listener; newNode->listenerID = hashListenerId; newNode->next = nullptr; diff --git a/native/cocos/bindings/jswrapper/MappingUtils.cpp b/native/cocos/bindings/jswrapper/MappingUtils.cpp index 574faa9f44..0a2aae583b 100644 --- a/native/cocos/bindings/jswrapper/MappingUtils.cpp +++ b/native/cocos/bindings/jswrapper/MappingUtils.cpp @@ -25,6 +25,7 @@ ****************************************************************************/ #include "MappingUtils.h" +#include "base/memory/Memory.h" namespace se { @@ -33,7 +34,7 @@ NativePtrToObjectMap::Map *NativePtrToObjectMap::__nativePtrToObjectMap = nullpt bool NativePtrToObjectMap::init() { if (__nativePtrToObjectMap == nullptr) - __nativePtrToObjectMap = new (std::nothrow) NativePtrToObjectMap::Map(); + __nativePtrToObjectMap = ccnew NativePtrToObjectMap::Map(); return __nativePtrToObjectMap != nullptr; } diff --git a/native/cocos/bindings/jswrapper/PrivateObject.h b/native/cocos/bindings/jswrapper/PrivateObject.h index 4113065d7c..08c6332c1d 100644 --- a/native/cocos/bindings/jswrapper/PrivateObject.h +++ b/native/cocos/bindings/jswrapper/PrivateObject.h @@ -31,6 +31,7 @@ #include #include "base/Ptr.h" #include "base/RefCounted.h" +#include "base/memory/Memory.h" namespace se { @@ -186,12 +187,12 @@ inline void inHeap(void *ptr) { template typename std::enable_if::value, PrivateObjectBase *>::type cc_tmp_new_ptr(T *cobj) { - return new CCSharedPtrPrivateObject(cc::IntrusivePtr(cobj)); + return ccnew CCSharedPtrPrivateObject(cc::IntrusivePtr(cobj)); } template typename std::enable_if::value, PrivateObjectBase *>::type cc_tmp_new_ptr(T *cobj) { - return new SharedPrivateObject(std::shared_ptr(cobj)); + return ccnew SharedPrivateObject(std::shared_ptr(cobj)); } template @@ -206,13 +207,13 @@ inline PrivateObjectBase *make_shared_private_object(T *cobj) { // NOLINT template inline PrivateObjectBase *shared_private_object(std::shared_ptr &&ptr) { // NOLINT static_assert(!std::is_base_of::value, "cc::RefCounted is not acceptable for shared_ptr"); - return new SharedPrivateObject(std::forward>(ptr)); + return ccnew SharedPrivateObject(std::forward>(ptr)); } template inline PrivateObjectBase *shared_private_object(const std::shared_ptr &ptr) { // NOLINT static_assert(!std::is_base_of::value, "cc::RefCounted is not acceptable for shared_ptr"); - return new SharedPrivateObject(ptr); + return ccnew SharedPrivateObject(ptr); } template @@ -222,17 +223,17 @@ inline PrivateObjectBase *rawref_private_object(T *ptr) { // NOLINT #if CC_DEBUG inHeap(ptr); #endif - return new RawRefPrivateObject(ptr); + return ccnew RawRefPrivateObject(ptr); } template inline PrivateObjectBase *ccshared_private_object(const cc::IntrusivePtr &ptr) { // NOLINT static_assert(std::is_base_of::value, "cc::RefCounted expected!"); - return new CCSharedPtrPrivateObject(ptr); + return ccnew CCSharedPtrPrivateObject(ptr); } template inline PrivateObjectBase *ccshared_private_object(T *cobj) { // NOLINT static_assert(std::is_base_of::value, "cc::RefCounted expected!"); - return new CCSharedPtrPrivateObject(cc::IntrusivePtr(cobj)); + return ccnew CCSharedPtrPrivateObject(cc::IntrusivePtr(cobj)); } } // namespace se diff --git a/native/cocos/bindings/jswrapper/Value.cpp b/native/cocos/bindings/jswrapper/Value.cpp index 294e113b2d..3fd3c3b625 100644 --- a/native/cocos/bindings/jswrapper/Value.cpp +++ b/native/cocos/bindings/jswrapper/Value.cpp @@ -525,7 +525,7 @@ void Value::reset(Type type) { switch (type) { case Type::String: - _u._string = new ccstd::string(); + _u._string = ccnew ccstd::string(); break; default: break; diff --git a/native/cocos/bindings/jswrapper/config.cpp b/native/cocos/bindings/jswrapper/config.cpp index 6cafbc1709..a314d9ddfe 100644 --- a/native/cocos/bindings/jswrapper/config.cpp +++ b/native/cocos/bindings/jswrapper/config.cpp @@ -26,6 +26,7 @@ #include "config.h" #include #include +#include "base/memory/Memory.h" #if defined(_WIN32) && defined(_WINDOWS) @@ -37,7 +38,7 @@ static void _winLog(FILE *fp, const char *format, va_list args) { char * buf = nullptr; do { - buf = new (std::nothrow) char[bufferSize]; + buf = ccnew char[bufferSize]; if (buf == nullptr) return; // not enough memory diff --git a/native/cocos/bindings/jswrapper/sm/Class.cpp b/native/cocos/bindings/jswrapper/sm/Class.cpp index 2a5791c4d2..33c894a5bb 100644 --- a/native/cocos/bindings/jswrapper/sm/Class.cpp +++ b/native/cocos/bindings/jswrapper/sm/Class.cpp @@ -64,7 +64,7 @@ Class::~Class() { } Class *Class::create(const char *className, Object *obj, Object *parentProto, JSNative ctor) { - Class *cls = new Class(); + Class *cls = ccnew Class(); if (cls != nullptr && !cls->init(className, obj, parentProto, ctor)) { delete cls; cls = nullptr; diff --git a/native/cocos/bindings/jswrapper/sm/Object.cpp b/native/cocos/bindings/jswrapper/sm/Object.cpp index 794d7e38de..8418b9bf5b 100644 --- a/native/cocos/bindings/jswrapper/sm/Object.cpp +++ b/native/cocos/bindings/jswrapper/sm/Object.cpp @@ -79,7 +79,7 @@ bool Object::init(Class *cls, JSObject *obj) { } Object *Object::_createJSObject(Class *cls, JSObject *obj) { - Object *ret = new Object(); + Object *ret = ccnew Object(); if (!ret->init(cls, obj)) { delete ret; ret = nullptr; @@ -89,7 +89,7 @@ Object *Object::_createJSObject(Class *cls, JSObject *obj) { } Object *Object::_createJSObjectForConstructor(Class *cls, const JS::CallArgs &args) { - Object * ret = new Object(); + Object * ret = ccnew Object(); JS::RootedObject obj(__cx, JS_NewObjectForConstructor(__cx, &cls->_jsCls, args)); if (!ret->init(cls, obj)) { delete ret; @@ -162,7 +162,7 @@ Object *Object::createExternalArrayBufferObject(void *contents, size_t byteLengt size_t byteLength; }; - auto *userData = new BackingStoreUserData(); + auto *userData = ccnew BackingStoreUserData(); userData->freeFunc = freeFunc; userData->freeUserData = freeUserData; userData->byteLength = byteLength; diff --git a/native/cocos/bindings/jswrapper/sm/ScriptEngine.cpp b/native/cocos/bindings/jswrapper/sm/ScriptEngine.cpp index 9e8ccedd4d..46877c1858 100644 --- a/native/cocos/bindings/jswrapper/sm/ScriptEngine.cpp +++ b/native/cocos/bindings/jswrapper/sm/ScriptEngine.cpp @@ -259,7 +259,7 @@ AutoHandleScope::~AutoHandleScope() { ScriptEngine *ScriptEngine::getInstance() { if (__instance == nullptr) { - __instance = new ScriptEngine(); + __instance = ccnew ScriptEngine(); } return __instance; @@ -882,7 +882,7 @@ bool ScriptEngine::compileScript(const std::string &path, JS::MutableHandleScrip // if (appended && result == JS::TranscodeResult::TranscodeResult_Ok) // { // compileSucceed = true; - // _filenameScriptMap[byteCodePath] = new (std::nothrow) JS::PersistentRootedScript(_cx, script.get()); + // _filenameScriptMap[byteCodePath] = ccnew JS::PersistentRootedScript(_cx, script.get()); // } // assert(compileSucceed); // } @@ -910,7 +910,7 @@ bool ScriptEngine::compileScript(const std::string &path, JS::MutableHandleScrip compileSucceed = true; script.set(compiledScript); std::string fullPath = _fileOperationDelegate.onGetFullPath(path); - _filenameScriptMap[fullPath] = new (std::nothrow) JS::PersistentRootedScript(_cx, script.get()); + _filenameScriptMap[fullPath] = ccnew JS::PersistentRootedScript(_cx, script.get()); } assert(compileSucceed); } diff --git a/native/cocos/bindings/jswrapper/v8/Class.cpp b/native/cocos/bindings/jswrapper/v8/Class.cpp index 99c1994ee6..a556e52086 100644 --- a/native/cocos/bindings/jswrapper/v8/Class.cpp +++ b/native/cocos/bindings/jswrapper/v8/Class.cpp @@ -67,7 +67,7 @@ Class::~Class() = default; /* static */ Class *Class::create(const ccstd::string &clsName, se::Object *parent, Object *parentProto, v8::FunctionCallback ctor) { - auto *cls = new Class(); + auto *cls = ccnew Class(); if (cls != nullptr && !cls->init(clsName, parent, parentProto, ctor)) { delete cls; cls = nullptr; diff --git a/native/cocos/bindings/jswrapper/v8/Object.cpp b/native/cocos/bindings/jswrapper/v8/Object.cpp index 5b6e08859c..9b378bad09 100644 --- a/native/cocos/bindings/jswrapper/v8/Object.cpp +++ b/native/cocos/bindings/jswrapper/v8/Object.cpp @@ -169,7 +169,7 @@ Object *Object::getObjectWithPtr(void *ptr) { } Object *Object::_createJSObject(Class *cls, v8::Local obj) { // NOLINT(readability-identifier-naming) - auto *ret = new Object(); + auto *ret = ccnew Object(); if (!ret->init(cls, obj)) { delete ret; ret = nullptr; diff --git a/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp b/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp index 1390d48570..3226e51cc4 100644 --- a/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp +++ b/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp @@ -472,7 +472,7 @@ void ScriptEngine::privateDataFinalize(PrivateObjectBase *privateObj) { ScriptEngine *ScriptEngine::getInstance() { if (gSriptEngineInstance == nullptr) { - gSriptEngineInstance = new ScriptEngine(); + gSriptEngineInstance = ccnew ScriptEngine(); } return gSriptEngineInstance; @@ -504,7 +504,7 @@ ScriptEngine::ScriptEngine() _isErrorHandleWorking(false) { #if !CC_EDITOR if (!gSharedV8) { - gSharedV8 = new ScriptEngineV8Context(); + gSharedV8 = ccnew ScriptEngineV8Context(); } #endif } @@ -959,7 +959,7 @@ bool ScriptEngine::runByteCodeFile(const ccstd::string &pathBc, Value *ret /* = v8::ScriptOrigin origin(_isolate, scriptPath, 0, 0, true); // restore CacheData - auto * v8CacheData = new v8::ScriptCompiler::CachedData(cachedData.getBytes(), static_cast(cachedData.getSize())); + auto * v8CacheData = ccnew v8::ScriptCompiler::CachedData(cachedData.getBytes(), static_cast(cachedData.getSize())); v8::Local dummyCode; // generate dummy code @@ -1152,7 +1152,7 @@ v8::MaybeLocal ScriptEngine::VMStringPool::get(v8::Isolate *isolate, if (iter == _vmStringPoolMap.end()) { v8::MaybeLocal nameValue = v8::String::NewFromUtf8(isolate, name, v8::NewStringType::kNormal); if (!nameValue.IsEmpty()) { - auto *persistentName = new v8::Persistent(); + auto *persistentName = ccnew v8::Persistent(); persistentName->Reset(isolate, nameValue.ToLocalChecked()); _vmStringPoolMap.emplace(name, persistentName); ret = v8::Local::New(isolate, *persistentName); diff --git a/native/cocos/bindings/manual/JavaScriptJavaBridge.cpp b/native/cocos/bindings/manual/JavaScriptJavaBridge.cpp index dc267f0eef..9c657d725f 100644 --- a/native/cocos/bindings/manual/JavaScriptJavaBridge.cpp +++ b/native/cocos/bindings/manual/JavaScriptJavaBridge.cpp @@ -251,7 +251,7 @@ bool JavaScriptJavaBridge::CallInfo::execute() { _mRetjstring = static_cast(_mEnv->CallStaticObjectMethod(_mClassID, _mMethodID)); if (_mRetjstring) { ccstd::string strValue = cc::StringUtils::getStringUTFCharsJNI(_mEnv, _mRetjstring); - _mRet.stringValue = new ccstd::string(strValue); + _mRet.stringValue = ccnew ccstd::string(strValue); } else { _mRet.stringValue = nullptr; } @@ -301,7 +301,7 @@ bool JavaScriptJavaBridge::CallInfo::executeWithArgs(jvalue *args) { _mRetjstring = static_cast(_mEnv->CallStaticObjectMethodA(_mClassID, _mMethodID, args)); if (_mRetjstring) { ccstd::string strValue = cc::StringUtils::getStringUTFCharsJNI(_mEnv, _mRetjstring); - _mRet.stringValue = new ccstd::string(strValue); + _mRet.stringValue = ccnew ccstd::string(strValue); } else { _mRet.stringValue = nullptr; } @@ -484,7 +484,7 @@ static bool JavaScriptJavaBridge_finalize(se::State &s) { //NOLINT(readability-i SE_BIND_FINALIZE_FUNC(JavaScriptJavaBridge_finalize) static bool JavaScriptJavaBridge_constructor(se::State &s) { //NOLINT(readability-identifier-naming) - auto *cobj = new (std::nothrow) JavaScriptJavaBridge(); + auto *cobj = ccnew JavaScriptJavaBridge(); s.thisObject()->setPrivateData(cobj); return true; } @@ -542,7 +542,7 @@ static bool JavaScriptJavaBridge_callStaticMethod(se::State &s) { //NOLINT(reada JavaScriptJavaBridge::CallInfo call(clsName.c_str(), methodName.c_str(), methodSig.c_str()); if (call.isValid() && call.getArgumentsCount() == (argc - 3)) { int count = argc - 3; - auto * jargs = new jvalue[count]; + auto * jargs = ccnew jvalue[count]; ccstd::vector toReleaseObjects; for (int i = 0; i < count; ++i) { int index = i + 3; @@ -693,7 +693,7 @@ static bool ScriptNativeBridge_finalize(se::State &s) { //NOLINT(readability-ide SE_BIND_FINALIZE_FUNC(ScriptNativeBridge_finalize) static bool ScriptNativeBridge_constructor(se::State &s) { //NOLINT(readability-identifier-naming) - auto *cobj = new (std::nothrow) ScriptNativeBridge(); + auto *cobj = ccnew ScriptNativeBridge(); s.thisObject()->setPrivateData(cobj); ScriptNativeBridge::bridgeCxxInstance = cobj; return true; diff --git a/native/cocos/bindings/manual/JavaScriptObjCBridge.mm b/native/cocos/bindings/manual/JavaScriptObjCBridge.mm index fa81bf254b..7b3c11c698 100644 --- a/native/cocos/bindings/manual/JavaScriptObjCBridge.mm +++ b/native/cocos/bindings/manual/JavaScriptObjCBridge.mm @@ -300,7 +300,7 @@ static bool JavaScriptObjCBridge_finalize(se::State &s) { SE_BIND_FINALIZE_FUNC(JavaScriptObjCBridge_finalize) static bool JavaScriptObjCBridge_constructor(se::State &s) { - JavaScriptObjCBridge *cobj = new (std::nothrow) JavaScriptObjCBridge(); + JavaScriptObjCBridge *cobj = ccnew JavaScriptObjCBridge(); s.thisObject()->setPrivateData(cobj); return true; } @@ -419,7 +419,7 @@ static bool ScriptNativeBridge_finalize(se::State &s) { //NOLINT(readability-ide SE_BIND_FINALIZE_FUNC(ScriptNativeBridge_finalize) static bool ScriptNativeBridge_constructor(se::State &s) { //NOLINT(readability-identifier-naming) - auto *cobj = new (std::nothrow) ScriptNativeBridge(); + auto *cobj = ccnew ScriptNativeBridge(); s.thisObject()->setPrivateData(cobj); ScriptNativeBridge::bridgeCxxInstance = cobj; return true; diff --git a/native/cocos/bindings/manual/jsb_cocos_manual.cpp b/native/cocos/bindings/manual/jsb_cocos_manual.cpp index 9b6d45c27b..f76438ba75 100644 --- a/native/cocos/bindings/manual/jsb_cocos_manual.cpp +++ b/native/cocos/bindings/manual/jsb_cocos_manual.cpp @@ -44,7 +44,7 @@ public: static JSPlistDelegator *getInstance() { static JSPlistDelegator *pInstance = nullptr; if (pInstance == nullptr) { - pInstance = new (std::nothrow) JSPlistDelegator(); + pInstance = ccnew JSPlistDelegator(); } return pInstance; }; diff --git a/native/cocos/bindings/manual/jsb_conversions.h b/native/cocos/bindings/manual/jsb_conversions.h index bc16d9813d..7b77631a06 100644 --- a/native/cocos/bindings/manual/jsb_conversions.h +++ b/native/cocos/bindings/manual/jsb_conversions.h @@ -935,7 +935,7 @@ inline bool sevalue_to_native(const se::Value &from, HolderType return true; } if CC_CONSTEXPR (std::is_constructible::value) { - holder->ptr = new (&holder->inlineObject) T; + holder->ptr = ccnew_placement (&holder->inlineObject) T; } else { assert(false); // default construtor not provided } @@ -962,8 +962,8 @@ inline typename std::enable_if, bool>::type sevalue_to_native holder->data = static_cast(ptr); return true; } else { - // holder->ptr = new T; - holder->ptr = new (&holder->inlineObject) T; + // holder->ptr = ccnew T; + holder->ptr = ccnew_placement (&holder->inlineObject) T; return sevalue_to_native(from, holder->ptr, ctx); } } @@ -1053,7 +1053,7 @@ bool sevalue_to_native(const se::Value &from, std::shared_ptr *out, se::Objec template inline typename std::enable_if::value, bool>::type sevalue_to_native(const se::Value &from, cc::IntrusivePtr> *out, se::Object *ctx) { // NOLINT(readability-identifier-naming) - *out = new cc::TypedArrayTemp(); + *out = ccnew cc::TypedArrayTemp(); sevalue_to_native(from, out->get(), ctx); return true; } diff --git a/native/cocos/bindings/manual/jsb_conversions_spec.cpp b/native/cocos/bindings/manual/jsb_conversions_spec.cpp index f951363255..0469de8023 100644 --- a/native/cocos/bindings/manual/jsb_conversions_spec.cpp +++ b/native/cocos/bindings/manual/jsb_conversions_spec.cpp @@ -1043,7 +1043,7 @@ bool sevalue_to_native(const se::Value &from, cc::ArrayBuffer *to, se::Object * } bool sevalue_to_native(const se::Value &from, cc::ArrayBuffer **to, se::Object * /*ctx*/) { assert(from.isObject()); - *to = new cc::ArrayBuffer(); + *to = ccnew cc::ArrayBuffer(); (*to)->addRef(); (*to)->setJSArrayBuffer(from.toObject()); cc::DeferredReleasePool::add(*to); diff --git a/native/cocos/bindings/manual/jsb_global.cpp b/native/cocos/bindings/manual/jsb_global.cpp index d1b99faad1..34de2b90ef 100644 --- a/native/cocos/bindings/manual/jsb_global.cpp +++ b/native/cocos/bindings/manual/jsb_global.cpp @@ -500,7 +500,7 @@ uint8_t *convertI2RGBA(uint32_t length, uint8_t *src) { } struct ImageInfo *createImageInfo(Image *img) { - auto *imgInfo = new struct ImageInfo(); + auto *imgInfo = ccnew struct ImageInfo(); imgInfo->length = static_cast(img->getDataLen()); imgInfo->width = img->getWidth(); imgInfo->height = img->getHeight(); @@ -555,7 +555,7 @@ bool jsb_global_load_image(const ccstd::string &path, const se::Value &callbackV std::shared_ptr callbackPtr = std::make_shared(callbackVal); auto initImageFunc = [path, callbackPtr](const ccstd::string &fullPath, unsigned char *imageData, int imageBytes) { - auto *img = new (std::nothrow) Image(); + auto *img = ccnew Image(); gThreadPool->pushTask([=](int /*tid*/) { // NOTE: FileUtils::getInstance()->fullPathForFilename isn't a threadsafe method, diff --git a/native/cocos/bindings/manual/jsb_global.h b/native/cocos/bindings/manual/jsb_global.h index fa4a2b7814..c9e5be4a7c 100644 --- a/native/cocos/bindings/manual/jsb_global.h +++ b/native/cocos/bindings/manual/jsb_global.h @@ -31,7 +31,7 @@ template T *jsb_override_new(Args &&...args) { //NOLINT(readability-identifier-naming) //create object in the default way - return new T(std::forward(args)...); + return ccnew T(std::forward(args)...); } template @@ -43,8 +43,8 @@ void jsb_override_delete(T *arg) { //NOLINT(readability-identifier-naming) template typename std::enable_if::value, se::PrivateObjectBase *>::type jsb_make_private_object(ARGS &&...args) { //NOLINT(readability-identifier-naming) - //return se::raw_private_data(new T(std::forward(args)...)); - return se::ccshared_private_object(new T(std::forward(args)...)); + //return se::raw_private_data(ccnew T(std::forward(args)...)); + return se::ccshared_private_object(ccnew T(std::forward(args)...)); } template diff --git a/native/cocos/bindings/manual/jsb_helper.cpp b/native/cocos/bindings/manual/jsb_helper.cpp index d4178de49d..36db2a4a50 100644 --- a/native/cocos/bindings/manual/jsb_helper.cpp +++ b/native/cocos/bindings/manual/jsb_helper.cpp @@ -25,17 +25,16 @@ #include "jsb_helper.h" #include "base/DeferredReleasePool.h" +#include "base/memory/Memory.h" /* static */ void CleanupTask::pushTaskToAutoReleasePool(const std::function &cb) { - auto *ret = new (std::nothrow) CleanupTask(); + auto *ret = ccnew CleanupTask; ret->_cb = cb; cc::DeferredReleasePool::add(ret); } -CleanupTask::CleanupTask() -: _cb(nullptr) { -} +CleanupTask::CleanupTask() = default; CleanupTask::~CleanupTask() { if (_cb != nullptr) { diff --git a/native/cocos/bindings/manual/jsb_helper.h b/native/cocos/bindings/manual/jsb_helper.h index 35ade61cca..0f0e5334bf 100644 --- a/native/cocos/bindings/manual/jsb_helper.h +++ b/native/cocos/bindings/manual/jsb_helper.h @@ -37,5 +37,5 @@ public: ~CleanupTask() override; private: - std::function _cb; + std::function _cb{nullptr}; }; diff --git a/native/cocos/bindings/manual/jsb_scene_manual.cpp b/native/cocos/bindings/manual/jsb_scene_manual.cpp index 35e40bd322..407c049643 100644 --- a/native/cocos/bindings/manual/jsb_scene_manual.cpp +++ b/native/cocos/bindings/manual/jsb_scene_manual.cpp @@ -32,7 +32,7 @@ #include "scene/Model.h" #ifndef JSB_ALLOC - #define JSB_ALLOC(kls, ...) new (std::nothrow) kls(__VA_ARGS__) + #define JSB_ALLOC(kls, ...) ccnew kls(__VA_ARGS__) #endif #ifndef JSB_FREE diff --git a/native/cocos/bindings/manual/jsb_socketio.cpp b/native/cocos/bindings/manual/jsb_socketio.cpp index fcfc46897d..b09e487fc0 100644 --- a/native/cocos/bindings/manual/jsb_socketio.cpp +++ b/native/cocos/bindings/manual/jsb_socketio.cpp @@ -285,7 +285,7 @@ static bool SocketIO_connect(se::State &s) { // NOLINT(readability-identifier-na } } - auto *siodelegate = new (std::nothrow) JSB_SocketIODelegate(); + auto *siodelegate = ccnew JSB_SocketIODelegate(); CC_LOG_DEBUG("Calling native SocketIO.connect method"); cc::network::SIOClient *ret = cc::network::SocketIO::connect(url, *siodelegate, caFilePath); diff --git a/native/cocos/bindings/manual/jsb_spine_manual.cpp b/native/cocos/bindings/manual/jsb_spine_manual.cpp index 6e642fa45c..5a8b4ed181 100644 --- a/native/cocos/bindings/manual/jsb_spine_manual.cpp +++ b/native/cocos/bindings/manual/jsb_spine_manual.cpp @@ -25,22 +25,20 @@ #include "jsb_spine_manual.h" #include "platform/FileUtils.h" - #include "base/Data.h" -#include "cocos/bindings/auto/jsb_spine_auto.h" -#include "cocos/bindings/jswrapper/SeApi.h" -#include "cocos/bindings/manual/jsb_conversions.h" -#include "cocos/bindings/manual/jsb_global.h" -#include "cocos/bindings/manual/jsb_helper.h" - +#include "base/memory/Memory.h" +#include "bindings/auto/jsb_spine_auto.h" +#include "bindings/jswrapper/SeApi.h" +#include "bindings/manual/jsb_conversions.h" +#include "bindings/manual/jsb_global.h" +#include "bindings/manual/jsb_helper.h" +#include "editor-support/spine-creator-support/spine-cocos2dx.h" +#include "editor-support/spine/spine.h" #include "middleware-adapter.h" #include "spine-creator-support/SkeletonDataMgr.h" #include "spine-creator-support/SkeletonRenderer.h" #include "spine-creator-support/spine-cocos2dx.h" -#include "cocos/editor-support/spine-creator-support/spine-cocos2dx.h" -#include "cocos/editor-support/spine/spine.h" - using namespace cc; static spine::Cocos2dTextureLoader textureLoader; @@ -93,12 +91,12 @@ static bool js_register_spine_initSkeletonData(se::State &s) { _preloadedAtlasTextures = &textures; spine::spAtlasPage_setCustomTextureLoader(_getPreloadedAtlasTexture); - spine::Atlas *atlas = new (__FILE__, __LINE__) spine::Atlas(atlasText.c_str(), (int)atlasText.size(), "", &textureLoader); + spine::Atlas *atlas = ccnew_placement(__FILE__, __LINE__) spine::Atlas(atlasText.c_str(), (int)atlasText.size(), "", &textureLoader); _preloadedAtlasTextures = nullptr; spine::spAtlasPage_setCustomTextureLoader(nullptr); - spine::AttachmentLoader *attachmentLoader = new (__FILE__, __LINE__) spine::Cocos2dAtlasAttachmentLoader(atlas); + spine::AttachmentLoader *attachmentLoader = ccnew_placement(__FILE__, __LINE__) spine::Cocos2dAtlasAttachmentLoader(atlas); spine::SkeletonData * skeletonData = nullptr; std::size_t length = skeletonDataFile.length(); diff --git a/native/cocos/bindings/manual/jsb_websocket.cpp b/native/cocos/bindings/manual/jsb_websocket.cpp index 1cb075951c..d30d1fcf3c 100644 --- a/native/cocos/bindings/manual/jsb_websocket.cpp +++ b/native/cocos/bindings/manual/jsb_websocket.cpp @@ -293,8 +293,8 @@ static bool webSocketConstructor(se::State &s) { SE_PRECONDITION2(ok, false, "Error processing caFilePath"); } - cobj = new (std::nothrow) cc::network::WebSocket(); - auto *delegate = new (std::nothrow) JsbWebSocketDelegate(); + cobj = ccnew cc::network::WebSocket(); + auto *delegate = ccnew JsbWebSocketDelegate(); delegate->addRef(); if (cobj->init(*delegate, url, &protocols, caFilePath)) { delegate->setJSDelegate(se::Value(obj, true)); @@ -307,8 +307,8 @@ static bool webSocketConstructor(se::State &s) { return false; } } else { - cobj = new (std::nothrow) cc::network::WebSocket(); - auto *delegate = new (std::nothrow) JsbWebSocketDelegate(); + cobj = ccnew cc::network::WebSocket(); + auto *delegate = ccnew JsbWebSocketDelegate(); delegate->addRef(); if (cobj->init(*delegate, url)) { delegate->setJSDelegate(se::Value(obj, true)); diff --git a/native/cocos/bindings/manual/jsb_websocket_server.cpp b/native/cocos/bindings/manual/jsb_websocket_server.cpp index 600d827f17..95f793a732 100644 --- a/native/cocos/bindings/manual/jsb_websocket_server.cpp +++ b/native/cocos/bindings/manual/jsb_websocket_server.cpp @@ -63,7 +63,7 @@ static bool WebSocketServer_constructor(se::State &s) { int argc = (int)args.size(); if (argc == 0) { se::Object *obj = s.thisObject(); - WSSPTR cobj = new std::shared_ptr(new WebSocketServer()); + WSSPTR cobj = ccnew std::shared_ptr(ccnew WebSocketServer()); obj->setPrivateData(cobj); (*cobj)->setData(obj); @@ -182,7 +182,7 @@ static bool WebSocketServer_onconnection(se::State &s) { } se::Object *obj = se::Object::createObjectWithClass(__jsb_WebSocketServer_Connection_class); - WSCONNPTR prv = new std::shared_ptr(conn); + WSCONNPTR prv = ccnew std::shared_ptr(conn); // a connection is dead only if no reference & closed! obj->root(); obj->setPrivateData(prv); diff --git a/native/cocos/bindings/manual/jsb_xmlhttprequest.cpp b/native/cocos/bindings/manual/jsb_xmlhttprequest.cpp index 80835615f7..48d786f69d 100644 --- a/native/cocos/bindings/manual/jsb_xmlhttprequest.cpp +++ b/native/cocos/bindings/manual/jsb_xmlhttprequest.cpp @@ -222,7 +222,7 @@ XMLHttpRequest::XMLHttpRequest() onabort(nullptr), onerror(nullptr), ontimeout(nullptr), - _httpRequest(new (std::nothrow) HttpRequest()), + _httpRequest(ccnew HttpRequest()), _responseType(ResponseType::STRING), _readyState(ReadyState::UNSENT) { } @@ -581,7 +581,7 @@ static bool XMLHttpRequest_finalize(se::State &s) { //NOLINT(readability-identif SE_BIND_FINALIZE_FUNC(XMLHttpRequest_finalize) static bool XMLHttpRequest_constructor(se::State &s) { //NOLINT(readability-identifier-naming, google-runtime-references) - auto *request = new XMLHttpRequest(); + auto *request = ccnew XMLHttpRequest(); s.thisObject()->setPrivateData(request); se::Value thiz(s.thisObject()); diff --git a/native/cocos/core/ArrayBuffer.h b/native/cocos/core/ArrayBuffer.h index 3162b7cf58..4c7ed4daee 100644 --- a/native/cocos/core/ArrayBuffer.h +++ b/native/cocos/core/ArrayBuffer.h @@ -28,6 +28,7 @@ #include "base/Macros.h" #include "base/Ptr.h" #include "base/RefCounted.h" +#include "base/memory/Memory.h" #include "bindings/jswrapper/Object.h" namespace cc { @@ -82,7 +83,7 @@ public: CC_ASSERT(begin < _byteLength); CC_ASSERT(end <= _byteLength); uint32_t newBufByteLength = (end - begin); - Ptr buffer = new ArrayBuffer(newBufByteLength); + Ptr buffer = ccnew ArrayBuffer(newBufByteLength); memcpy(buffer->getData(), _data + begin, newBufByteLength); return buffer; } diff --git a/native/cocos/core/Root.cpp b/native/cocos/core/Root.cpp index d7db7049b1..cca458ecf9 100644 --- a/native/cocos/core/Root.cpp +++ b/native/cocos/core/Root.cpp @@ -24,7 +24,6 @@ ****************************************************************************/ #include "core/Root.h" -// #include "core/Director.h" #include "core/event/CallbacksInvoker.h" #include "core/event/EventTypesToJS.h" #include "profiler/Profiler.h" @@ -190,7 +189,7 @@ bool Root::setRenderPipeline(pipeline::RenderPipeline *rppl /* = nullptr*/) { bool isCreateDefaultPipeline{false}; if (!rppl) { - rppl = new pipeline::ForwardPipeline(); + rppl = ccnew pipeline::ForwardPipeline(); rppl->initialize({}); isCreateDefaultPipeline = true; } @@ -233,7 +232,7 @@ bool Root::setRenderPipeline(pipeline::RenderPipeline *rppl /* = nullptr*/) { _eventProcessor->emit(EventTypesToJS::ROOT_BATCH2D_INIT, this); // TODO(minggo): // if (!_batcher) { - // _batcher = new Batcher2D(this); + // _batcher = ccnew Batcher2D(this); // if (!this._batcher.initialize()) { // this.destroy(); // return false; @@ -323,7 +322,7 @@ void Root::frameMove(float deltaTime, int32_t totalFrames) { } scene::RenderWindow *Root::createWindow(scene::IRenderWindowInfo &info) { - IntrusivePtr window = new scene::RenderWindow(); + IntrusivePtr window = ccnew scene::RenderWindow(); window->initialize(_device, info); _windows.emplace_back(window); @@ -346,7 +345,7 @@ void Root::destroyWindows() { } scene::RenderScene *Root::createScene(const scene::IRenderSceneInfo &info) { - IntrusivePtr scene = new scene::RenderScene(); + IntrusivePtr scene = ccnew scene::RenderScene(); scene->initialize(info); _scenes.emplace_back(scene); return scene.get(); @@ -389,7 +388,7 @@ void Root::destroyLight(scene::Light *light) { // NOLINT(readability-convert-mem } scene::Camera *Root::createCamera() const { - return new scene::Camera(_device); + return ccnew scene::Camera(_device); } void Root::destroyScenes() { diff --git a/native/cocos/core/Root.h b/native/cocos/core/Root.h index 9750e4e3ea..ecbc5dd674 100644 --- a/native/cocos/core/Root.h +++ b/native/cocos/core/Root.h @@ -132,7 +132,7 @@ public: template ::value>> T *createModel() { //cjh TODO: need use model pool? - T *model = new T(); + T *model = ccnew T(); model->initialize(); return model; } @@ -142,7 +142,7 @@ public: template ::value>> T *createLight() { //TODO(xwx): need use model pool? - T *light = new T(); + T *light = ccnew T(); light->initialize(); return light; } diff --git a/native/cocos/core/TypedArray.h b/native/cocos/core/TypedArray.h index 94aba34cec..75c7dd1774 100644 --- a/native/cocos/core/TypedArray.h +++ b/native/cocos/core/TypedArray.h @@ -178,7 +178,7 @@ public: CC_ASSERT(start < (_byteLength / BYTES_PER_ELEMENT)); CC_ASSERT(end <= (_byteLength / BYTES_PER_ELEMENT)); uint32_t newBufByteLength = (end - start) * BYTES_PER_ELEMENT; - auto * buffer = new ArrayBuffer(newBufByteLength); + auto * buffer = ccnew ArrayBuffer(newBufByteLength); memcpy(buffer->getData(), _buffer->getData() + start * BYTES_PER_ELEMENT + _byteOffset, newBufByteLength); return TypedArrayTemp(buffer); } @@ -213,7 +213,7 @@ public: _jsTypedArray = nullptr; } const uint32_t byteLength = length * BYTES_PER_ELEMENT; - _buffer = new ArrayBuffer(byteLength); + _buffer = ccnew ArrayBuffer(byteLength); _byteLength = _buffer->byteLength(); _byteOffset = 0; _byteEndPos = byteLength; @@ -243,7 +243,7 @@ public: assert(tmpVal.isObject()); assert(tmpVal.toObject()->isArrayBuffer()); - _buffer = new ArrayBuffer(); + _buffer = ccnew ArrayBuffer(); _buffer->setJSArrayBuffer(tmpVal.toObject()); _jsTypedArray->getProperty("byteOffset", &tmpVal); diff --git a/native/cocos/core/animation/SkeletalAnimationUtils.cpp b/native/cocos/core/animation/SkeletalAnimationUtils.cpp index 5c6bcc6f5f..2afe14e160 100644 --- a/native/cocos/core/animation/SkeletalAnimationUtils.cpp +++ b/native/cocos/core/animation/SkeletalAnimationUtils.cpp @@ -74,7 +74,7 @@ IJointTransform *getTransform(Node *node, Node *root) { break; } // TODO(): object reuse - joint = pool[id] = new IJointTransform{ + joint = pool[id] = ccnew IJointTransform{ node, Mat4(), Mat4(), diff --git a/native/cocos/core/assets/BitmapFont.cpp b/native/cocos/core/assets/BitmapFont.cpp index fcec95c150..2e0e5b24e3 100644 --- a/native/cocos/core/assets/BitmapFont.cpp +++ b/native/cocos/core/assets/BitmapFont.cpp @@ -148,7 +148,7 @@ float BitmapFontFace::getKerning(uint32_t prevCode, uint32_t nextCode) { } gfx::Texture *BitmapFontFace::loadTexture(const ccstd::string &path) { - auto *image = new Image(); + auto *image = ccnew Image(); bool success = image->initWithImageFile(path); if (!success) { CC_LOG_WARNING("BitmapFontFace initWithImageFile failed, path: %s.", path.c_str()); @@ -193,7 +193,7 @@ BitmapFont::BitmapFont(const ccstd::string &path) } FontFace *BitmapFont::createFace(const FontFaceInfo &info) { - auto *face = new BitmapFontFace(this); + auto *face = ccnew BitmapFontFace(this); face->doInit(info); uint32_t fontSize = face->getFontSize(); diff --git a/native/cocos/core/assets/FreeTypeFont.cpp b/native/cocos/core/assets/FreeTypeFont.cpp index ec6f55cb81..8ca132e274 100644 --- a/native/cocos/core/assets/FreeTypeFont.cpp +++ b/native/cocos/core/assets/FreeTypeFont.cpp @@ -140,7 +140,7 @@ FTLibrary *FreeTypeFontFace::library = nullptr; FreeTypeFontFace::FreeTypeFontFace(Font *font) : FontFace(font) { if (!library) { - library = new FTLibrary(); + library = ccnew FTLibrary(); } } @@ -304,7 +304,7 @@ FreeTypeFont::FreeTypeFont(const ccstd::string &path) } FontFace *FreeTypeFont::createFace(const FontFaceInfo &info) { - auto *face = new FreeTypeFontFace(this); + auto *face = ccnew FreeTypeFontFace(this); face->doInit(info); uint32_t fontSize = face->getFontSize(); diff --git a/native/cocos/core/assets/Material.cpp b/native/cocos/core/assets/Material.cpp index 39662c46d6..500d8ebc7c 100644 --- a/native/cocos/core/assets/Material.cpp +++ b/native/cocos/core/assets/Material.cpp @@ -348,7 +348,7 @@ ccstd::vector> Material::createPasses() { continue; } - auto *pass = new scene::Pass(Root::getInstance()); + auto *pass = ccnew scene::Pass(Root::getInstance()); pass->initialize(passInfo); passes.emplace_back(pass); } diff --git a/native/cocos/core/assets/SceneAsset.cpp b/native/cocos/core/assets/SceneAsset.cpp index 86cd1bd688..720534af80 100644 --- a/native/cocos/core/assets/SceneAsset.cpp +++ b/native/cocos/core/assets/SceneAsset.cpp @@ -39,7 +39,7 @@ void SceneAsset::setScene(Scene *scene) { _scene = scene; }; void SceneAsset::initDefault(const cc::optional &uuid) { Super::initDefault(uuid); - _scene = new Scene("New Scene"); + _scene = ccnew Scene("New Scene"); } } // namespace cc diff --git a/native/cocos/core/assets/Texture2D.cpp b/native/cocos/core/assets/Texture2D.cpp index 3cf46e76e9..4f40174c26 100644 --- a/native/cocos/core/assets/Texture2D.cpp +++ b/native/cocos/core/assets/Texture2D.cpp @@ -178,7 +178,7 @@ void Texture2D::deserialize(const cc::any &serializedData, const cc::any &handle _mipmaps.resize(data->mipmaps.size()); for (size_t i = 0; i < data->mipmaps.size(); ++i) { // Prevent resource load failed - _mipmaps[i] = new ImageAsset(); + _mipmaps[i] = ccnew ImageAsset(); if (data->mipmaps[i].empty()) { continue; } @@ -211,7 +211,7 @@ gfx::TextureViewInfo Texture2D::getGfxTextureViewCreateInfo(gfx::Texture *textur void Texture2D::initDefault(const cc::optional &uuid) { Super::initDefault(uuid); - auto *imageAsset = new ImageAsset(); + auto *imageAsset = ccnew ImageAsset(); imageAsset->initDefault(cc::nullopt); setImage(imageAsset); } diff --git a/native/cocos/core/assets/TextureCube.cpp b/native/cocos/core/assets/TextureCube.cpp index 7109307fc9..1e7bb9ba65 100644 --- a/native/cocos/core/assets/TextureCube.cpp +++ b/native/cocos/core/assets/TextureCube.cpp @@ -66,7 +66,7 @@ TextureCube *TextureCube::fromTexture2DArray(const ccstd::vector &t mipmaps.emplace_back(mipmap); } - auto *out = new TextureCube(); + auto *out = ccnew TextureCube(); out->setMipmaps(mipmaps); return out; } @@ -201,12 +201,12 @@ void TextureCube::deserialize(const cc::any &serializedData, const cc::any &hand for (size_t i = 0; i < data->mipmaps.size(); ++i) { // Prevent resource load failed ITextureCubeMipmap mipmap; - mipmap.front = new ImageAsset(), - mipmap.back = new ImageAsset(), - mipmap.left = new ImageAsset(), - mipmap.right = new ImageAsset(), - mipmap.top = new ImageAsset(), - mipmap.bottom = new ImageAsset(); + mipmap.front = ccnew ImageAsset(), + mipmap.back = ccnew ImageAsset(), + mipmap.left = ccnew ImageAsset(), + mipmap.right = ccnew ImageAsset(), + mipmap.top = ccnew ImageAsset(), + mipmap.bottom = ccnew ImageAsset(); _mipmaps[i] = mipmap; // auto* mipmap = data->mipmaps[i]; @@ -249,7 +249,7 @@ gfx::TextureViewInfo TextureCube::getGfxTextureViewCreateInfo(gfx::Texture *text void TextureCube::initDefault(const cc::optional &uuid) { Super::initDefault(uuid); - auto *imageAsset = new ImageAsset(); + auto *imageAsset = ccnew ImageAsset(); imageAsset->initDefault(cc::nullopt); ITextureCubeMipmap mipmap; diff --git a/native/cocos/core/builtin/BuiltinResMgr.cpp b/native/cocos/core/builtin/BuiltinResMgr.cpp index 713b6bf7b9..5060e026fa 100644 --- a/native/cocos/core/builtin/BuiltinResMgr.cpp +++ b/native/cocos/core/builtin/BuiltinResMgr.cpp @@ -120,7 +120,7 @@ BuiltinResMgr *BuiltinResMgr::instance = nullptr; /* static */ BuiltinResMgr *BuiltinResMgr::getInstance() { if (BuiltinResMgr::instance == nullptr) { - BuiltinResMgr::instance = new BuiltinResMgr(); + BuiltinResMgr::instance = ccnew BuiltinResMgr(); BuiltinResMgr::instance->addRef(); } return instance; @@ -177,9 +177,9 @@ bool BuiltinResMgr::initBuiltinRes(gfx::Device *device) { initTextureCubeWithUuid("default-cube-texture", DEFAULT_IMAGE_RGBA_DATA_16X16, sizeof(DEFAULT_IMAGE_RGBA_DATA_16X16), 16, 16); //cjh TODO: if (SpriteFrame) { - // const spriteFrame = new SpriteFrame() as SpriteFrame; + // const spriteFrame = ccnew SpriteFrame() as SpriteFrame; // const image = imgAsset; - // const texture = new Texture2D(); + // const texture = ccnew Texture2D(); // texture.image = image; // spriteFrame.texture = texture; // spriteFrame._uuid = 'default-spriteframe"; @@ -212,7 +212,7 @@ bool BuiltinResMgr::initBuiltinRes(gfx::Device *device) { rapidjson::Type type = doc.GetType(); auto assetDeserializer = AssetDeserializerFactory::createAssetDeserializer(DeserializeAssetType::EFFECT); for (const auto &e : doc.GetArray()) { - IntrusivePtr effect = new EffectAsset(); + IntrusivePtr effect = ccnew EffectAsset(); assetDeserializer->deserialize(e, effect); index_t shaderIndex = 0; @@ -248,7 +248,7 @@ void BuiltinResMgr::initMaterials() { auto &resources = _resources; // standard material - auto *standardMtl = new Material(); + auto *standardMtl = ccnew Material(); standardMtl->setUuid("standard-material"); IMaterialInfo standardInfo; standardInfo.effectName = ccstd::string{"standard"}; @@ -257,7 +257,7 @@ void BuiltinResMgr::initMaterials() { _materialsToBeCompiled.emplace_back(standardMtl); // material indicating missing effect (yellow) - auto * missingEfxMtl = new Material(); + auto * missingEfxMtl = ccnew Material(); IMaterialInfo missingEfxInfo; missingEfxInfo.effectName = ccstd::string{"unlit"}; missingEfxInfo.defines = IMaterialInfo::DefinesType{ @@ -270,7 +270,7 @@ void BuiltinResMgr::initMaterials() { _materialsToBeCompiled.emplace_back(missingEfxMtl); // material indicating missing material (purple) - auto * missingMtl = new Material(); + auto * missingMtl = ccnew Material(); IMaterialInfo missingInfo; missingInfo.effectName = ccstd::string{"unlit"}, missingInfo.defines = IMaterialInfo::DefinesType{MacroRecord{ @@ -281,7 +281,7 @@ void BuiltinResMgr::initMaterials() { resources[missingMtl->getUuid()] = missingMtl; _materialsToBeCompiled.emplace_back(missingMtl); - auto * clearStencilMtl = new Material(); + auto * clearStencilMtl = ccnew Material(); IMaterialInfo clearStencilInfo; clearStencilInfo.effectName = ccstd::string{"clear-stencil"}, clearStencilInfo.defines = IMaterialInfo::DefinesType{MacroRecord{ @@ -292,7 +292,7 @@ void BuiltinResMgr::initMaterials() { _materialsToBeCompiled.emplace_back(clearStencilMtl); // sprite material - auto *spriteMtl = new Material(); + auto *spriteMtl = ccnew Material(); spriteMtl->setUuid("ui-base-material"); IMaterialInfo spriteInfo; spriteInfo.effectName = ccstd::string{"sprite"}, @@ -302,7 +302,7 @@ void BuiltinResMgr::initMaterials() { _materialsToBeCompiled.emplace_back(spriteMtl); // sprite material - auto *spriteColorMtl = new Material(); + auto *spriteColorMtl = ccnew Material(); spriteColorMtl->setUuid("ui-sprite-material"); IMaterialInfo spriteColorInfo; spriteColorInfo.effectName = ccstd::string{"sprite"}, @@ -312,7 +312,7 @@ void BuiltinResMgr::initMaterials() { _materialsToBeCompiled.emplace_back(spriteColorMtl); // sprite alpha test material - auto * alphaTestMaskMtl = new Material(); + auto * alphaTestMaskMtl = ccnew Material(); IMaterialInfo alphaTestMaskInfo; alphaTestMaskInfo.effectName = ccstd::string{"sprite"}, alphaTestMaskInfo.defines = IMaterialInfo::DefinesType{MacroRecord{ @@ -323,7 +323,7 @@ void BuiltinResMgr::initMaterials() { _materialsToBeCompiled.emplace_back(alphaTestMaskMtl); // sprite gray material - auto *spriteGrayMtl = new Material(); + auto *spriteGrayMtl = ccnew Material(); spriteGrayMtl->setUuid("ui-sprite-gray-material"); IMaterialInfo spriteGrayInfo; spriteGrayInfo.effectName = ccstd::string{"sprite"}, @@ -333,7 +333,7 @@ void BuiltinResMgr::initMaterials() { _materialsToBeCompiled.emplace_back(spriteGrayMtl); // sprite alpha material - auto *spriteAlphaMtl = new Material(); + auto *spriteAlphaMtl = ccnew Material(); spriteAlphaMtl->setUuid("ui-sprite-alpha-sep-material"); IMaterialInfo spriteAlphaInfo; spriteAlphaInfo.effectName = ccstd::string{"sprite"}, @@ -343,7 +343,7 @@ void BuiltinResMgr::initMaterials() { _materialsToBeCompiled.emplace_back(spriteAlphaMtl); // sprite alpha & gray material - auto * spriteAlphaGrayMtl = new Material(); + auto * spriteAlphaGrayMtl = ccnew Material(); IMaterialInfo spriteAlphaGrayInfo; spriteAlphaGrayInfo.effectName = ccstd::string{"sprite"}, spriteAlphaGrayInfo.defines = IMaterialInfo::DefinesType{MacroRecord{ @@ -354,7 +354,7 @@ void BuiltinResMgr::initMaterials() { _materialsToBeCompiled.emplace_back(spriteAlphaGrayMtl); // ui graphics material - auto *defaultGraphicsMtl = new Material(); + auto *defaultGraphicsMtl = ccnew Material(); defaultGraphicsMtl->setUuid("ui-graphics-material"); IMaterialInfo defaultGraphicsInfo; defaultGraphicsInfo.effectName = ccstd::string{"graphics"}; @@ -363,7 +363,7 @@ void BuiltinResMgr::initMaterials() { _materialsToBeCompiled.emplace_back(defaultGraphicsMtl); // default particle material - auto *defaultParticleMtl = new Material(); + auto *defaultParticleMtl = ccnew Material(); defaultParticleMtl->setUuid("default-particle-material"); IMaterialInfo defaultParticleInfo; defaultParticleInfo.effectName = ccstd::string{"particle"}; @@ -372,7 +372,7 @@ void BuiltinResMgr::initMaterials() { _materialsToBeCompiled.emplace_back(defaultParticleMtl); // default particle gpu material - auto *defaultParticleGPUMtl = new Material(); + auto *defaultParticleGPUMtl = ccnew Material(); defaultParticleGPUMtl->setUuid("default-particle-gpu-material"); IMaterialInfo defaultParticleGPUInfo; defaultParticleGPUInfo.effectName = ccstd::string{"particle-gpu"}; @@ -381,7 +381,7 @@ void BuiltinResMgr::initMaterials() { _materialsToBeCompiled.emplace_back(defaultParticleGPUMtl); // default particle material - auto *defaultTrailMtl = new Material(); + auto *defaultTrailMtl = ccnew Material(); defaultTrailMtl->setUuid("default-trail-material"); IMaterialInfo defaultTrailInfo; defaultTrailInfo.effectName = ccstd::string{"particle-trail"}; @@ -390,7 +390,7 @@ void BuiltinResMgr::initMaterials() { _materialsToBeCompiled.emplace_back(defaultTrailMtl); // default particle material - auto *defaultBillboardMtl = new Material(); + auto *defaultBillboardMtl = ccnew Material(); defaultBillboardMtl->setUuid("default-billboard-material"); IMaterialInfo defaultBillboardInfo; defaultBillboardInfo.effectName = ccstd::string{"billboard"}; @@ -399,7 +399,7 @@ void BuiltinResMgr::initMaterials() { _materialsToBeCompiled.emplace_back(defaultBillboardMtl); // ui spine two color material - auto *spineTwoColorMtl = new Material(); + auto *spineTwoColorMtl = ccnew Material(); spineTwoColorMtl->setUuid("default-spine-material"); IMaterialInfo spineTwoColorInfo; spineTwoColorInfo.effectName = ccstd::string{"spine"}, @@ -430,15 +430,15 @@ void BuiltinResMgr::initTexture2DWithUuid(const ccstd::string &uuid, const uint8 IMemoryImageSource imageSource; imageSource.width = width; imageSource.height = height; - imageSource.data = new (std::nothrow) ArrayBuffer(data, static_cast(dataBytes)); + imageSource.data = ccnew ArrayBuffer(data, static_cast(dataBytes)); imageSource.compressed = false; imageSource.format = PixelFormat::RGBA8888; - auto *texture = new (std::nothrow) Texture2D(); + auto *texture = ccnew Texture2D(); if (texture) { texture->setUuid(uuid); - auto *imgAsset = new (std::nothrow) ImageAsset(); + auto *imgAsset = ccnew ImageAsset(); imgAsset->setNativeAsset(imageSource); texture->setImage(imgAsset); @@ -451,27 +451,27 @@ void BuiltinResMgr::initTextureCubeWithUuid(const ccstd::string &uuid, const uin IMemoryImageSource imageSource; imageSource.width = width; imageSource.height = height; - imageSource.data = new (std::nothrow) ArrayBuffer(data, static_cast(dataBytes)); + imageSource.data = ccnew ArrayBuffer(data, static_cast(dataBytes)); imageSource.compressed = false; imageSource.format = PixelFormat::RGBA8888; - auto *texture = new (std::nothrow) TextureCube(); + auto *texture = ccnew TextureCube(); if (texture) { texture->setUuid(uuid); texture->setMipFilter(TextureCube::Filter::NEAREST); ITextureCubeMipmap mipmap; - mipmap.front = new ImageAsset(); + mipmap.front = ccnew ImageAsset(); mipmap.front->setNativeAsset(imageSource); - mipmap.back = new ImageAsset(); + mipmap.back = ccnew ImageAsset(); mipmap.back->setNativeAsset(imageSource); - mipmap.left = new ImageAsset(); + mipmap.left = ccnew ImageAsset(); mipmap.left->setNativeAsset(imageSource); - mipmap.right = new ImageAsset(); + mipmap.right = ccnew ImageAsset(); mipmap.right->setNativeAsset(imageSource); - mipmap.top = new ImageAsset(); + mipmap.top = ccnew ImageAsset(); mipmap.top->setNativeAsset(imageSource); - mipmap.bottom = new ImageAsset(); + mipmap.bottom = ccnew ImageAsset(); mipmap.bottom->setNativeAsset(imageSource); texture->setImage(mipmap); diff --git a/native/cocos/core/geometry/AABB.h b/native/cocos/core/geometry/AABB.h index c53d0a3301..d99bccd271 100644 --- a/native/cocos/core/geometry/AABB.h +++ b/native/cocos/core/geometry/AABB.h @@ -26,6 +26,7 @@ #pragma once #include +#include "base/memory/Memory.h" #include "base/std/container/vector.h" #include "core/geometry/Enums.h" #include "math/Mat3.h" @@ -55,7 +56,7 @@ public: * @returns 返回新创建的 AABB 实例。 */ static AABB *create(float px, float py, float pz, float hw, float hh, float hl) { - return new AABB(px, py, pz, hw, hh, hl); + return ccnew AABB(px, py, pz, hw, hh, hl); } /** diff --git a/native/cocos/core/geometry/Curve.h b/native/cocos/core/geometry/Curve.h index 1c01d5158e..0a1492ee26 100644 --- a/native/cocos/core/geometry/Curve.h +++ b/native/cocos/core/geometry/Curve.h @@ -94,7 +94,7 @@ public: */ auto getKeyFrames() { return Array.from(this._curve.keyframes()).map(([ time, value ]) = > { - const legacyKeyframe = new Keyframe(); + const legacyKeyframe = ccnew Keyframe(); legacyKeyframe.time = time; legacyKeyframe.value = value.value; legacyKeyframe.inTangent = value.leftTangent; @@ -155,7 +155,7 @@ private if (keyFrames instanceof RealCurve) { this._curve = keyFrames; } else { - const curve = new RealCurve(); + const curve = ccnew RealCurve(); this._curve = curve; curve.preExtrapolation = ExtrapolationMode.LOOP; curve.postExtrapolation = ExtrapolationMode.CLAMP; @@ -173,7 +173,7 @@ private } ])); } } - this.cachedKey = new OptimizedKey(); + this.cachedKey = ccnew OptimizedKey(); } /** @@ -350,7 +350,7 @@ function toLegacyWrapMode(extrapolationMode * Same as but more effective than `new LegacyCurve()._internalCurve`. */ export function constructLegacyCurveAndConvert() { - const curve = new RealCurve(); + const curve = ccnew RealCurve(); curve.assignSorted([ [ 0.0, {interpolationMode : RealInterpolationMode.CUBIC, value : 1.0} ], [ 1.0, {interpolationMode : RealInterpolationMode.CUBIC, value : 1.0} ], diff --git a/native/cocos/core/geometry/Frustum.h b/native/cocos/core/geometry/Frustum.h index d87857877f..ae071941cc 100644 --- a/native/cocos/core/geometry/Frustum.h +++ b/native/cocos/core/geometry/Frustum.h @@ -25,6 +25,7 @@ #pragma once +#include "base/memory/Memory.h" #include "base/std/container/array.h" #include "core/geometry/AABB.h" #include "core/geometry/Enums.h" @@ -81,13 +82,13 @@ public: /** * @en - * create a new frustum. + * create a ccnew frustum. * @zh * 创建一个新的截锥体。 * @return {Frustum} frustum. */ static Frustum *create() { - return new Frustum(); + return ccnew Frustum(); } /** @@ -97,7 +98,7 @@ public: * 克隆一个截锥体。 */ static Frustum *clone(const Frustum &f) { - return Frustum::copy(new Frustum(), f); + return Frustum::copy(ccnew Frustum(), f); } /** @@ -128,7 +129,7 @@ public: Frustum() { setType(ShapeEnum::SHAPE_FRUSTUM); for (size_t i = 0; i < planes.size(); ++i) { // NOLINT(modernize-loop-convert) - planes[i] = new Plane(); + planes[i] = ccnew Plane(); planes[i]->addRef(); } } diff --git a/native/cocos/core/geometry/Line.cpp b/native/cocos/core/geometry/Line.cpp index ed5dad90ba..85486dcc53 100644 --- a/native/cocos/core/geometry/Line.cpp +++ b/native/cocos/core/geometry/Line.cpp @@ -1,4 +1,5 @@ #include "core/geometry/Line.h" +#include "base/memory/Memory.h" namespace cc { namespace geometry { @@ -9,11 +10,11 @@ Line *Line::create(float sx, float ex, float ey, float ez) { - return new Line(sx, sy, sz, ex, ey, ez); + return ccnew Line(sx, sy, sz, ex, ey, ez); } Line *Line::clone(const Line &a) { - return new Line( + return ccnew Line( a.s.x, a.s.y, a.s.z, a.e.x, a.e.y, a.e.z); } @@ -54,4 +55,4 @@ Line::Line(float sx, float sy, float sz, float ex, float ey, float ez) { } } // namespace geometry -} // namespace cc \ No newline at end of file +} // namespace cc diff --git a/native/cocos/core/geometry/Obb.cpp b/native/cocos/core/geometry/Obb.cpp index 84ba332b2a..87c0ad342e 100644 --- a/native/cocos/core/geometry/Obb.cpp +++ b/native/cocos/core/geometry/Obb.cpp @@ -1,4 +1,5 @@ #include "cocos/core/geometry/Obb.h" +#include "base/memory/Memory.h" namespace { void transformExtentM3(cc::Vec3 *out, const cc::Vec3 &extent, const cc::Mat3 &m3) { @@ -25,14 +26,14 @@ OBB *OBB::create( float ox1, float ox2, float ox3, float oy1, float oy2, float oy3, float oz1, float oz2, float oz3) { - return new OBB(cx, cy, cz, hw, hh, hl, + return ccnew OBB(cx, cy, cz, hw, hh, hl, ox1, ox2, ox3, oy1, oy2, oy3, oz1, oz2, oz3); } OBB *OBB::clone(const OBB &a) { - return new OBB(a.center.x, a.center.y, a.center.z, + return ccnew OBB(a.center.x, a.center.y, a.center.z, a.halfExtents.x, a.halfExtents.y, a.halfExtents.z, a.orientation.m[0], a.orientation.m[1], a.orientation.m[2], a.orientation.m[3], a.orientation.m[4], a.orientation.m[5], diff --git a/native/cocos/core/geometry/Plane.cpp b/native/cocos/core/geometry/Plane.cpp index 5d1c242ca0..07b3288c07 100644 --- a/native/cocos/core/geometry/Plane.cpp +++ b/native/cocos/core/geometry/Plane.cpp @@ -1,13 +1,14 @@ #include "cocos/core/geometry/Plane.h" +#include "base/memory/Memory.h" namespace cc { namespace geometry { Plane *Plane::create(float nx, float ny, float nz, float d) { - return new Plane{nx, ny, nz, d}; + return ccnew Plane{nx, ny, nz, d}; } Plane *Plane::clone(const Plane &p) { - return new Plane{p.n.x, p.n.y, p.n.z, p.d}; + return ccnew Plane{p.n.x, p.n.y, p.n.z, p.d}; } Plane *Plane::copy(Plane *out, const Plane &p) { @@ -91,4 +92,4 @@ Plane Plane::clone() const { } } // namespace geometry -} // namespace cc \ No newline at end of file +} // namespace cc diff --git a/native/cocos/core/geometry/Ray.cpp b/native/cocos/core/geometry/Ray.cpp index ab361b7556..091675034d 100644 --- a/native/cocos/core/geometry/Ray.cpp +++ b/native/cocos/core/geometry/Ray.cpp @@ -1,13 +1,14 @@ #include "core/geometry/Ray.h" +#include "base/memory/Memory.h" namespace cc { namespace geometry { Ray *Ray::create(float ox, float oy, float oz, float dx, float dy, float dz) { - return new Ray{ox, oy, oz, dx, dy, dz}; + return ccnew Ray{ox, oy, oz, dx, dy, dz}; } Ray *Ray::clone(const Ray &a) { - return new Ray{ + return ccnew Ray{ a.o.x, a.o.y, a.o.z, a.d.x, a.d.y, a.d.z}; } @@ -49,4 +50,4 @@ void Ray::computeHit(Vec3 *out, float distance) const { *out = o + d.getNormalized() * distance; } } // namespace geometry -} // namespace cc \ No newline at end of file +} // namespace cc diff --git a/native/cocos/core/geometry/Sphere.cpp b/native/cocos/core/geometry/Sphere.cpp index d0802564c6..c551ad946d 100644 --- a/native/cocos/core/geometry/Sphere.cpp +++ b/native/cocos/core/geometry/Sphere.cpp @@ -32,11 +32,11 @@ namespace cc { namespace geometry { Sphere *Sphere::create(float cx, float cy, float cz, float radius) { - return new Sphere(cx, cy, cz, radius); + return ccnew Sphere(cx, cy, cz, radius); } Sphere *Sphere::clone(const Sphere &p) { - return new Sphere(p._center.x, p._center.y, p._center.z, p._radius); + return ccnew Sphere(p._center.x, p._center.y, p._center.z, p._radius); } Sphere *Sphere::copy(Sphere *out, const Sphere &p) { diff --git a/native/cocos/core/geometry/Spline.cpp b/native/cocos/core/geometry/Spline.cpp index 8de9280d91..4df43951ed 100644 --- a/native/cocos/core/geometry/Spline.cpp +++ b/native/cocos/core/geometry/Spline.cpp @@ -27,6 +27,7 @@ #include #include "base/Log.h" #include "base/Macros.h" +#include "base/memory/Memory.h" #include "math/Utils.h" namespace cc { @@ -38,11 +39,11 @@ Spline::Spline(SplineMode mode /*= SplineMode::CATMULL_ROM*/, ccstd::vector &knots /*= {}*/) { - return new Spline(mode, knots); + return ccnew Spline(mode, knots); } Spline *Spline::clone(const Spline &s) { - return new Spline(s._mode, s._knots); + return ccnew Spline(s._mode, s._knots); } Spline *Spline::copy(Spline *out, const Spline &s) { diff --git a/native/cocos/core/geometry/Triangle.cpp b/native/cocos/core/geometry/Triangle.cpp index 40a3012073..6ca32037d3 100644 --- a/native/cocos/core/geometry/Triangle.cpp +++ b/native/cocos/core/geometry/Triangle.cpp @@ -1,4 +1,5 @@ #include "core/geometry/Triangle.h" +#include "base/memory/Memory.h" namespace cc { namespace geometry { @@ -6,11 +7,11 @@ namespace geometry { Triangle *Triangle::create(float ax, float ay, float az, float bx, float by, float bz, float cx, float cy, float cz) { - return new Triangle(ax, ay, az, bx, by, bz, cx, cy, cz); + return ccnew Triangle(ax, ay, az, bx, by, bz, cx, cy, cz); } auto Triangle::clone(const Triangle &t) -> Triangle * { - return new Triangle( + return ccnew Triangle( t.a.x, t.a.y, t.a.z, t.b.x, t.b.y, t.b.z, t.c.x, t.c.y, t.c.z); @@ -60,4 +61,4 @@ Triangle::Triangle(float ax, float ay, float az, c = {cx, cy, cz}; } } // namespace geometry -} // namespace cc \ No newline at end of file +} // namespace cc diff --git a/native/cocos/core/scene-graph/Node.cpp b/native/cocos/core/scene-graph/Node.cpp index ca986e1a71..f6a0cada9c 100644 --- a/native/cocos/core/scene-graph/Node.cpp +++ b/native/cocos/core/scene-graph/Node.cpp @@ -88,7 +88,7 @@ Node::Node(const ccstd::string &name) { _name = name; } allNodes.push(this); - _eventProcessor = new NodeEventProcessor(this); + _eventProcessor = ccnew NodeEventProcessor(this); } Node::~Node() { diff --git a/native/cocos/core/scene-graph/NodeEventProcessor.h b/native/cocos/core/scene-graph/NodeEventProcessor.h index 01bd8bbcc2..777fb1ce7a 100644 --- a/native/cocos/core/scene-graph/NodeEventProcessor.h +++ b/native/cocos/core/scene-graph/NodeEventProcessor.h @@ -26,6 +26,7 @@ #pragma once #include +#include "base/memory/Memory.h" #include "base/std/container/string.h" #include "cocos/base/Any.h" #include "core/event/CallbacksInvoker.h" @@ -199,12 +200,12 @@ void NodeEventProcessor::onDispatch(const CallbacksInvoker::KeyType &type, std:: CallbacksInvoker *listeners = nullptr; if (useCapture) { if (_capturingTargets == nullptr) { - _capturingTargets = new CallbacksInvoker(); + _capturingTargets = ccnew CallbacksInvoker(); } listeners = _capturingTargets; } else { if (_bubblingTargets == nullptr) { - _bubblingTargets = new CallbacksInvoker(); + _bubblingTargets = ccnew CallbacksInvoker(); } listeners = _bubblingTargets; } @@ -218,12 +219,12 @@ void NodeEventProcessor::onDispatch(const CallbacksInvoker::KeyType &type, std:: CallbacksInvoker *listeners = nullptr; if (useCapture) { if (_capturingTargets == nullptr) { - _capturingTargets = new CallbacksInvoker(); + _capturingTargets = ccnew CallbacksInvoker(); } listeners = _capturingTargets; } else { if (_bubblingTargets == nullptr) { - _bubblingTargets = new CallbacksInvoker(); + _bubblingTargets = ccnew CallbacksInvoker(); } listeners = _bubblingTargets; } @@ -237,12 +238,12 @@ void NodeEventProcessor::onDispatch(const CallbacksInvoker::KeyType &type, void CallbacksInvoker *listeners = nullptr; if (useCapture) { if (_capturingTargets == nullptr) { - _capturingTargets = new CallbacksInvoker(); + _capturingTargets = ccnew CallbacksInvoker(); } listeners = _capturingTargets; } else { if (_bubblingTargets == nullptr) { - _bubblingTargets = new CallbacksInvoker(); + _bubblingTargets = ccnew CallbacksInvoker(); } listeners = _bubblingTargets; } @@ -259,7 +260,7 @@ void NodeEventProcessor::on(const CallbacksInvoker::KeyType &type, std::function // } else { if (_bubblingTargets == nullptr) { - _bubblingTargets = new CallbacksInvoker(); + _bubblingTargets = ccnew CallbacksInvoker(); } _bubblingTargets->on(type, std::forward>(callback), cbID); } @@ -273,7 +274,7 @@ void NodeEventProcessor::on(const CallbacksInvoker::KeyType &type, std::function // } else { if (_bubblingTargets == nullptr) { - _bubblingTargets = new CallbacksInvoker(); + _bubblingTargets = ccnew CallbacksInvoker(); } _bubblingTargets->on(type, std::forward>(callback), cbID); } @@ -288,7 +289,7 @@ NodeEventProcessor::on(const CallbacksInvoker::KeyType &type, LambdaType &&callb // } else { if (_bubblingTargets == nullptr) { - _bubblingTargets = new CallbacksInvoker(); + _bubblingTargets = ccnew CallbacksInvoker(); } _bubblingTargets->on(type, callback, target, cbID); } @@ -303,7 +304,7 @@ NodeEventProcessor::on(const CallbacksInvoker::KeyType &type, LambdaType &&callb // } else { if (_bubblingTargets == nullptr) { - _bubblingTargets = new CallbacksInvoker(); + _bubblingTargets = ccnew CallbacksInvoker(); } _bubblingTargets->on(type, callback, cbID); } @@ -318,7 +319,7 @@ void NodeEventProcessor::on(const CallbacksInvoker::KeyType &type, void (Target: // } else { if (_bubblingTargets == nullptr) { - _bubblingTargets = new CallbacksInvoker(); + _bubblingTargets = ccnew CallbacksInvoker(); } _bubblingTargets->on(type, memberFn, target); } @@ -334,12 +335,12 @@ void NodeEventProcessor::once(const CallbacksInvoker::KeyType &type, void (Targe CallbacksInvoker *listeners = nullptr; if (useCapture) { if (_capturingTargets == nullptr) { - _capturingTargets = new CallbacksInvoker(); + _capturingTargets = ccnew CallbacksInvoker(); } listeners = _capturingTargets; } else { if (_bubblingTargets == nullptr) { - _bubblingTargets = new CallbacksInvoker(); + _bubblingTargets = ccnew CallbacksInvoker(); } listeners = _bubblingTargets; } @@ -354,12 +355,12 @@ void NodeEventProcessor::once(const CallbacksInvoker::KeyType &type, std::functi CallbacksInvoker *listeners = nullptr; if (useCapture) { if (_capturingTargets == nullptr) { - _capturingTargets = new CallbacksInvoker(); + _capturingTargets = ccnew CallbacksInvoker(); } listeners = _capturingTargets; } else { if (_bubblingTargets == nullptr) { - _bubblingTargets = new CallbacksInvoker(); + _bubblingTargets = ccnew CallbacksInvoker(); } listeners = _bubblingTargets; } diff --git a/native/cocos/core/scene-graph/Scene.cpp b/native/cocos/core/scene-graph/Scene.cpp index 5a6b59a1de..1c77804101 100644 --- a/native/cocos/core/scene-graph/Scene.cpp +++ b/native/cocos/core/scene-graph/Scene.cpp @@ -36,7 +36,7 @@ Scene::Scene(const ccstd::string &name) // _activeInHierarchy is initalized to 'false', so doesn't need to set it to false again // _activeInHierarchy = false; _renderScene = Root::getInstance()->createScene({}); - _globals = new SceneGlobals(); + _globals = ccnew SceneGlobals(); } Scene::Scene() : Scene("") {} diff --git a/native/cocos/core/scene-graph/SceneGlobals.cpp b/native/cocos/core/scene-graph/SceneGlobals.cpp index e83ca78732..983af8fcd0 100644 --- a/native/cocos/core/scene-graph/SceneGlobals.cpp +++ b/native/cocos/core/scene-graph/SceneGlobals.cpp @@ -36,11 +36,11 @@ namespace cc { SceneGlobals::SceneGlobals() { - _ambientInfo = new scene::AmbientInfo(); - _shadowInfo = new scene::ShadowsInfo(); - _skyboxInfo = new scene::SkyboxInfo(); - _fogInfo = new scene::FogInfo(); - _octreeInfo = new scene::OctreeInfo(); + _ambientInfo = ccnew scene::AmbientInfo(); + _shadowInfo = ccnew scene::ShadowsInfo(); + _skyboxInfo = ccnew scene::SkyboxInfo(); + _fogInfo = ccnew scene::FogInfo(); + _octreeInfo = ccnew scene::OctreeInfo(); } void SceneGlobals::activate() { diff --git a/native/cocos/network/Downloader-curl.cpp b/native/cocos/network/Downloader-curl.cpp index e3fbb92fb3..4136a47d69 100644 --- a/native/cocos/network/Downloader-curl.cpp +++ b/native/cocos/network/Downloader-curl.cpp @@ -32,6 +32,7 @@ #include "application/ApplicationManager.h" #include "base/Scheduler.h" +#include "base/memory/Memory.h" #include "base/std/container/deque.h" #include "base/std/container/set.h" #include "base/std/container/vector.h" @@ -667,7 +668,7 @@ DownloaderCURL::~DownloaderCURL() { } IDownloadTask *DownloaderCURL::createCoTask(std::shared_ptr &task) { - DownloadTaskCURL *coTask = new (std::nothrow) DownloadTaskCURL; + DownloadTaskCURL *coTask = ccnew DownloadTaskCURL; coTask->init(task->storagePath, _impl->hints.tempFileNameSuffix); DLLOG(" DownloaderCURL: createTask: Id(%d)", coTask->serialId); diff --git a/native/cocos/network/Downloader-java.cpp b/native/cocos/network/Downloader-java.cpp index 0d70a74ffe..2dc7d194b1 100644 --- a/native/cocos/network/Downloader-java.cpp +++ b/native/cocos/network/Downloader-java.cpp @@ -28,6 +28,7 @@ #include #include "application/ApplicationManager.h" +#include "base/memory/Memory.h" #include "network/Downloader.h" #include "platform/java/jni/JniHelper.h" #include "platform/java/jni/JniImp.h" @@ -137,7 +138,7 @@ DownloaderJava::~DownloaderJava() { } IDownloadTask *DownloaderJava::createCoTask(std::shared_ptr &task) { - auto *coTask = new DownloadTaskAndroid; + auto *coTask = ccnew DownloadTaskAndroid; coTask->task = task; JniMethodInfo methodInfo; diff --git a/native/cocos/network/Downloader.cpp b/native/cocos/network/Downloader.cpp index 752f845dda..ed383b4cb4 100644 --- a/native/cocos/network/Downloader.cpp +++ b/native/cocos/network/Downloader.cpp @@ -26,7 +26,7 @@ ****************************************************************************/ #include - +#include "base/memory/Memory.h" #include "network/Downloader.h" // include platform specific implement class @@ -66,7 +66,7 @@ Downloader::Downloader() { 6, 45, ".tmp"}; - new (this) Downloader(hints); + ccnew_placement(this) Downloader(hints); } Downloader::Downloader(const DownloaderHints &hints) { @@ -113,7 +113,7 @@ Downloader::~Downloader() { } std::shared_ptr Downloader::createDownloadDataTask(const ccstd::string &srcUrl, const ccstd::string &identifier /* = ""*/) { - auto * iTask = new (std::nothrow) DownloadTask(); + auto * iTask = ccnew DownloadTask(); std::shared_ptr task(iTask); do { iTask->requestURL = srcUrl; @@ -135,7 +135,7 @@ std::shared_ptr Downloader::createDownloadFileTask(const ccs const ccstd::string & storagePath, const ccstd::unordered_map &header, const ccstd::string & identifier /* = ""*/) { - auto * iTask = new (std::nothrow) DownloadTask(); + auto * iTask = ccnew DownloadTask(); std::shared_ptr task(iTask); do { iTask->requestURL = srcUrl; diff --git a/native/cocos/network/DownloaderImpl-apple.mm b/native/cocos/network/DownloaderImpl-apple.mm index a4b57f6d8f..756c33a4fb 100644 --- a/native/cocos/network/DownloaderImpl-apple.mm +++ b/native/cocos/network/DownloaderImpl-apple.mm @@ -26,9 +26,10 @@ #include "network/DownloaderImpl-apple.h" #import +#include "base/memory/Memory.h" #include "base/std/container/queue.h" -#include "network/Downloader.h" #include "base/UTF8.h" +#include "network/Downloader.h" //////////////////////////////////////////////////////////////////////////////// // OC Classes Declaration @@ -98,7 +99,7 @@ DownloaderApple::~DownloaderApple() { DLLOG("Destruct DownloaderApple %p", this); } IDownloadTask *DownloaderApple::createCoTask(std::shared_ptr &task) { - DownloadTaskApple *coTask = new (std::nothrow) DownloadTaskApple(); + DownloadTaskApple *coTask = ccnew DownloadTaskApple(); DeclareDownloaderImplVar; if (task->storagePath.length()) { coTask->downloadTask = [impl createFileTask:task]; diff --git a/native/cocos/network/HttpClient-apple.mm b/native/cocos/network/HttpClient-apple.mm index 8ce670264c..5fc48fcdb2 100644 --- a/native/cocos/network/HttpClient-apple.mm +++ b/native/cocos/network/HttpClient-apple.mm @@ -68,7 +68,7 @@ void HttpClient::networkThread() { } // Create a HttpResponse object, the default setting is http access failed - HttpResponse *response = new (std::nothrow) HttpResponse(request); + HttpResponse *response = ccnew HttpResponse(request); response->addRef(); processResponse(response, _responseMessage); @@ -274,7 +274,7 @@ static int processTask(HttpClient *client, HttpRequest *request, NSString *reque // HttpClient implementation HttpClient *HttpClient::getInstance() { if (_httpClient == nullptr) { - _httpClient = new (std::nothrow) HttpClient(); + _httpClient = ccnew HttpClient(); } return _httpClient; @@ -319,7 +319,7 @@ void HttpClient::enableCookies(const char *cookieFile) { _cookieFileMutex.unlock(); if (nullptr == _cookie) { - _cookie = new (std::nothrow) HttpCookie; + _cookie = ccnew HttpCookie; } _cookie->setCookieFileName(_cookieFilename); _cookie->readFile(); @@ -337,7 +337,7 @@ HttpClient::HttpClient() _threadCount(0), _cookie(nullptr) { CC_LOG_DEBUG("In the constructor of HttpClient!"); - _requestSentinel = new HttpRequest(); + _requestSentinel = ccnew HttpRequest(); _requestSentinel->addRef(); memset(_responseMessage, 0, sizeof(char) * RESPONSE_BUFFER_SIZE); _scheduler = CC_CURRENT_ENGINE()->getScheduler(); @@ -393,8 +393,8 @@ void HttpClient::sendImmediate(HttpRequest *request) { request->addRef(); // Create a HttpResponse object, the default setting is http access failed - HttpResponse *response = new (std::nothrow) HttpResponse(request); - response->addRef(); // NOTE: RefCounted object's reference count is changed to 0 now. so needs to addRef after new. + HttpResponse *response = ccnew HttpResponse(request); + response->addRef(); // NOTE: RefCounted object's reference count is changed to 0 now. so needs to addRef after ccnew. auto t = std::thread(&HttpClient::networkThreadAlone, this, request, response); t.detach(); diff --git a/native/cocos/network/HttpClient-java.cpp b/native/cocos/network/HttpClient-java.cpp index 1f6784adfb..952bcd3ec7 100644 --- a/native/cocos/network/HttpClient-java.cpp +++ b/native/cocos/network/HttpClient-java.cpp @@ -719,8 +719,8 @@ void HttpClient::networkThread() { } // Create a HttpResponse object, the default setting is http access failed - auto *response = new (std::nothrow) HttpResponse(request); - response->addRef(); // NOTE: RefCounted object's reference count is changed to 0 now. so needs to addRef after new. + auto *response = ccnew HttpResponse(request); + response->addRef(); // NOTE: RefCounted object's reference count is changed to 0 now. so needs to addRef after ccnew. processResponse(response, _responseMessage); // add response packet into queue @@ -775,7 +775,7 @@ void HttpClient::networkThreadAlone(HttpRequest *request, HttpResponse *response // HttpClient implementation HttpClient *HttpClient::getInstance() { if (gHttpClient == nullptr) { - gHttpClient = new (std::nothrow) HttpClient(); + gHttpClient = ccnew HttpClient(); } return gHttpClient; @@ -829,7 +829,7 @@ HttpClient::HttpClient() _timeoutForRead(60), _threadCount(0), _cookie(nullptr), - _requestSentinel(new HttpRequest()) { + _requestSentinel(ccnew HttpRequest()) { CC_LOG_DEBUG("In the constructor of HttpClient!"); increaseThreadCount(); _scheduler = CC_CURRENT_ENGINE()->getScheduler(); @@ -880,8 +880,8 @@ void HttpClient::sendImmediate(HttpRequest *request) { request->addRef(); // Create a HttpResponse object, the default setting is http access failed - auto *response = new (std::nothrow) HttpResponse(request); - response->addRef(); // NOTE: RefCounted object's reference count is changed to 0 now. so needs to addRef after new. + auto *response = ccnew HttpResponse(request); + response->addRef(); // NOTE: RefCounted object's reference count is changed to 0 now. so needs to addRef after ccnew. auto t = std::thread(&HttpClient::networkThreadAlone, this, request, response); t.detach(); } diff --git a/native/cocos/network/HttpClient.cpp b/native/cocos/network/HttpClient.cpp index d04bbf2e11..c12fad3162 100644 --- a/native/cocos/network/HttpClient.cpp +++ b/native/cocos/network/HttpClient.cpp @@ -101,8 +101,8 @@ void HttpClient::networkThread() { // step 2: libcurl sync access // Create a HttpResponse object, the default setting is http access failed - HttpResponse *response = new (std::nothrow) HttpResponse(request); - response->addRef(); // NOTE: RefCounted object's reference count is changed to 0 now. so needs to addRef after new. + HttpResponse *response = ccnew HttpResponse(request); + response->addRef(); // NOTE: RefCounted object's reference count is changed to 0 now. so needs to addRef after ccnew. processResponse(response, _responseMessage); @@ -307,7 +307,7 @@ static int processDeleteTask(HttpClient *client, HttpRequest *request, write_cal // HttpClient implementation HttpClient *HttpClient::getInstance() { if (_httpClient == nullptr) { - _httpClient = new (std::nothrow) HttpClient(); + _httpClient = ccnew HttpClient(); } return _httpClient; @@ -361,7 +361,7 @@ HttpClient::HttpClient() _timeoutForRead(60), _threadCount(0), _cookie(nullptr), - _requestSentinel(new HttpRequest()) { + _requestSentinel(ccnew HttpRequest()) { CC_LOG_DEBUG("In the constructor of HttpClient!"); memset(_responseMessage, 0, RESPONSE_BUFFER_SIZE * sizeof(char)); _scheduler = CC_CURRENT_ENGINE()->getScheduler(); @@ -413,8 +413,8 @@ void HttpClient::sendImmediate(HttpRequest *request) { request->addRef(); // Create a HttpResponse object, the default setting is http access failed - HttpResponse *response = new (std::nothrow) HttpResponse(request); - response->addRef(); // NOTE: RefCounted object's reference count is changed to 0 now. so needs to addRef after new. + HttpResponse *response = ccnew HttpResponse(request); + response->addRef(); // NOTE: RefCounted object's reference count is changed to 0 now. so needs to addRef after ccnew. auto t = std::thread(&HttpClient::networkThreadAlone, this, request, response); t.detach(); diff --git a/native/cocos/network/SocketIO.cpp b/native/cocos/network/SocketIO.cpp index 6563cf1dbb..833e23e1da 100644 --- a/native/cocos/network/SocketIO.cpp +++ b/native/cocos/network/SocketIO.cpp @@ -269,10 +269,10 @@ SocketIOPacket *SocketIOPacket::createPacketWithType(const ccstd::string &type, SocketIOPacket *ret; switch (version) { case SocketIOPacket::SocketIOVersion::V09X: - ret = new (std::nothrow) SocketIOPacket; + ret = ccnew SocketIOPacket; break; case SocketIOPacket::SocketIOVersion::V10X: - ret = new (std::nothrow) SocketIOPacketV10x; + ret = ccnew SocketIOPacketV10x; break; } ret->initWithType(type); @@ -283,10 +283,10 @@ SocketIOPacket *SocketIOPacket::createPacketWithTypeIndex(int type, SocketIOPack SocketIOPacket *ret; switch (version) { case SocketIOPacket::SocketIOVersion::V09X: - ret = new (std::nothrow) SocketIOPacket; + ret = ccnew SocketIOPacket; break; case SocketIOPacket::SocketIOVersion::V10X: - return new (std::nothrow) SocketIOPacketV10x; + return ccnew SocketIOPacketV10x; break; } ret->initWithTypeIndex(type); @@ -369,7 +369,7 @@ void SIOClientImpl::handshake() { pre << _uri.getAuthority() << "/socket.io/1/?EIO=2&transport=polling&b64=true"; - auto *request = new (std::nothrow) HttpRequest(); + auto *request = ccnew HttpRequest(); request->setUrl(pre.str()); request->setRequestType(HttpRequest::Type::GET); @@ -516,7 +516,7 @@ void SIOClientImpl::openSocket() { break; } - _ws = new (std::nothrow) WebSocket(); + _ws = ccnew WebSocket(); if (!_ws->init(*this, s.str(), nullptr, _caFilePath)) { CC_SAFE_RELEASE_NULL(_ws); } @@ -557,7 +557,7 @@ void SIOClientImpl::disconnect() { } SIOClientImpl *SIOClientImpl::create(const Uri &uri, const ccstd::string &caFilePath) { - auto *s = new (std::nothrow) SIOClientImpl(uri, caFilePath); + auto *s = ccnew SIOClientImpl(uri, caFilePath); if (s && s->init()) { return s; @@ -987,7 +987,7 @@ SocketIO::~SocketIO() = default; SocketIO *SocketIO::getInstance() { if (nullptr == inst) { - inst = new (std::nothrow) SocketIO(); + inst = ccnew SocketIO(); } return inst; @@ -1020,7 +1020,7 @@ SIOClient *SocketIO::connect(const ccstd::string &uri, SIODelegate &delegate, co //create a new socket, new client, connect socket = SIOClientImpl::create(uriObj, caFilePath); - c = new (std::nothrow) SIOClient(path, socket, delegate); + c = ccnew SIOClient(path, socket, delegate); socket->addClient(path, c); @@ -1030,7 +1030,7 @@ SIOClient *SocketIO::connect(const ccstd::string &uri, SIODelegate &delegate, co c = socket->getClient(path); if (c == nullptr) { - c = new (std::nothrow) SIOClient(path, socket, delegate); + c = ccnew SIOClient(path, socket, delegate); socket->addClient(path, c); @@ -1041,7 +1041,7 @@ SIOClient *SocketIO::connect(const ccstd::string &uri, SIODelegate &delegate, co CC_LOG_DEBUG("SocketIO: recreate a new socket, new client, connect"); SIOClientImpl *newSocket = SIOClientImpl::create(uriObj, caFilePath); - auto * newC = new (std::nothrow) SIOClient(path, newSocket, delegate); + auto * newC = ccnew SIOClient(path, newSocket, delegate); newSocket->addClient(path, newC); newSocket->connect(); diff --git a/native/cocos/network/WebSocket-libwebsockets.cpp b/native/cocos/network/WebSocket-libwebsockets.cpp index 975c30661c..dc758623cd 100644 --- a/native/cocos/network/WebSocket-libwebsockets.cpp +++ b/native/cocos/network/WebSocket-libwebsockets.cpp @@ -97,7 +97,7 @@ static void _winLog(const char *format, va_list args) { char * buf = nullptr; do { - buf = new (std::nothrow) char[bufferSize]; + buf = ccnew char[bufferSize]; if (buf == nullptr) return; // not enough memory @@ -419,7 +419,7 @@ public: WsThreadHelper::WsThreadHelper() { - _subThreadWsMessageQueue = new (std::nothrow) ccstd::list(); + _subThreadWsMessageQueue = ccnew ccstd::list(); } WsThreadHelper::~WsThreadHelper() { @@ -430,7 +430,7 @@ WsThreadHelper::~WsThreadHelper() { bool WsThreadHelper::createWebSocketThread() { // Creates websocket thread - _subThreadInstance = new (std::nothrow) std::thread(&WsThreadHelper::wsThreadEntryFunc, this); + _subThreadInstance = ccnew std::thread(&WsThreadHelper::wsThreadEntryFunc, this); return true; } @@ -610,7 +610,7 @@ WebSocketImpl::WebSocketImpl(cc::network::WebSocket *ws) { std::lock_guard lk(instanceMutex); if (websocketInstances == nullptr) { - websocketInstances = new (std::nothrow) ccstd::vector(); + websocketInstances = ccnew ccstd::vector(); } websocketInstances->push_back(this); } @@ -698,11 +698,11 @@ bool WebSocketImpl::init(const cc::network::WebSocket::Delegate &delegate, bool isWebSocketThreadCreated = true; if (wsHelper == nullptr) { - wsHelper = new (std::nothrow) WsThreadHelper(); + wsHelper = ccnew WsThreadHelper(); isWebSocketThreadCreated = false; } - auto *msg = new (std::nothrow) WsMessage(); + auto *msg = ccnew WsMessage(); msg->what = WS_MSG_TO_SUBTHREAD_CREATE_CONNECTION; msg->user = this; wsHelper->sendMessageToWebSocketThread(msg); @@ -742,14 +742,14 @@ ccstd::string WebSocketImpl::getExtensions() const { void WebSocketImpl::send(const ccstd::string &message) { if (_readyState == cc::network::WebSocket::State::OPEN) { // In main thread - auto *data = new (std::nothrow) cc::network::WebSocket::Data(); + auto *data = ccnew cc::network::WebSocket::Data(); data->bytes = static_cast(malloc(message.length() + 1)); // Make sure the last byte is '\0' data->bytes[message.length()] = '\0'; strcpy(data->bytes, message.c_str()); data->len = static_cast(message.length()); - auto *msg = new (std::nothrow) WsMessage(); + auto *msg = ccnew WsMessage(); msg->what = WS_MSG_TO_SUBTRHEAD_SENDING_STRING; msg->data = data; msg->user = this; @@ -762,7 +762,7 @@ void WebSocketImpl::send(const ccstd::string &message) { void WebSocketImpl::send(const unsigned char *binaryMsg, unsigned int len) { if (_readyState == cc::network::WebSocket::State::OPEN) { // In main thread - auto *data = new (std::nothrow) cc::network::WebSocket::Data(); + auto *data = ccnew cc::network::WebSocket::Data(); if (len == 0) { // If data length is zero, allocate 1 byte for safe. data->bytes = static_cast(malloc(1)); @@ -773,7 +773,7 @@ void WebSocketImpl::send(const unsigned char *binaryMsg, unsigned int len) { } data->len = len; - auto *msg = new (std::nothrow) WsMessage(); + auto *msg = ccnew WsMessage(); msg->what = WS_MSG_TO_SUBTRHEAD_SENDING_BINARY; msg->data = data; msg->user = this; @@ -1037,7 +1037,7 @@ int WebSocketImpl::onClientWritable() { if (data->ext) { frame = static_cast(data->ext); } else { - frame = new (std::nothrow) WebSocketFrame(); + frame = ccnew WebSocketFrame(); bool success = frame && frame->init(reinterpret_cast(data->bytes + data->issued), n); if (success) { data->ext = frame; @@ -1153,7 +1153,7 @@ int WebSocketImpl::onClientReceivedData(void *in, ssize_t len) { // LOGD("remainingSize: %d, isFinalFragment: %d\n", (int)remainingSize, isFinalFragment); if (remainingSize == 0 && isFinalFragment) { - auto *frameData = new (std::nothrow) ccstd::vector(std::move(_receivedData)); + auto *frameData = ccnew ccstd::vector(std::move(_receivedData)); // reset capacity of received data buffer _receivedData.reserve(WS_RESERVE_RECEIVE_BUFFER_SIZE); @@ -1345,7 +1345,7 @@ void WebSocket::closeAllConnections() { } WebSocket::WebSocket() { - _impl = new (std::nothrow) WebSocketImpl(this); + _impl = ccnew WebSocketImpl(this); } WebSocket::~WebSocket() { diff --git a/native/cocos/network/WebSocket-okhttp.cpp b/native/cocos/network/WebSocket-okhttp.cpp index 263f6b4d88..95114361ec 100644 --- a/native/cocos/network/WebSocket-okhttp.cpp +++ b/native/cocos/network/WebSocket-okhttp.cpp @@ -4,6 +4,7 @@ #include "application/ApplicationManager.h" #include "base/Scheduler.h" #include "base/UTF8.h" +#include "base/memory/Memory.h" #include "platform/FileUtils.h" #include "platform/java/jni/JniHelper.h" @@ -254,7 +255,7 @@ void WebSocket::closeAllConnections() { } WebSocket::WebSocket() { - _impl = new (std::nothrow) WebSocketImpl(this); + _impl = ccnew WebSocketImpl(this); } WebSocket::~WebSocket() { @@ -402,4 +403,4 @@ JNI_PATH(nativeOnError)(JNIEnv * /*env*/, #undef JNI_PATH } -#undef HANDLE_TO_WS_OKHTTP3 \ No newline at end of file +#undef HANDLE_TO_WS_OKHTTP3 diff --git a/native/cocos/network/WebSocketServer.cpp b/native/cocos/network/WebSocketServer.cpp index 5d9772b4c1..8a19b3a3fd 100644 --- a/native/cocos/network/WebSocketServer.cpp +++ b/native/cocos/network/WebSocketServer.cpp @@ -27,9 +27,10 @@ #include #include -#include "cocos/application/ApplicationManager.h" -#include "cocos/base/Log.h" -#include "cocos/base/Scheduler.h" +#include "application/ApplicationManager.h" +#include "base/Log.h" +#include "base/Scheduler.h" +#include "base/memory/Memory.h" #include "cocos/network/WebSocketServer.h" #define MAX_MSG_PAYLOAD 2048 @@ -74,7 +75,7 @@ void flush_tasks_in_server_loop_cb(uv_async_t *asyn) { void init_libuv_async_handle(uv_loop_t *loop, uv_async_t *async) { memset(async, 0, sizeof(uv_async_t)); uv_async_init(loop, async, flush_tasks_in_server_loop_cb); - async->data = new AsyncTaskData(); + async->data = ccnew AsyncTaskData(); } // run in game thread, dispatch runnable object into server loop diff --git a/native/cocos/physics/physx/PhysXEventManager.cpp b/native/cocos/physics/physx/PhysXEventManager.cpp index 6705c0451d..abb61cabc8 100644 --- a/native/cocos/physics/physx/PhysXEventManager.cpp +++ b/native/cocos/physics/physx/PhysXEventManager.cpp @@ -53,7 +53,7 @@ void PhysXEventManager::SimulationEventCallback::onTrigger(physx::PxTriggerPair return (pair->shapeA == self || pair->shapeA == other) && (pair->shapeB == self || pair->shapeB == other); }); if (tp.status & physx::PxPairFlag::eNOTIFY_TOUCH_FOUND) { - if (iter == pairs.end()) pairs.push_back(std::shared_ptr(new TriggerEventPair{self, other})); + if (iter == pairs.end()) pairs.push_back(std::shared_ptr(ccnew TriggerEventPair{self, other})); } else if (tp.status & physx::PxPairFlag::eNOTIFY_TOUCH_LOST) { if (iter != pairs.end()) iter->get()->state = ETouchState::EXIT; } @@ -81,7 +81,7 @@ void PhysXEventManager::SimulationEventCallback::onContact(const physx::PxContac }); if (iter == pairs.end()) { - pairs.push_back(std::shared_ptr(new ContactEventPair{self, other})); + pairs.push_back(std::shared_ptr(ccnew ContactEventPair{self, other})); iter = pairs.end() - 1; } diff --git a/native/cocos/physics/physx/PhysXEventManager.h b/native/cocos/physics/physx/PhysXEventManager.h index ddec770ef1..10fe88508e 100644 --- a/native/cocos/physics/physx/PhysXEventManager.h +++ b/native/cocos/physics/physx/PhysXEventManager.h @@ -27,6 +27,7 @@ #include #include "base/Macros.h" +#include "base/memory/Memory.h" #include "base/std/container/vector.h" #include "physics/physx/PhysXInc.h" #include "physics/spec/IWorld.h" @@ -37,7 +38,7 @@ namespace physics { class PhysXEventManager final { public: PhysXEventManager() { - _mCallback = new SimulationEventCallback(this); + _mCallback = ccnew SimulationEventCallback(this); } ~PhysXEventManager() { diff --git a/native/cocos/physics/physx/PhysXSharedBody.cpp b/native/cocos/physics/physx/PhysXSharedBody.cpp index 09529506b0..f37ed03777 100644 --- a/native/cocos/physics/physx/PhysXSharedBody.cpp +++ b/native/cocos/physics/physx/PhysXSharedBody.cpp @@ -25,6 +25,7 @@ #include "physics/physx/PhysXSharedBody.h" #include +#include "base/memory/Memory.h" #include "physics/physx/PhysXInc.h" #include "physics/physx/PhysXUtils.h" #include "physics/physx/PhysXWorld.h" @@ -71,7 +72,7 @@ PhysXSharedBody *PhysXSharedBody::getSharedBody(const Node *node, PhysXWorld *co if (iter != sharedBodesMap.end()) { newSB = iter->second; } else { - newSB = new PhysXSharedBody(const_cast(node), world, body); + newSB = ccnew PhysXSharedBody(const_cast(node), world, body); newSB->_mFilterData.word0 = 1; newSB->_mFilterData.word1 = world->getMaskByIndex(0); sharedBodesMap.insert(std::pair(const_cast(node), newSB)); diff --git a/native/cocos/physics/physx/PhysXWorld.cpp b/native/cocos/physics/physx/PhysXWorld.cpp index ca4a8aef27..9ce7fb5efc 100644 --- a/native/cocos/physics/physx/PhysXWorld.cpp +++ b/native/cocos/physics/physx/PhysXWorld.cpp @@ -24,6 +24,7 @@ ****************************************************************************/ #include "physics/physx/PhysXWorld.h" +#include "base/memory/Memory.h" #include "physics/physx/PhysXFilterShader.h" #include "physics/physx/PhysXInc.h" #include "physics/physx/PhysXUtils.h" @@ -68,7 +69,7 @@ PhysXWorld::PhysXWorld() { PxInitExtensions(*_mPhysics, pvd); _mDispatcher = physx::PxDefaultCpuDispatcherCreate(0); - _mEventMgr = new PhysXEventManager(); + _mEventMgr = ccnew PhysXEventManager(); physx::PxSceneDesc sceneDesc(_mPhysics->getTolerancesScale()); sceneDesc.gravity = physx::PxVec3(0.0F, -10.0F, 0.0F); @@ -155,7 +156,7 @@ uintptr_t PhysXWorld::createHeightField(HeightFieldDesc &desc) { const auto rows = desc.rows; const auto columns = desc.columns; const physx::PxU32 counts = rows * columns; - auto * samples = new physx::PxHeightFieldSample[counts]; + auto * samples = ccnew physx::PxHeightFieldSample[counts]; for (physx::PxU32 r = 0; r < rows; r++) { for (physx::PxU32 c = 0; c < columns; c++) { const auto index = c + r * columns; diff --git a/native/cocos/physics/sdk/Joint.cpp b/native/cocos/physics/sdk/Joint.cpp index 9435f862b6..916295e91e 100644 --- a/native/cocos/physics/sdk/Joint.cpp +++ b/native/cocos/physics/sdk/Joint.cpp @@ -24,12 +24,13 @@ ****************************************************************************/ #include "physics/sdk/Joint.h" +#include "base/memory/Memory.h" #include "physics/PhysicsSelector.h" #define CC_PHYSICS_JOINT_DEFINITION(CLASS, WRAPPED) \ \ CLASS::CLASS() { \ - _impl.reset(new WRAPPED()); \ + _impl.reset(ccnew WRAPPED()); \ } \ \ CLASS::~CLASS() { \ diff --git a/native/cocos/physics/sdk/Shape.cpp b/native/cocos/physics/sdk/Shape.cpp index 111cbdee9b..3adbbf0bd9 100644 --- a/native/cocos/physics/sdk/Shape.cpp +++ b/native/cocos/physics/sdk/Shape.cpp @@ -24,12 +24,13 @@ ****************************************************************************/ #include "physics/sdk/Shape.h" +#include "base/memory/Memory.h" #include "physics/PhysicsSelector.h" #define CC_PHYSICS_SHAPE_DEFINITION(CLASS, WRAPPED) \ \ CLASS::CLASS() { \ - _impl.reset(new WRAPPED()); \ + _impl.reset(ccnew WRAPPED()); \ } \ \ CLASS::~CLASS() { \ diff --git a/native/cocos/platform/FileUtils.cpp b/native/cocos/platform/FileUtils.cpp index e8af3d6edb..060589da26 100644 --- a/native/cocos/platform/FileUtils.cpp +++ b/native/cocos/platform/FileUtils.cpp @@ -309,7 +309,7 @@ bool FileUtils::writeToFile(const ValueMap &dict, const ccstd::string &fullPath) } bool FileUtils::writeValueMapToFile(const ValueMap &dict, const ccstd::string &fullPath) { - auto *doc = new (std::nothrow) tinyxml2::XMLDocument(); + auto *doc = ccnew tinyxml2::XMLDocument(); if (nullptr == doc) { return false; } @@ -346,7 +346,7 @@ bool FileUtils::writeValueMapToFile(const ValueMap &dict, const ccstd::string &f } bool FileUtils::writeValueVectorToFile(const ValueVector &vecData, const ccstd::string &fullPath) { - auto *doc = new (std::nothrow) tinyxml2::XMLDocument(); + auto *doc = ccnew tinyxml2::XMLDocument(); if (nullptr == doc) { return false; } diff --git a/native/cocos/platform/android/FileUtils-android.cpp b/native/cocos/platform/android/FileUtils-android.cpp index 44cd69a177..609afda1cf 100644 --- a/native/cocos/platform/android/FileUtils-android.cpp +++ b/native/cocos/platform/android/FileUtils-android.cpp @@ -33,6 +33,7 @@ #include "android/asset_manager_jni.h" #include "base/Log.h" #include "base/ZipUtils.h" +#include "base/memory/Memory.h" #include "platform/java/jni/JniHelper.h" #include "platform/java/jni/JniImp.h" @@ -61,7 +62,7 @@ void FileUtilsAndroid::setassetmanager(AAssetManager *a) { FileUtils *FileUtils::getInstance() { if (FileUtils::sharedFileUtils == nullptr) { - FileUtils::sharedFileUtils = new FileUtilsAndroid(); + FileUtils::sharedFileUtils = ccnew FileUtilsAndroid(); if (!FileUtils::sharedFileUtils->init()) { delete FileUtils::sharedFileUtils; FileUtils::sharedFileUtils = nullptr; @@ -85,7 +86,7 @@ bool FileUtilsAndroid::init() { ccstd::string assetsPath(getObbFilePathJNI()); if (assetsPath.find("/obb/") != ccstd::string::npos) { - obbfile = new ZipFile(assetsPath); + obbfile = ccnew ZipFile(assetsPath); } return FileUtils::init(); diff --git a/native/cocos/platform/apple/FileUtils-apple.mm b/native/cocos/platform/apple/FileUtils-apple.mm index 06bc980030..2549dc4684 100644 --- a/native/cocos/platform/apple/FileUtils-apple.mm +++ b/native/cocos/platform/apple/FileUtils-apple.mm @@ -31,13 +31,12 @@ #include "platform/apple/FileUtils-apple.h" #include - -#include "base/std/container/string.h" #include - +#include "base/Log.h" +#include "base/memory/Memory.h" +#include "base/std/container/string.h" #include "platform/FileUtils.h" #include "platform/SAXParser.h" -#include "base/Log.h" namespace cc { @@ -179,7 +178,7 @@ static void addCCValueToNSDictionary(const ccstd::string &key, const Value &valu [dict setObject:convertCCValueToNSObject(value) forKey:NSkey]; } -FileUtilsApple::FileUtilsApple() : pimpl_(new IMPL([NSBundle mainBundle])) { +FileUtilsApple::FileUtilsApple() : pimpl_(ccnew IMPL([NSBundle mainBundle])) { } FileUtilsApple::~FileUtilsApple() = default; @@ -196,7 +195,7 @@ static NSFileManager *s_fileManager = [NSFileManager defaultManager]; FileUtils *FileUtils::getInstance() { if (FileUtils::sharedFileUtils == nullptr) { - FileUtils::sharedFileUtils = new (std::nothrow) FileUtilsApple(); + FileUtils::sharedFileUtils = ccnew FileUtilsApple(); if (!FileUtils::sharedFileUtils->init()) { delete FileUtils::sharedFileUtils; FileUtils::sharedFileUtils = nullptr; diff --git a/native/cocos/platform/apple/Reachability.cpp b/native/cocos/platform/apple/Reachability.cpp index 8474f939dd..c2a952623f 100644 --- a/native/cocos/platform/apple/Reachability.cpp +++ b/native/cocos/platform/apple/Reachability.cpp @@ -24,15 +24,15 @@ ****************************************************************************/ #include "Reachability.h" -#include "base/DeferredReleasePool.h" -#include "base/Macros.h" - #include #include #include #include #include #include +#include "base/DeferredReleasePool.h" +#include "base/Macros.h" +#include "base/memory/Memory.h" namespace { @@ -109,7 +109,7 @@ Reachability *Reachability::createWithHostName(const ccstd::string &hostName) { Reachability * returnValue = nullptr; SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(nullptr, hostName.c_str()); if (reachability != nullptr) { - returnValue = new (std::nothrow) Reachability(); + returnValue = ccnew Reachability(); returnValue->addRef(); if (returnValue != nullptr) { cc::DeferredReleasePool::add(returnValue); @@ -127,7 +127,7 @@ Reachability *Reachability::createWithAddress(const struct sockaddr *hostAddress Reachability *returnValue = nullptr; if (reachability != nullptr) { - returnValue = new (std::nothrow) Reachability(); + returnValue = ccnew Reachability(); returnValue->addRef(); if (returnValue != nullptr) { cc::DeferredReleasePool::add(returnValue); diff --git a/native/cocos/platform/interfaces/modules/canvas/CanvasRenderingContext2D.cpp b/native/cocos/platform/interfaces/modules/canvas/CanvasRenderingContext2D.cpp index 44b95c09be..50ff442b10 100644 --- a/native/cocos/platform/interfaces/modules/canvas/CanvasRenderingContext2D.cpp +++ b/native/cocos/platform/interfaces/modules/canvas/CanvasRenderingContext2D.cpp @@ -83,7 +83,7 @@ void CanvasGradient::addColorStop(float offset, const ccstd::string &color) { CanvasRenderingContext2D::CanvasRenderingContext2D(float width, float height) : _width(width), _height(height) { - _delegate = new CanvasRenderingContext2DDelegate(); + _delegate = ccnew CanvasRenderingContext2DDelegate(); //SE_LOGD("CanvasRenderingContext2D constructor: %p, width: %f, height: %f\n", this, width, height); } diff --git a/native/cocos/platform/linux/FileUtils-linux.cpp b/native/cocos/platform/linux/FileUtils-linux.cpp index 35c098f343..00c54ae8e7 100644 --- a/native/cocos/platform/linux/FileUtils-linux.cpp +++ b/native/cocos/platform/linux/FileUtils-linux.cpp @@ -29,6 +29,7 @@ #include #include #include "base/Log.h" +#include "base/memory/Memory.h" #define DECLARE_GUARD std::lock_guard mutexGuard(_mutex) #ifndef CC_RESOURCE_FOLDER_LINUX @@ -39,7 +40,7 @@ namespace cc { FileUtils *FileUtils::getInstance() { if (FileUtils::sharedFileUtils == nullptr) { - FileUtils::sharedFileUtils = new FileUtilsLinux(); + FileUtils::sharedFileUtils = ccnew FileUtilsLinux(); if (!FileUtils::sharedFileUtils->init()) { delete FileUtils::sharedFileUtils; FileUtils::sharedFileUtils = nullptr; diff --git a/native/cocos/platform/ohos/FileUtils-ohos.cpp b/native/cocos/platform/ohos/FileUtils-ohos.cpp index c80598336e..4f6f13c297 100644 --- a/native/cocos/platform/ohos/FileUtils-ohos.cpp +++ b/native/cocos/platform/ohos/FileUtils-ohos.cpp @@ -23,17 +23,17 @@ THE SOFTWARE. ****************************************************************************/ -#include "cocos/platform/ohos/FileUtils-ohos.h" -#include -#include +#include "platform/ohos/FileUtils-ohos.h" #include +#include #include -#include "base/std/container/string.h" -#include "cocos/base/Log.h" -#include "cocos/platform/java/jni/JniHelper.h" - +#include #include #include +#include "base/std/container/string.h" +#include "base/memory/Memory.h" +#include "base/Log.h" +#include "platform/java/jni/JniHelper.h" #define ASSETS_FOLDER_NAME "@assets/" @@ -97,7 +97,7 @@ ResourceManager *FileUtilsOHOS::getResourceManager() { FileUtils *FileUtils::getInstance() { if (FileUtils::sharedFileUtils == nullptr) { - FileUtils::sharedFileUtils = new FileUtilsOHOS(); + FileUtils::sharedFileUtils = ccnew FileUtilsOHOS(); if (!FileUtils::sharedFileUtils->init()) { delete FileUtils::sharedFileUtils; FileUtils::sharedFileUtils = nullptr; diff --git a/native/cocos/platform/qnx/FileUtils-qnx.cpp b/native/cocos/platform/qnx/FileUtils-qnx.cpp index a1d0d19915..cf2e3e77dd 100644 --- a/native/cocos/platform/qnx/FileUtils-qnx.cpp +++ b/native/cocos/platform/qnx/FileUtils-qnx.cpp @@ -30,6 +30,7 @@ #include #include #include "base/Log.h" +#include "base/memory/Memory.h" #define DECLARE_GUARD std::lock_guard mutexGuard(_mutex) #ifndef CC_RESOURCE_FOLDER_LINUX @@ -40,7 +41,7 @@ namespace cc { FileUtils *FileUtils::getInstance() { if (FileUtils::sharedFileUtils == nullptr) { - FileUtils::sharedFileUtils = new FileUtilsQNX(); + FileUtils::sharedFileUtils = ccnew FileUtilsQNX(); if (!FileUtils::sharedFileUtils->init()) { delete FileUtils::sharedFileUtils; FileUtils::sharedFileUtils = nullptr; diff --git a/native/cocos/platform/win32/FileUtils-win32.cpp b/native/cocos/platform/win32/FileUtils-win32.cpp index 6cf15994d7..f5e2f501da 100644 --- a/native/cocos/platform/win32/FileUtils-win32.cpp +++ b/native/cocos/platform/win32/FileUtils-win32.cpp @@ -25,14 +25,14 @@ THE SOFTWARE. ****************************************************************************/ -#if CC_PLATFORM == CC_PLATFORM_WINDOWS - #include "platform/win32/FileUtils-win32.h" - #include - #include - #include - #include - #include "base/Log.h" - #include "platform/win32/Utils-win32.h" +#include "platform/win32/FileUtils-win32.h" +#include +#include +#include +#include +#include "base/Log.h" +#include "base/memory/Memory.h" +#include "platform/win32/Utils-win32.h" using namespace std; @@ -74,7 +74,7 @@ static void _checkPath() { FileUtils *FileUtils::getInstance() { if (FileUtils::sharedFileUtils == nullptr) { - FileUtils::sharedFileUtils = new FileUtilsWin32(); + FileUtils::sharedFileUtils = ccnew FileUtilsWin32(); if (!FileUtils::sharedFileUtils->init()) { delete FileUtils::sharedFileUtils; FileUtils::sharedFileUtils = nullptr; @@ -363,5 +363,3 @@ bool FileUtilsWin32::removeDirectory(const ccstd::string &dirPath) { } } // namespace cc - -#endif // CC_PLATFORM == CC_PLATFORM_WINDOWS diff --git a/native/cocos/platform/win32/Utils-win32.cpp b/native/cocos/platform/win32/Utils-win32.cpp index 680af5813b..838236e603 100644 --- a/native/cocos/platform/win32/Utils-win32.cpp +++ b/native/cocos/platform/win32/Utils-win32.cpp @@ -28,6 +28,7 @@ #include "platform/win32/Utils-win32.h" #include #include "base/Log.h" +#include "base/memory/Memory.h" #include "platform/StdC.h" namespace cc { @@ -37,7 +38,7 @@ std::wstring StringUtf8ToWideChar(const ccstd::string &strUtf8) { if (!strUtf8.empty()) { int nNum = MultiByteToWideChar(CP_UTF8, 0, strUtf8.c_str(), -1, nullptr, 0); if (nNum) { - WCHAR *wideCharString = new WCHAR[nNum + 1]; + WCHAR *wideCharString = ccnew WCHAR[nNum + 1]; wideCharString[0] = 0; nNum = MultiByteToWideChar(CP_UTF8, 0, strUtf8.c_str(), -1, wideCharString, nNum + 1); @@ -56,7 +57,7 @@ ccstd::string StringWideCharToUtf8(const std::wstring &strWideChar) { if (!strWideChar.empty()) { int nNum = WideCharToMultiByte(CP_UTF8, 0, strWideChar.c_str(), -1, nullptr, 0, nullptr, FALSE); if (nNum) { - char *utf8String = new char[nNum + 1]; + char *utf8String = ccnew char[nNum + 1]; utf8String[0] = 0; nNum = WideCharToMultiByte(CP_UTF8, 0, strWideChar.c_str(), -1, utf8String, nNum + 1, nullptr, FALSE); @@ -77,7 +78,7 @@ ccstd::string UTF8StringToMultiByte(const ccstd::string &strUtf8) { std::wstring strWideChar = StringUtf8ToWideChar(strUtf8); int nNum = WideCharToMultiByte(CP_ACP, 0, strWideChar.c_str(), -1, nullptr, 0, nullptr, FALSE); if (nNum) { - char *ansiString = new char[nNum + 1]; + char *ansiString = ccnew char[nNum + 1]; ansiString[0] = 0; nNum = WideCharToMultiByte(CP_ACP, 0, strWideChar.c_str(), -1, ansiString, nNum + 1, nullptr, FALSE); diff --git a/native/cocos/platform/win32/modules/CanvasRenderingContext2DDelegate.cpp b/native/cocos/platform/win32/modules/CanvasRenderingContext2DDelegate.cpp index 5dd2ef0e54..8d41362016 100644 --- a/native/cocos/platform/win32/modules/CanvasRenderingContext2DDelegate.cpp +++ b/native/cocos/platform/win32/modules/CanvasRenderingContext2DDelegate.cpp @@ -293,7 +293,7 @@ wchar_t *CanvasRenderingContext2DDelegate::utf8ToUtf16(const ccstd::string &str, } int nLen = static_cast(str.size()); int nBufLen = nLen + 1; - pwszBuffer = new wchar_t[nBufLen]; + pwszBuffer = ccnew wchar_t[nBufLen]; CC_BREAK_IF(!pwszBuffer); memset(pwszBuffer, 0, sizeof(wchar_t) * nBufLen); // str.size() not equal actuallyLen for Chinese char diff --git a/native/cocos/platform/win32/modules/System.cpp b/native/cocos/platform/win32/modules/System.cpp index d12194f012..9d55ad6a9d 100644 --- a/native/cocos/platform/win32/modules/System.cpp +++ b/native/cocos/platform/win32/modules/System.cpp @@ -25,6 +25,7 @@ #include "platform/win32/modules/System.h" #include +#include "base/memory/Memory.h" namespace cc { using OSType = System::OSType; @@ -111,7 +112,7 @@ ccstd::string System::getCurrentLanguageCode() const { const LCID locale_id = MAKELCID(lid, SORT_DEFAULT); int length = GetLocaleInfoA(locale_id, LOCALE_SISO639LANGNAME, nullptr, 0); - char *tempCode = new char[length]; + char *tempCode = ccnew char[length]; GetLocaleInfoA(locale_id, LOCALE_SISO639LANGNAME, tempCode, length); ccstd::string code = tempCode; delete tempCode; @@ -144,7 +145,7 @@ ccstd::string System::getSystemVersion() const { } bool System::openURL(const ccstd::string &url) { - WCHAR *temp = new WCHAR[url.size() + 1]; + WCHAR *temp = ccnew WCHAR[url.size() + 1]; int urlSize = static_cast(url.size() + 1); MultiByteToWideChar(CP_UTF8, 0, url.c_str(), urlSize, temp, urlSize); HINSTANCE r = ShellExecuteW(NULL, L"open", temp, NULL, NULL, SW_SHOWNORMAL); diff --git a/native/cocos/profiler/DebugRenderer.cpp b/native/cocos/profiler/DebugRenderer.cpp index 565f1df167..4e7e3f81de 100644 --- a/native/cocos/profiler/DebugRenderer.cpp +++ b/native/cocos/profiler/DebugRenderer.cpp @@ -175,7 +175,7 @@ public: } } - auto *batch = new DebugBatch(device, bold, italic, texture); + auto *batch = ccnew DebugBatch(device, bold, italic, texture); _batches.push_back(batch); return *batch; @@ -208,7 +208,7 @@ DebugRendererInfo::DebugRendererInfo() DebugRenderer *DebugRenderer::instance = nullptr; DebugRenderer *DebugRenderer::getInstance() { if (!instance) { - instance = new DebugRenderer(); + instance = ccnew DebugRenderer(); } return instance; @@ -229,7 +229,7 @@ void DebugRenderer::activate(gfx::Device *device, const DebugRendererInfo &info) {"a_texCoord", gfx::Format::RG32F}, {"a_color", gfx::Format::RGBA32F}}; - _buffer = new DebugVertexBuffer(); + _buffer = ccnew DebugVertexBuffer(); _buffer->init(_device, info.maxCharacters * DEBUG_VERTICES_PER_CHAR, ATTRIBUTES); const auto *window = CC_CURRENT_ENGINE()->getInterface(); @@ -238,7 +238,7 @@ void DebugRenderer::activate(gfx::Device *device, const DebugRendererInfo &info) fontSize = fontSize < 10U ? 10U : (fontSize > 20U ? 20U : fontSize); for (auto i = 0U; i < _fonts.size(); i++) { - _fonts[i].font = new FreeTypeFont(getFontPath(i)); + _fonts[i].font = ccnew FreeTypeFont(getFontPath(i)); _fonts[i].face = _fonts[i].font->createFace(FontFaceInfo(fontSize)); _fonts[i].invTextureSize = {1.0F / _fonts[i].face->getTextureWidth(), 1.0F / _fonts[i].face->getTextureHeight()}; } diff --git a/native/cocos/profiler/Profiler.cpp b/native/cocos/profiler/Profiler.cpp index 8320063358..afe52e756b 100644 --- a/native/cocos/profiler/Profiler.cpp +++ b/native/cocos/profiler/Profiler.cpp @@ -83,7 +83,7 @@ ProfilerBlock *ProfilerBlock::getOrCreateChild(const ccstd::string &name) { } } - auto *child = new ProfilerBlock(this, name); + auto *child = ccnew ProfilerBlock(this, name); _children.push_back(child); return child; @@ -124,7 +124,7 @@ struct ProfilerBlockDepth { Profiler *Profiler::instance = nullptr; Profiler *Profiler::getInstance() { if (!instance) { - instance = new Profiler(); + instance = ccnew Profiler(); } return instance; @@ -139,7 +139,7 @@ void Profiler::destroyInstance() { Profiler::Profiler() { _mainThreadId = std::this_thread::get_id(); - _root = new ProfilerBlock(nullptr, "MainThread"); + _root = ccnew ProfilerBlock(nullptr, "MainThread"); _current = _root; } diff --git a/native/cocos/renderer/GFXDeviceManager.h b/native/cocos/renderer/GFXDeviceManager.h index a97c56f9cb..deb8d3ab01 100644 --- a/native/cocos/renderer/GFXDeviceManager.h +++ b/native/cocos/renderer/GFXDeviceManager.h @@ -139,14 +139,14 @@ public: private: template ::value>> static bool tryCreate(const DeviceInfo &info, Device **pDevice) { - Device *device = CC_NEW(DeviceCtor); + Device *device = ccnew DeviceCtor; if (DETACH_DEVICE_THREAD) { - device = CC_NEW(gfx::DeviceAgent(device)); + device = ccnew gfx::DeviceAgent(device); } if (CC_DEBUG > 0 && !FORCE_DISABLE_VALIDATION || FORCE_ENABLE_VALIDATION) { - device = CC_NEW(gfx::DeviceValidator(device)); + device = ccnew gfx::DeviceValidator(device); } if (!device->initialize(info)) { diff --git a/native/cocos/renderer/core/MaterialInstance.cpp b/native/cocos/renderer/core/MaterialInstance.cpp index 60c2578336..0254711886 100644 --- a/native/cocos/renderer/core/MaterialInstance.cpp +++ b/native/cocos/renderer/core/MaterialInstance.cpp @@ -67,7 +67,7 @@ ccstd::vector> MaterialInstance::createPasses() { passes.reserve(parentPasses->size()); for (auto &parentPass : *parentPasses) { - passes.emplace_back(new PassInstance(parentPass, this)); + passes.emplace_back(ccnew PassInstance(parentPass, this)); } return passes; } diff --git a/native/cocos/renderer/core/ProgramLib.cpp b/native/cocos/renderer/core/ProgramLib.cpp index 8db7ebaeb6..2ae06e406f 100644 --- a/native/cocos/renderer/core/ProgramLib.cpp +++ b/native/cocos/renderer/core/ProgramLib.cpp @@ -282,7 +282,7 @@ ProgramLib *ProgramLib::instance = nullptr; ProgramLib *ProgramLib::getInstance() { if (!ProgramLib::instance) { - ProgramLib::instance = new ProgramLib(); + ProgramLib::instance = ccnew ProgramLib(); } return ProgramLib::instance; } diff --git a/native/cocos/renderer/frame-graph/FrameGraph.cpp b/native/cocos/renderer/frame-graph/FrameGraph.cpp index f8894b0323..cd7e34c2ff 100644 --- a/native/cocos/renderer/frame-graph/FrameGraph.cpp +++ b/native/cocos/renderer/frame-graph/FrameGraph.cpp @@ -200,7 +200,7 @@ Handle FrameGraph::create(VirtualResource *const virtualResource) { } PassNode &FrameGraph::createPassNode(const PassInsertPoint insertPoint, const StringHandle &name, Executable *const pass) { - _passNodes.emplace_back(new PassNode(insertPoint, name, static_cast(_passNodes.size()), pass)); + _passNodes.emplace_back(ccnew PassNode(insertPoint, name, static_cast(_passNodes.size()), pass)); return *_passNodes.back(); } @@ -448,7 +448,7 @@ void FrameGraph::generateDevicePasses() { } if (passId != passNode->_devicePassId) { - _devicePasses.emplace_back(new DevicePass(*this, subpassNodes)); + _devicePasses.emplace_back(ccnew DevicePass(*this, subpassNodes)); for (PassNode *const p : subpassNodes) { p->releaseTransientResources(); @@ -464,7 +464,7 @@ void FrameGraph::generateDevicePasses() { CC_ASSERT(subpassNodes.size() == 1); - _devicePasses.emplace_back(new DevicePass(*this, subpassNodes)); + _devicePasses.emplace_back(ccnew DevicePass(*this, subpassNodes)); for (PassNode *const p : subpassNodes) { p->releaseTransientResources(); diff --git a/native/cocos/renderer/frame-graph/FrameGraph.h b/native/cocos/renderer/frame-graph/FrameGraph.h index e110be8255..abe9102a4e 100644 --- a/native/cocos/renderer/frame-graph/FrameGraph.h +++ b/native/cocos/renderer/frame-graph/FrameGraph.h @@ -105,7 +105,7 @@ private: template const CallbackPass &FrameGraph::addPass(const PassInsertPoint insertPoint, const StringHandle &name, SetupMethod setup, ExecuteMethod &&execute) noexcept { static_assert(sizeof(ExecuteMethod) < 1024, "Execute() lambda is capturing too much data."); - auto *const pass = new CallbackPass(std::forward(execute)); + auto *const pass = ccnew CallbackPass(std::forward(execute)); PassNode & passNode = createPassNode(insertPoint, name, pass); PassNodeBuilder builder(*this, passNode); setup(builder, pass->getData()); @@ -114,14 +114,14 @@ const CallbackPass &FrameGraph::addPass(const PassInsertPoi template TypedHandle FrameGraph::create(const StringHandle &name, const DescriptorType &desc) noexcept { - auto *const virtualResource = new ResourceEntry(name, static_cast(_virtualResources.size()), desc); + auto *const virtualResource = ccnew ResourceEntry(name, static_cast(_virtualResources.size()), desc); return TypedHandle(create(virtualResource)); } template TypedHandle FrameGraph::importExternal(const StringHandle &name, ResourceType &resource) noexcept { CC_ASSERT(resource.get()); - auto *const virtualResource = new ResourceEntry(name, static_cast(_virtualResources.size()), resource); + auto *const virtualResource = ccnew ResourceEntry(name, static_cast(_virtualResources.size()), resource); return TypedHandle(create(virtualResource)); } diff --git a/native/cocos/renderer/frame-graph/ResourceAllocator.h b/native/cocos/renderer/frame-graph/ResourceAllocator.h index e8d5484f2d..53c76d014c 100644 --- a/native/cocos/renderer/frame-graph/ResourceAllocator.h +++ b/native/cocos/renderer/frame-graph/ResourceAllocator.h @@ -142,7 +142,7 @@ void ResourceAllocator_cmdBuffRefs.insert(this); - // TODO(PatriceJiang): replace with: _messageQueue = CC_NEW(MessageQueue); - _messageQueue = CC_NEW_ALIGN(MessageQueue, alignof(MessageQueue)); + // TODO(PatriceJiang): replace with: _messageQueue = ccnew MessageQueue; + _messageQueue = ccnew_placement(CC_MALLOC_ALIGN(sizeof(MessageQueue), alignof(MessageQueue))) MessageQueue; if (device->_multithreaded) _messageQueue->setImmediateMode(false); } void CommandBufferAgent::destroyMessageQueue() { DeviceAgent::getInstance()->getMessageQueue()->kickAndWait(); // TODO(PatriceJiang): replace with: CC_SAFE_DELETE(_messageQueue); - CC_DELETE_ALIGN(_messageQueue, MessageQueue, alignof(MessageQueue)); + _messageQueue->~MessageQueue(); + CC_FREE_ALIGN(_messageQueue); _messageQueue = nullptr; DeviceAgent::getInstance()->_cmdBuffRefs.erase(this); diff --git a/native/cocos/renderer/gfx-agent/DeviceAgent.cpp b/native/cocos/renderer/gfx-agent/DeviceAgent.cpp index 868877c6cc..f7ce02a2f9 100644 --- a/native/cocos/renderer/gfx-agent/DeviceAgent.cpp +++ b/native/cocos/renderer/gfx-agent/DeviceAgent.cpp @@ -69,9 +69,9 @@ bool DeviceAgent::doInit(const DeviceInfo &info) { _api = _actor->getGfxAPI(); _deviceName = _actor->getDeviceName(); - _queue = CC_NEW(QueueAgent(_actor->getQueue())); - _queryPool = CC_NEW(QueryPoolAgent(_actor->getQueryPool())); - _cmdBuff = CC_NEW(CommandBufferAgent(_actor->getCommandBuffer())); + _queue = ccnew QueueAgent(_actor->getQueue()); + _queryPool = ccnew QueryPoolAgent(_actor->getQueryPool()); + _cmdBuff = ccnew CommandBufferAgent(_actor->getCommandBuffer()); _renderer = _actor->getRenderer(); _vendor = _actor->getVendor(); _caps = _actor->_caps; @@ -79,8 +79,8 @@ bool DeviceAgent::doInit(const DeviceInfo &info) { memcpy(_formatFeatures.data(), _actor->_formatFeatures.data(), static_cast(Format::COUNT) * sizeof(FormatFeatureBit)); // NOTE: C++17 is required when enable alignment - // TODO(PatriceJiang): replace with: _mainMessageQueue = CC_NEW(MessageQueue); - _mainMessageQueue = CC_NEW_ALIGN(MessageQueue, alignof(MessageQueue)); //NOLINT + // TODO(PatriceJiang): replace with: _mainMessageQueue = ccnew MessageQueue; + _mainMessageQueue = ccnew_placement(CC_MALLOC_ALIGN(sizeof(MessageQueue), alignof(MessageQueue))) MessageQueue; //NOLINT static_cast(_cmdBuff)->_queue = _queue; static_cast(_cmdBuff)->initAgent(); @@ -101,17 +101,17 @@ void DeviceAgent::doDestroy() { if (_cmdBuff) { static_cast(_cmdBuff)->destroyAgent(); static_cast(_cmdBuff)->_actor = nullptr; - CC_DELETE(_cmdBuff); + delete _cmdBuff; _cmdBuff = nullptr; } if (_queryPool) { static_cast(_queryPool)->_actor = nullptr; - CC_DELETE(_queryPool); + delete _queryPool; _queryPool = nullptr; } if (_queue) { static_cast(_queue)->_actor = nullptr; - CC_DELETE(_queue); + delete _queue; _queue = nullptr; } @@ -119,7 +119,8 @@ void DeviceAgent::doDestroy() { // NOTE: C++17 required when enable alignment // TODO(PatriceJiang): replace with: CC_SAFE_DELETE(_mainMessageQueue); - CC_DELETE_ALIGN(_mainMessageQueue, MessageQueue, alignof(MessageQueue)); // NOLINT + _mainMessageQueue->~MessageQueue(); + CC_FREE_ALIGN(_mainMessageQueue); _mainMessageQueue = nullptr; } @@ -194,72 +195,72 @@ void DeviceAgent::setMultithreaded(bool multithreaded) { CommandBuffer *DeviceAgent::createCommandBuffer(const CommandBufferInfo &info, bool /*hasAgent*/) { CommandBuffer *actor = _actor->createCommandBuffer(info, true); - return CC_NEW(CommandBufferAgent(actor)); + return ccnew CommandBufferAgent(actor); } Queue *DeviceAgent::createQueue() { Queue *actor = _actor->createQueue(); - return CC_NEW(QueueAgent(actor)); + return ccnew QueueAgent(actor); } QueryPool *DeviceAgent::createQueryPool() { QueryPool *actor = _actor->createQueryPool(); - return CC_NEW(QueryPoolAgent(actor)); + return ccnew QueryPoolAgent(actor); } Swapchain *DeviceAgent::createSwapchain() { Swapchain *actor = _actor->createSwapchain(); - return CC_NEW(SwapchainAgent(actor)); + return ccnew SwapchainAgent(actor); } Buffer *DeviceAgent::createBuffer() { Buffer *actor = _actor->createBuffer(); - return CC_NEW(BufferAgent(actor)); + return ccnew BufferAgent(actor); } Texture *DeviceAgent::createTexture() { Texture *actor = _actor->createTexture(); - return CC_NEW(TextureAgent(actor)); + return ccnew TextureAgent(actor); } Shader *DeviceAgent::createShader() { Shader *actor = _actor->createShader(); - return CC_NEW(ShaderAgent(actor)); + return ccnew ShaderAgent(actor); } InputAssembler *DeviceAgent::createInputAssembler() { InputAssembler *actor = _actor->createInputAssembler(); - return CC_NEW(InputAssemblerAgent(actor)); + return ccnew InputAssemblerAgent(actor); } RenderPass *DeviceAgent::createRenderPass() { RenderPass *actor = _actor->createRenderPass(); - return CC_NEW(RenderPassAgent(actor)); + return ccnew RenderPassAgent(actor); } Framebuffer *DeviceAgent::createFramebuffer() { Framebuffer *actor = _actor->createFramebuffer(); - return CC_NEW(FramebufferAgent(actor)); + return ccnew FramebufferAgent(actor); } DescriptorSet *DeviceAgent::createDescriptorSet() { DescriptorSet *actor = _actor->createDescriptorSet(); - return CC_NEW(DescriptorSetAgent(actor)); + return ccnew DescriptorSetAgent(actor); } DescriptorSetLayout *DeviceAgent::createDescriptorSetLayout() { DescriptorSetLayout *actor = _actor->createDescriptorSetLayout(); - return CC_NEW(DescriptorSetLayoutAgent(actor)); + return ccnew DescriptorSetLayoutAgent(actor); } PipelineLayout *DeviceAgent::createPipelineLayout() { PipelineLayout *actor = _actor->createPipelineLayout(); - return CC_NEW(PipelineLayoutAgent(actor)); + return ccnew PipelineLayoutAgent(actor); } PipelineState *DeviceAgent::createPipelineState() { PipelineState *actor = _actor->createPipelineState(); - return CC_NEW(PipelineStateAgent(actor)); + return ccnew PipelineStateAgent(actor); } Sampler *DeviceAgent::getSampler(const SamplerInfo &info) { @@ -288,9 +289,10 @@ void doBufferTextureCopy(const uint8_t *const *buffers, Texture *texture, const totalSize += size * region.texSubres.layerCount; } - //TODO(PatriceJiang): in C++17 replace with:*allocator = CC_NEW(ThreadSafeLinearAllocator(totalSize)); - auto *allocator = CC_NEW_ALIGN(ThreadSafeLinearAllocator(totalSize), alignof(ThreadSafeLinearAllocator)); - + //TODO(PatriceJiang): in C++17 replace with:*allocator = ccnew ThreadSafeLinearAllocator(totalSize); + auto *memory = CC_MALLOC_ALIGN(sizeof(ThreadSafeLinearAllocator), alignof(ThreadSafeLinearAllocator)); + auto *allocator = ccnew_placement(memory) ThreadSafeLinearAllocator(totalSize); + auto *actorRegions = allocator->allocate(count); memcpy(actorRegions, regions, count * sizeof(BufferTextureCopy)); @@ -316,8 +318,11 @@ void doBufferTextureCopy(const uint8_t *const *buffers, Texture *texture, const allocator, allocator, { actor->copyBuffersToTexture(buffers, dst, regions, count); - // TODO(PatriceJiang): C++17 replace with: CC_DELETE(allocator); - if (allocator) CC_DELETE_ALIGN(allocator, ThreadSafeLinearAllocator, alignof(ThreadSafeLinearAllocator)); + // TODO(PatriceJiang): C++17 replace with: delete allocator; + if (allocator) { + allocator->~ThreadSafeLinearAllocator(); + CC_FREE_ALIGN(allocator); + } }); } diff --git a/native/cocos/renderer/gfx-agent/SwapchainAgent.cpp b/native/cocos/renderer/gfx-agent/SwapchainAgent.cpp index f0fb8af8f3..78af3a9bd2 100644 --- a/native/cocos/renderer/gfx-agent/SwapchainAgent.cpp +++ b/native/cocos/renderer/gfx-agent/SwapchainAgent.cpp @@ -58,11 +58,11 @@ void SwapchainAgent::doInit(const SwapchainInfo &info) { DeviceAgent::getInstance()->getMessageQueue()->kickAndWait(); - auto *colorTexture = CC_NEW(TextureAgent(_actor->getColorTexture())); + auto *colorTexture = ccnew TextureAgent(_actor->getColorTexture()); colorTexture->renounceOwnership(); _colorTexture = colorTexture; - auto *depthStencilTexture = CC_NEW(TextureAgent(_actor->getDepthStencilTexture())); + auto *depthStencilTexture = ccnew TextureAgent(_actor->getDepthStencilTexture()); depthStencilTexture->renounceOwnership(); _depthStencilTexture = depthStencilTexture; diff --git a/native/cocos/renderer/gfx-base/GFXDevice.h b/native/cocos/renderer/gfx-base/GFXDevice.h index 7189a9939f..2484c2928f 100644 --- a/native/cocos/renderer/gfx-base/GFXDevice.h +++ b/native/cocos/renderer/gfx-base/GFXDevice.h @@ -150,9 +150,9 @@ protected: virtual PipelineLayout * createPipelineLayout() = 0; virtual PipelineState * createPipelineState() = 0; - virtual Sampler * createSampler(const SamplerInfo &info) { return CC_NEW(Sampler(info)); } - virtual GeneralBarrier *createGeneralBarrier(const GeneralBarrierInfo &info) { return CC_NEW(GeneralBarrier(info)); } - virtual TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info) { return CC_NEW(TextureBarrier(info)); } + virtual Sampler * createSampler(const SamplerInfo &info) { return ccnew Sampler(info); } + virtual GeneralBarrier *createGeneralBarrier(const GeneralBarrierInfo &info) { return ccnew GeneralBarrier(info); } + virtual TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info) { return ccnew TextureBarrier(info); } // For context switching between threads virtual void bindContext(bool bound) {} @@ -313,7 +313,7 @@ void Device::acquire(const ccstd::vector &swapchains) { template void Device::registerOnAcquireCallback(ExecuteMethod &&execute) { - _onAcquire = CC_NEW(CallbackExecutable(std::forward(execute))); + _onAcquire = ccnew CallbackExecutable(std::forward(execute)); } } // namespace gfx diff --git a/native/cocos/renderer/gfx-empty/EmptyDevice.cpp b/native/cocos/renderer/gfx-empty/EmptyDevice.cpp index a3a73e83e5..b3b1b4bce6 100644 --- a/native/cocos/renderer/gfx-empty/EmptyDevice.cpp +++ b/native/cocos/renderer/gfx-empty/EmptyDevice.cpp @@ -95,59 +95,59 @@ void EmptyDevice::present() { } CommandBuffer *EmptyDevice::createCommandBuffer(const CommandBufferInfo & /*info*/, bool /*hasAgent*/) { - return CC_NEW(EmptyCommandBuffer); + return ccnew EmptyCommandBuffer; } Queue *EmptyDevice::createQueue() { - return CC_NEW(EmptyQueue); + return ccnew EmptyQueue; } QueryPool *EmptyDevice::createQueryPool() { - return CC_NEW(EmptyQueryPool); + return ccnew EmptyQueryPool; } Swapchain *EmptyDevice::createSwapchain() { - return CC_NEW(EmptySwapchain); + return ccnew EmptySwapchain; } Buffer *EmptyDevice::createBuffer() { - return CC_NEW(EmptyBuffer); + return ccnew EmptyBuffer; } Texture *EmptyDevice::createTexture() { - return CC_NEW(EmptyTexture); + return ccnew EmptyTexture; } Shader *EmptyDevice::createShader() { - return CC_NEW(EmptyShader); + return ccnew EmptyShader; } InputAssembler *EmptyDevice::createInputAssembler() { - return CC_NEW(EmptyInputAssembler); + return ccnew EmptyInputAssembler; } RenderPass *EmptyDevice::createRenderPass() { - return CC_NEW(EmptyRenderPass); + return ccnew EmptyRenderPass; } Framebuffer *EmptyDevice::createFramebuffer() { - return CC_NEW(EmptyFramebuffer); + return ccnew EmptyFramebuffer; } DescriptorSet *EmptyDevice::createDescriptorSet() { - return CC_NEW(EmptyDescriptorSet); + return ccnew EmptyDescriptorSet; } DescriptorSetLayout *EmptyDevice::createDescriptorSetLayout() { - return CC_NEW(EmptyDescriptorSetLayout); + return ccnew EmptyDescriptorSetLayout; } PipelineLayout *EmptyDevice::createPipelineLayout() { - return CC_NEW(EmptyPipelineLayout); + return ccnew EmptyPipelineLayout; } PipelineState *EmptyDevice::createPipelineState() { - return CC_NEW(EmptyPipelineState); + return ccnew EmptyPipelineState; } void EmptyDevice::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) { diff --git a/native/cocos/renderer/gfx-empty/EmptySwapchain.cpp b/native/cocos/renderer/gfx-empty/EmptySwapchain.cpp index 8386a7fcf4..99203ddcbc 100644 --- a/native/cocos/renderer/gfx-empty/EmptySwapchain.cpp +++ b/native/cocos/renderer/gfx-empty/EmptySwapchain.cpp @@ -30,8 +30,8 @@ namespace cc { namespace gfx { void EmptySwapchain::doInit(const SwapchainInfo &info) { - _colorTexture = CC_NEW(EmptyTexture); - _depthStencilTexture = CC_NEW(EmptyTexture); + _colorTexture = ccnew EmptyTexture; + _depthStencilTexture = ccnew EmptyTexture; SwapchainTextureInfo textureInfo; textureInfo.swapchain = this; diff --git a/native/cocos/renderer/gfx-gles-common/GLESCommandPool.h b/native/cocos/renderer/gfx-gles-common/GLESCommandPool.h index e4265e6988..5cbdfd089f 100644 --- a/native/cocos/renderer/gfx-gles-common/GLESCommandPool.h +++ b/native/cocos/renderer/gfx-gles-common/GLESCommandPool.h @@ -84,22 +84,22 @@ template ::v class CommandPool { public: CommandPool() : _freeCmds(INITIAL_CAPACITY) { - _frees = new T *[INITIAL_CAPACITY]; + _frees = ccnew T *[INITIAL_CAPACITY]; _count = INITIAL_CAPACITY; _freeIdx = INITIAL_CAPACITY - 1; for (uint32_t i = 0; i < _count; ++i) { - _frees[i] = CC_NEW(T); + _frees[i] = ccnew T; } } ~CommandPool() { for (uint32_t i = 0; i < _count; ++i) { - CC_DELETE(_frees[i]); + delete _frees[i]; } delete[](_frees); for (uint32_t i = 0; i < _freeCmds.size(); ++i) { - CC_DELETE(_freeCmds[i]); + delete _freeCmds[i]; } _freeCmds.clear(); } @@ -108,10 +108,10 @@ public: if (_freeIdx < 0) { T ** oldFrees = _frees; uint32_t size = _count * 2; - _frees = new T *[size]; + _frees = ccnew T *[size]; uint32_t increase = size - _count; for (uint32_t i = 0; i < increase; ++i) { - _frees[i] = CC_NEW(T); + _frees[i] = ccnew T; } for (uint32_t i = increase, j = 0; i < size; ++i, ++j) { _frees[i] = oldFrees[j]; diff --git a/native/cocos/renderer/gfx-gles2/GLES2Buffer.cpp b/native/cocos/renderer/gfx-gles2/GLES2Buffer.cpp index 6e8c1e50c3..8d784f35d5 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Buffer.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Buffer.cpp @@ -42,7 +42,7 @@ GLES2Buffer::~GLES2Buffer() { } void GLES2Buffer::doInit(const BufferInfo & /*info*/) { - _gpuBuffer = CC_NEW(GLES2GPUBuffer); + _gpuBuffer = ccnew GLES2GPUBuffer; _gpuBuffer->usage = _usage; _gpuBuffer->memUsage = _memUsage; _gpuBuffer->size = _size; @@ -60,7 +60,7 @@ void GLES2Buffer::doInit(const BufferInfo & /*info*/) { void GLES2Buffer::doInit(const BufferViewInfo &info) { auto *buffer = static_cast(info.buffer); - _gpuBufferView = CC_NEW(GLES2GPUBufferView); + _gpuBufferView = ccnew GLES2GPUBufferView; _gpuBufferView->gpuBuffer = buffer->gpuBuffer(); _gpuBufferView->range = _size; _gpuBufferView->offset = info.offset; @@ -71,7 +71,7 @@ void GLES2Buffer::doDestroy() { GLES2Device::getInstance()->getMemoryStatus().bufferSize -= _size; CC_PROFILE_MEMORY_DEC(Buffer, _size); cmdFuncGLES2DestroyBuffer(GLES2Device::getInstance(), _gpuBuffer); - CC_DELETE(_gpuBuffer); + delete _gpuBuffer; _gpuBuffer = nullptr; } diff --git a/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cpp b/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cpp index 4f8939f2e2..a293d11a8f 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cpp @@ -52,8 +52,8 @@ void GLES2CommandBuffer::doInit(const CommandBufferInfo &info) { _type = info.type; _queue = info.queue; - _cmdAllocator = CC_NEW(GLES2GPUCommandAllocator); - _curCmdPackage = CC_NEW(GLES2CmdPackage); + _cmdAllocator = ccnew GLES2GPUCommandAllocator; + _curCmdPackage = ccnew GLES2CmdPackage; size_t setCount = GLES2Device::getInstance()->bindingMappingInfo().setIndices.size(); _curGPUDescriptorSets.resize(setCount); @@ -105,7 +105,7 @@ void GLES2CommandBuffer::end() { _curCmdPackage = _freePackages.front(); _freePackages.pop(); } else { - _curCmdPackage = CC_NEW(GLES2CmdPackage); + _curCmdPackage = ccnew GLES2CmdPackage; } } diff --git a/native/cocos/renderer/gfx-gles2/GLES2DescriptorSet.cpp b/native/cocos/renderer/gfx-gles2/GLES2DescriptorSet.cpp index 0797bb7751..a2fdab8344 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2DescriptorSet.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2DescriptorSet.cpp @@ -52,7 +52,7 @@ void GLES2DescriptorSet::doInit(const DescriptorSetInfo & /*info*/) { _textures.resize(descriptorCount); _samplers.resize(descriptorCount); - _gpuDescriptorSet = CC_NEW(GLES2GPUDescriptorSet); + _gpuDescriptorSet = ccnew GLES2GPUDescriptorSet; _gpuDescriptorSet->gpuDescriptors.resize(descriptorCount); for (size_t i = 0U, k = 0U; i < bindingCount; i++) { const DescriptorSetLayoutBinding &binding = gpuDescriptorSetLayout->bindings[i]; @@ -65,10 +65,7 @@ void GLES2DescriptorSet::doInit(const DescriptorSetInfo & /*info*/) { } void GLES2DescriptorSet::doDestroy() { - if (_gpuDescriptorSet) { - CC_DELETE(_gpuDescriptorSet); - _gpuDescriptorSet = nullptr; - } + CC_SAFE_DELETE(_gpuDescriptorSet); } void GLES2DescriptorSet::update() { diff --git a/native/cocos/renderer/gfx-gles2/GLES2DescriptorSetLayout.cpp b/native/cocos/renderer/gfx-gles2/GLES2DescriptorSetLayout.cpp index d99063a2c4..6f23745c80 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2DescriptorSetLayout.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2DescriptorSetLayout.cpp @@ -40,7 +40,7 @@ GLES2DescriptorSetLayout::~GLES2DescriptorSetLayout() { } void GLES2DescriptorSetLayout::doInit(const DescriptorSetLayoutInfo & /*info*/) { - _gpuDescriptorSetLayout = CC_NEW(GLES2GPUDescriptorSetLayout); + _gpuDescriptorSetLayout = ccnew GLES2GPUDescriptorSetLayout; _gpuDescriptorSetLayout->descriptorCount = _descriptorCount; _gpuDescriptorSetLayout->bindingIndices = _bindingIndices; _gpuDescriptorSetLayout->descriptorIndices = _descriptorIndices; @@ -56,10 +56,7 @@ void GLES2DescriptorSetLayout::doInit(const DescriptorSetLayoutInfo & /*info*/) } void GLES2DescriptorSetLayout::doDestroy() { - if (_gpuDescriptorSetLayout) { - CC_DELETE(_gpuDescriptorSetLayout); - _gpuDescriptorSetLayout = nullptr; - } + CC_SAFE_DELETE(_gpuDescriptorSetLayout); } } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles2/GLES2Device.cpp b/native/cocos/renderer/gfx-gles2/GLES2Device.cpp index 28e7dbc61d..f744b17503 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Device.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Device.cpp @@ -72,12 +72,12 @@ GLES2Device::~GLES2Device() { } bool GLES2Device::doInit(const DeviceInfo & /*info*/) { - _gpuContext = CC_NEW(GLES2GPUContext); - _gpuStateCache = CC_NEW(GLES2GPUStateCache); - _gpuBlitManager = CC_NEW(GLES2GPUBlitManager); - _gpuFramebufferHub = CC_NEW(GLES2GPUFramebufferHub); - _gpuConstantRegistry = CC_NEW(GLES2GPUConstantRegistry); - _gpuFramebufferCacheMap = CC_NEW(GLES2GPUFramebufferCacheMap(_gpuStateCache)); + _gpuContext = ccnew GLES2GPUContext; + _gpuStateCache = ccnew GLES2GPUStateCache; + _gpuBlitManager = ccnew GLES2GPUBlitManager; + _gpuFramebufferHub = ccnew GLES2GPUFramebufferHub; + _gpuConstantRegistry = ccnew GLES2GPUConstantRegistry; + _gpuFramebufferCacheMap = ccnew GLES2GPUFramebufferCacheMap(_gpuStateCache); if (!_gpuContext->initialize(_gpuStateCache, _gpuConstantRegistry)) { destroy(); @@ -438,64 +438,64 @@ void GLES2Device::initFormatFeature() { } CommandBuffer *GLES2Device::createCommandBuffer(const CommandBufferInfo &info, bool hasAgent) { - if (hasAgent || info.type == CommandBufferType::PRIMARY) return CC_NEW(GLES2PrimaryCommandBuffer); - return CC_NEW(GLES2CommandBuffer); + if (hasAgent || info.type == CommandBufferType::PRIMARY) return ccnew GLES2PrimaryCommandBuffer; + return ccnew GLES2CommandBuffer; } Queue *GLES2Device::createQueue() { - return CC_NEW(GLES2Queue); + return ccnew GLES2Queue; } QueryPool *GLES2Device::createQueryPool() { - return CC_NEW(GLES2QueryPool); + return ccnew GLES2QueryPool; } Swapchain *GLES2Device::createSwapchain() { - return CC_NEW(GLES2Swapchain); + return ccnew GLES2Swapchain; } Buffer *GLES2Device::createBuffer() { - return CC_NEW(GLES2Buffer); + return ccnew GLES2Buffer; } Texture *GLES2Device::createTexture() { - return CC_NEW(GLES2Texture); + return ccnew GLES2Texture; } Shader *GLES2Device::createShader() { - return CC_NEW(GLES2Shader); + return ccnew GLES2Shader; } InputAssembler *GLES2Device::createInputAssembler() { - return CC_NEW(GLES2InputAssembler); + return ccnew GLES2InputAssembler; } RenderPass *GLES2Device::createRenderPass() { - return CC_NEW(GLES2RenderPass); + return ccnew GLES2RenderPass; } Framebuffer *GLES2Device::createFramebuffer() { - return CC_NEW(GLES2Framebuffer); + return ccnew GLES2Framebuffer; } DescriptorSet *GLES2Device::createDescriptorSet() { - return CC_NEW(GLES2DescriptorSet); + return ccnew GLES2DescriptorSet; } DescriptorSetLayout *GLES2Device::createDescriptorSetLayout() { - return CC_NEW(GLES2DescriptorSetLayout); + return ccnew GLES2DescriptorSetLayout; } PipelineLayout *GLES2Device::createPipelineLayout() { - return CC_NEW(GLES2PipelineLayout); + return ccnew GLES2PipelineLayout; } PipelineState *GLES2Device::createPipelineState() { - return CC_NEW(GLES2PipelineState); + return ccnew GLES2PipelineState; } Sampler *GLES2Device::createSampler(const SamplerInfo &info) { - return CC_NEW(GLES2Sampler(info)); + return ccnew GLES2Sampler(info); } void GLES2Device::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) { diff --git a/native/cocos/renderer/gfx-gles2/GLES2Framebuffer.cpp b/native/cocos/renderer/gfx-gles2/GLES2Framebuffer.cpp index 2d1d115d95..337a4119be 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Framebuffer.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Framebuffer.cpp @@ -43,7 +43,7 @@ GLES2Framebuffer::~GLES2Framebuffer() { } void GLES2Framebuffer::doInit(const FramebufferInfo & /*info*/) { - _gpuFBO = CC_NEW(GLES2GPUFramebuffer); + _gpuFBO = ccnew GLES2GPUFramebuffer; _gpuFBO->gpuRenderPass = static_cast(_renderPass)->gpuRenderPass(); _gpuFBO->gpuColorTextures.resize(_colorTextures.size()); @@ -77,7 +77,7 @@ void GLES2Framebuffer::doDestroy() { GLES2Device::getInstance()->framebufferHub()->disengage(depthTexture->gpuTexture(), _gpuFBO); } - CC_DELETE(_gpuFBO); + delete _gpuFBO; _gpuFBO = nullptr; } } diff --git a/native/cocos/renderer/gfx-gles2/GLES2InputAssembler.cpp b/native/cocos/renderer/gfx-gles2/GLES2InputAssembler.cpp index af8b8d823c..46934b65ef 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2InputAssembler.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2InputAssembler.cpp @@ -42,7 +42,7 @@ GLES2InputAssembler::~GLES2InputAssembler() { } void GLES2InputAssembler::doInit(const InputAssemblerInfo &info) { - _gpuInputAssembler = CC_NEW(GLES2GPUInputAssembler); + _gpuInputAssembler = ccnew GLES2GPUInputAssembler; _gpuInputAssembler->attributes = _attributes; _gpuInputAssembler->gpuVertexBuffers.resize(_vertexBuffers.size()); for (size_t i = 0; i < _gpuInputAssembler->gpuVertexBuffers.size(); ++i) { @@ -63,7 +63,7 @@ void GLES2InputAssembler::doInit(const InputAssemblerInfo &info) { void GLES2InputAssembler::doDestroy() { if (_gpuInputAssembler) { cmdFuncGLES2DestroyInputAssembler(GLES2Device::getInstance(), _gpuInputAssembler); - CC_DELETE(_gpuInputAssembler); + delete _gpuInputAssembler; _gpuInputAssembler = nullptr; } } diff --git a/native/cocos/renderer/gfx-gles2/GLES2PipelineLayout.cpp b/native/cocos/renderer/gfx-gles2/GLES2PipelineLayout.cpp index a44fb61cd5..7ae6e42419 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2PipelineLayout.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2PipelineLayout.cpp @@ -43,7 +43,7 @@ GLES2PipelineLayout::~GLES2PipelineLayout() { } void GLES2PipelineLayout::doInit(const PipelineLayoutInfo & /*info*/) { - _gpuPipelineLayout = CC_NEW(GLES2GPUPipelineLayout); + _gpuPipelineLayout = ccnew GLES2GPUPipelineLayout; uint32_t offset = 0U; _gpuPipelineLayout->dynamicOffsetIndices.resize(_setLayouts.size()); diff --git a/native/cocos/renderer/gfx-gles2/GLES2PipelineState.cpp b/native/cocos/renderer/gfx-gles2/GLES2PipelineState.cpp index c6d0b3c511..24c066e46a 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2PipelineState.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2PipelineState.cpp @@ -60,7 +60,7 @@ GLES2PipelineState::~GLES2PipelineState() { } void GLES2PipelineState::doInit(const PipelineStateInfo & /*info*/) { - _gpuPipelineState = CC_NEW(GLES2GPUPipelineState); + _gpuPipelineState = ccnew GLES2GPUPipelineState; _gpuPipelineState->glPrimitive = GLE_S2_PRIMITIVES[static_cast(_primitive)]; _gpuPipelineState->gpuShader = static_cast(_shader)->gpuShader(); _gpuPipelineState->rs = _rasterizerState; @@ -77,10 +77,7 @@ void GLES2PipelineState::doInit(const PipelineStateInfo & /*info*/) { } void GLES2PipelineState::doDestroy() { - if (_gpuPipelineState) { - CC_DELETE(_gpuPipelineState); - _gpuPipelineState = nullptr; - } + CC_SAFE_DELETE(_gpuPipelineState); } } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles2/GLES2RenderPass.cpp b/native/cocos/renderer/gfx-gles2/GLES2RenderPass.cpp index 751a5f5fbc..8638fc8fc1 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2RenderPass.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2RenderPass.cpp @@ -41,7 +41,7 @@ GLES2RenderPass::~GLES2RenderPass() { } void GLES2RenderPass::doInit(const RenderPassInfo & /*info*/) { - _gpuRenderPass = CC_NEW(GLES2GPURenderPass); + _gpuRenderPass = ccnew GLES2GPURenderPass; _gpuRenderPass->colorAttachments = _colorAttachments; _gpuRenderPass->depthStencilAttachment = _depthStencilAttachment; _gpuRenderPass->subpasses = _subpasses; @@ -76,7 +76,7 @@ void GLES2RenderPass::doInit(const RenderPassInfo & /*info*/) { void GLES2RenderPass::doDestroy() { if (_gpuRenderPass) { cmdFuncGLES2CreateRenderPass(GLES2Device::getInstance(), _gpuRenderPass); - CC_DELETE(_gpuRenderPass); + delete _gpuRenderPass; _gpuRenderPass = nullptr; } } diff --git a/native/cocos/renderer/gfx-gles2/GLES2Shader.cpp b/native/cocos/renderer/gfx-gles2/GLES2Shader.cpp index 706412d4cb..386930ec47 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Shader.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Shader.cpp @@ -41,7 +41,7 @@ GLES2Shader::~GLES2Shader() { } void GLES2Shader::doInit(const ShaderInfo & /*info*/) { - _gpuShader = CC_NEW(GLES2GPUShader); + _gpuShader = ccnew GLES2GPUShader; _gpuShader->name = _name; _gpuShader->blocks = _blocks; _gpuShader->samplerTextures = _samplerTextures; @@ -57,7 +57,7 @@ void GLES2Shader::doInit(const ShaderInfo & /*info*/) { void GLES2Shader::doDestroy() { if (_gpuShader) { cmdFuncGLES2DestroyShader(GLES2Device::getInstance(), _gpuShader); - CC_DELETE(_gpuShader); + delete _gpuShader; _gpuShader = nullptr; } } diff --git a/native/cocos/renderer/gfx-gles2/GLES2Swapchain.cpp b/native/cocos/renderer/gfx-gles2/GLES2Swapchain.cpp index 53717b53f5..e2bd89f820 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Swapchain.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Swapchain.cpp @@ -53,7 +53,7 @@ GLES2Swapchain::~GLES2Swapchain() { void GLES2Swapchain::doInit(const SwapchainInfo &info) { const auto *context = GLES2Device::getInstance()->context(); - _gpuSwapchain = CC_NEW(GLES2GPUSwapchain); + _gpuSwapchain = ccnew GLES2GPUSwapchain; auto window = reinterpret_cast(info.windowHandle); //NOLINT[readability-qualified-auto] #if CC_PLATFORM == CC_PLATFORM_ANDROID || CC_PLATFORM == CC_PLATFORM_OHOS @@ -109,8 +109,8 @@ void GLES2Swapchain::doInit(const SwapchainInfo &info) { ///////////////////// Texture Creation ///////////////////// - _colorTexture = CC_NEW(GLES2Texture); - _depthStencilTexture = CC_NEW(GLES2Texture); + _colorTexture = ccnew GLES2Texture; + _depthStencilTexture = ccnew GLES2Texture; SwapchainTextureInfo textureInfo; textureInfo.swapchain = this; diff --git a/native/cocos/renderer/gfx-gles2/GLES2Texture.cpp b/native/cocos/renderer/gfx-gles2/GLES2Texture.cpp index c96e0f00b6..8447d3c310 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Texture.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Texture.cpp @@ -43,7 +43,7 @@ GLES2Texture::~GLES2Texture() { } void GLES2Texture::doInit(const TextureInfo & /*info*/) { - _gpuTexture = CC_NEW(GLES2GPUTexture); + _gpuTexture = ccnew GLES2GPUTexture; _gpuTexture->type = _info.type; _gpuTexture->format = _info.format; _gpuTexture->usage = _info.usage; @@ -79,7 +79,7 @@ void GLES2Texture::doDestroy() { } cmdFuncGLES2DestroyTexture(GLES2Device::getInstance(), _gpuTexture); GLES2Device::getInstance()->framebufferHub()->disengage(_gpuTexture); - CC_DELETE(_gpuTexture); + delete _gpuTexture; } _gpuTexture = nullptr; } @@ -107,7 +107,7 @@ void GLES2Texture::doResize(uint32_t width, uint32_t height, uint32_t size) { ///////////////////////////// Swapchain Specific ///////////////////////////// void GLES2Texture::doInit(const SwapchainTextureInfo & /*info*/) { - _gpuTexture = CC_NEW(GLES2GPUTexture); + _gpuTexture = ccnew GLES2GPUTexture; _gpuTexture->type = _info.type; _gpuTexture->format = _info.format; _gpuTexture->usage = _info.usage; diff --git a/native/cocos/renderer/gfx-gles2/states/GLES2Sampler.cpp b/native/cocos/renderer/gfx-gles2/states/GLES2Sampler.cpp index 9e80cd1e86..7c53ab6641 100644 --- a/native/cocos/renderer/gfx-gles2/states/GLES2Sampler.cpp +++ b/native/cocos/renderer/gfx-gles2/states/GLES2Sampler.cpp @@ -33,7 +33,7 @@ namespace gfx { GLES2Sampler::GLES2Sampler(const SamplerInfo &info) : Sampler(info) { _typedID = generateObjectID(); - _gpuSampler = CC_NEW(GLES2GPUSampler); + _gpuSampler = ccnew GLES2GPUSampler; _gpuSampler->minFilter = _info.minFilter; _gpuSampler->magFilter = _info.magFilter; _gpuSampler->mipFilter = _info.mipFilter; @@ -47,7 +47,7 @@ GLES2Sampler::GLES2Sampler(const SamplerInfo &info) : Sampler(info) { GLES2Sampler::~GLES2Sampler() { if (_gpuSampler) { cmdFuncGLES2DestroySampler(GLES2Device::getInstance(), _gpuSampler); - CC_DELETE(_gpuSampler); + delete _gpuSampler; _gpuSampler = nullptr; } } diff --git a/native/cocos/renderer/gfx-gles3/GLES3Buffer.cpp b/native/cocos/renderer/gfx-gles3/GLES3Buffer.cpp index 9465597c96..0e13cda487 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Buffer.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Buffer.cpp @@ -42,7 +42,7 @@ GLES3Buffer::~GLES3Buffer() { } void GLES3Buffer::doInit(const BufferInfo & /*info*/) { - _gpuBuffer = CC_NEW(GLES3GPUBuffer); + _gpuBuffer = ccnew GLES3GPUBuffer; _gpuBuffer->usage = _usage; _gpuBuffer->memUsage = _memUsage; _gpuBuffer->size = _size; @@ -60,7 +60,7 @@ void GLES3Buffer::doInit(const BufferInfo & /*info*/) { void GLES3Buffer::doInit(const BufferViewInfo &info) { auto *buffer = static_cast(info.buffer); - _gpuBuffer = CC_NEW(GLES3GPUBuffer); + _gpuBuffer = ccnew GLES3GPUBuffer; _gpuBuffer->usage = _usage; _gpuBuffer->memUsage = _memUsage; _gpuBuffer->size = _size; @@ -80,7 +80,7 @@ void GLES3Buffer::doDestroy() { GLES3Device::getInstance()->getMemoryStatus().bufferSize -= _size; CC_PROFILE_MEMORY_DEC(Buffer, _size); } - CC_DELETE(_gpuBuffer); + delete _gpuBuffer; _gpuBuffer = nullptr; } } diff --git a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp index 30cde51ede..3d04777917 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp @@ -51,8 +51,8 @@ GLES3CommandBuffer::~GLES3CommandBuffer() { } void GLES3CommandBuffer::doInit(const CommandBufferInfo & /*info*/) { - _cmdAllocator = CC_NEW(GLES3GPUCommandAllocator); - _curCmdPackage = CC_NEW(GLES3CmdPackage); + _cmdAllocator = ccnew GLES3GPUCommandAllocator; + _curCmdPackage = ccnew GLES3CmdPackage; size_t setCount = GLES3Device::getInstance()->bindingMappingInfo().setIndices.size(); _curGPUDescriptorSets.resize(setCount); @@ -105,7 +105,7 @@ void GLES3CommandBuffer::end() { _curCmdPackage = _freePackages.front(); _freePackages.pop(); } else { - _curCmdPackage = CC_NEW(GLES3CmdPackage); + _curCmdPackage = ccnew GLES3CmdPackage; } } diff --git a/native/cocos/renderer/gfx-gles3/GLES3DescriptorSet.cpp b/native/cocos/renderer/gfx-gles3/GLES3DescriptorSet.cpp index e2a12a51f7..b7ba200b4d 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3DescriptorSet.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3DescriptorSet.cpp @@ -49,7 +49,7 @@ void GLES3DescriptorSet::doInit(const DescriptorSetInfo & /*info*/) { const size_t descriptorCount = gpuDescriptorSetLayout->descriptorCount; const size_t bindingCount = gpuDescriptorSetLayout->bindings.size(); - _gpuDescriptorSet = CC_NEW(GLES3GPUDescriptorSet); + _gpuDescriptorSet = ccnew GLES3GPUDescriptorSet; _gpuDescriptorSet->gpuDescriptors.resize(descriptorCount); for (size_t i = 0U, k = 0U; i < bindingCount; i++) { const DescriptorSetLayoutBinding &binding = gpuDescriptorSetLayout->bindings[i]; @@ -62,10 +62,7 @@ void GLES3DescriptorSet::doInit(const DescriptorSetInfo & /*info*/) { } void GLES3DescriptorSet::doDestroy() { - if (_gpuDescriptorSet) { - CC_DELETE(_gpuDescriptorSet); - _gpuDescriptorSet = nullptr; - } + CC_SAFE_DELETE(_gpuDescriptorSet); } void GLES3DescriptorSet::update() { diff --git a/native/cocos/renderer/gfx-gles3/GLES3DescriptorSetLayout.cpp b/native/cocos/renderer/gfx-gles3/GLES3DescriptorSetLayout.cpp index 78cbec491d..95a2f936fc 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3DescriptorSetLayout.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3DescriptorSetLayout.cpp @@ -40,7 +40,7 @@ GLES3DescriptorSetLayout::~GLES3DescriptorSetLayout() { } void GLES3DescriptorSetLayout::doInit(const DescriptorSetLayoutInfo & /*info*/) { - _gpuDescriptorSetLayout = CC_NEW(GLES3GPUDescriptorSetLayout); + _gpuDescriptorSetLayout = ccnew GLES3GPUDescriptorSetLayout; _gpuDescriptorSetLayout->descriptorCount = _descriptorCount; _gpuDescriptorSetLayout->bindingIndices = _bindingIndices; _gpuDescriptorSetLayout->descriptorIndices = _descriptorIndices; @@ -56,10 +56,7 @@ void GLES3DescriptorSetLayout::doInit(const DescriptorSetLayoutInfo & /*info*/) } void GLES3DescriptorSetLayout::doDestroy() { - if (_gpuDescriptorSetLayout) { - CC_DELETE(_gpuDescriptorSetLayout); - _gpuDescriptorSetLayout = nullptr; - } + CC_SAFE_DELETE(_gpuDescriptorSetLayout); } } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles3/GLES3Device.cpp b/native/cocos/renderer/gfx-gles3/GLES3Device.cpp index 74e3f7c2d0..73fd683bc9 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Device.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Device.cpp @@ -72,11 +72,11 @@ GLES3Device::~GLES3Device() { } bool GLES3Device::doInit(const DeviceInfo & /*info*/) { - _gpuContext = CC_NEW(GLES3GPUContext); - _gpuStateCache = CC_NEW(GLES3GPUStateCache); - _gpuFramebufferHub = CC_NEW(GLES3GPUFramebufferHub); - _gpuConstantRegistry = CC_NEW(GLES3GPUConstantRegistry); - _gpuFramebufferCacheMap = CC_NEW(GLES3GPUFramebufferCacheMap(_gpuStateCache)); + _gpuContext = ccnew GLES3GPUContext; + _gpuStateCache = ccnew GLES3GPUStateCache; + _gpuFramebufferHub = ccnew GLES3GPUFramebufferHub; + _gpuConstantRegistry = ccnew GLES3GPUConstantRegistry; + _gpuFramebufferCacheMap = ccnew GLES3GPUFramebufferCacheMap(_gpuStateCache); if (!_gpuContext->initialize(_gpuStateCache, _gpuConstantRegistry)) { destroy(); @@ -476,68 +476,68 @@ void GLES3Device::initFormatFeature() { } CommandBuffer *GLES3Device::createCommandBuffer(const CommandBufferInfo &info, bool hasAgent) { - if (hasAgent || info.type == CommandBufferType::PRIMARY) return CC_NEW(GLES3PrimaryCommandBuffer); - return CC_NEW(GLES3CommandBuffer); + if (hasAgent || info.type == CommandBufferType::PRIMARY) return ccnew GLES3PrimaryCommandBuffer; + return ccnew GLES3CommandBuffer; } Queue *GLES3Device::createQueue() { - return CC_NEW(GLES3Queue); + return ccnew GLES3Queue; } QueryPool *GLES3Device::createQueryPool() { - return CC_NEW(GLES3QueryPool); + return ccnew GLES3QueryPool; } Swapchain *GLES3Device::createSwapchain() { - return CC_NEW(GLES3Swapchain); + return ccnew GLES3Swapchain; } Buffer *GLES3Device::createBuffer() { - return CC_NEW(GLES3Buffer); + return ccnew GLES3Buffer; } Texture *GLES3Device::createTexture() { - return CC_NEW(GLES3Texture); + return ccnew GLES3Texture; } Shader *GLES3Device::createShader() { - return CC_NEW(GLES3Shader); + return ccnew GLES3Shader; } InputAssembler *GLES3Device::createInputAssembler() { - return CC_NEW(GLES3InputAssembler); + return ccnew GLES3InputAssembler; } RenderPass *GLES3Device::createRenderPass() { - return CC_NEW(GLES3RenderPass); + return ccnew GLES3RenderPass; } Framebuffer *GLES3Device::createFramebuffer() { - return CC_NEW(GLES3Framebuffer); + return ccnew GLES3Framebuffer; } DescriptorSet *GLES3Device::createDescriptorSet() { - return CC_NEW(GLES3DescriptorSet); + return ccnew GLES3DescriptorSet; } DescriptorSetLayout *GLES3Device::createDescriptorSetLayout() { - return CC_NEW(GLES3DescriptorSetLayout); + return ccnew GLES3DescriptorSetLayout; } PipelineLayout *GLES3Device::createPipelineLayout() { - return CC_NEW(GLES3PipelineLayout); + return ccnew GLES3PipelineLayout; } PipelineState *GLES3Device::createPipelineState() { - return CC_NEW(GLES3PipelineState); + return ccnew GLES3PipelineState; } Sampler *GLES3Device::createSampler(const SamplerInfo &info) { - return CC_NEW(GLES3Sampler(info)); + return ccnew GLES3Sampler(info); } GeneralBarrier *GLES3Device::createGeneralBarrier(const GeneralBarrierInfo &info) { - return CC_NEW(GLES3GeneralBarrier(info)); + return ccnew GLES3GeneralBarrier(info); } void GLES3Device::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) { diff --git a/native/cocos/renderer/gfx-gles3/GLES3Framebuffer.cpp b/native/cocos/renderer/gfx-gles3/GLES3Framebuffer.cpp index a5bbd64960..2d3d0292f1 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Framebuffer.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Framebuffer.cpp @@ -43,7 +43,7 @@ GLES3Framebuffer::~GLES3Framebuffer() { } void GLES3Framebuffer::doInit(const FramebufferInfo & /*info*/) { - _gpuFBO = CC_NEW(GLES3GPUFramebuffer); + _gpuFBO = ccnew GLES3GPUFramebuffer; _gpuFBO->gpuRenderPass = static_cast(_renderPass)->gpuRenderPass(); _gpuFBO->gpuColorViews.resize(_colorTextures.size()); @@ -75,7 +75,7 @@ void GLES3Framebuffer::doDestroy() { GLES3Device::getInstance()->framebufferHub()->disengage(depthTexture->gpuTexture(), _gpuFBO); } - CC_DELETE(_gpuFBO); + delete _gpuFBO; _gpuFBO = nullptr; } } diff --git a/native/cocos/renderer/gfx-gles3/GLES3InputAssembler.cpp b/native/cocos/renderer/gfx-gles3/GLES3InputAssembler.cpp index 44defe028d..017d751ff7 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3InputAssembler.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3InputAssembler.cpp @@ -42,7 +42,7 @@ GLES3InputAssembler::~GLES3InputAssembler() { } void GLES3InputAssembler::doInit(const InputAssemblerInfo &info) { - _gpuInputAssembler = CC_NEW(GLES3GPUInputAssembler); + _gpuInputAssembler = ccnew GLES3GPUInputAssembler; _gpuInputAssembler->attributes = _attributes; _gpuInputAssembler->gpuVertexBuffers.resize(_vertexBuffers.size()); for (size_t i = 0; i < _gpuInputAssembler->gpuVertexBuffers.size(); ++i) { @@ -63,7 +63,7 @@ void GLES3InputAssembler::doInit(const InputAssemblerInfo &info) { void GLES3InputAssembler::doDestroy() { if (_gpuInputAssembler) { cmdFuncGLES3DestroyInputAssembler(GLES3Device::getInstance(), _gpuInputAssembler); - CC_DELETE(_gpuInputAssembler); + delete _gpuInputAssembler; _gpuInputAssembler = nullptr; } } diff --git a/native/cocos/renderer/gfx-gles3/GLES3PipelineLayout.cpp b/native/cocos/renderer/gfx-gles3/GLES3PipelineLayout.cpp index 6ebd031255..42a5d22cb0 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3PipelineLayout.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3PipelineLayout.cpp @@ -42,7 +42,7 @@ GLES3PipelineLayout::~GLES3PipelineLayout() { } void GLES3PipelineLayout::doInit(const PipelineLayoutInfo & /*info*/) { - _gpuPipelineLayout = CC_NEW(GLES3GPUPipelineLayout); + _gpuPipelineLayout = ccnew GLES3GPUPipelineLayout; uint32_t offset = 0U; _gpuPipelineLayout->dynamicOffsetIndices.resize(_setLayouts.size()); @@ -67,10 +67,7 @@ void GLES3PipelineLayout::doInit(const PipelineLayoutInfo & /*info*/) { } void GLES3PipelineLayout::doDestroy() { - if (_gpuPipelineLayout) { - CC_DELETE(_gpuPipelineLayout); - _gpuPipelineLayout = nullptr; - } + CC_SAFE_DELETE(_gpuPipelineLayout); } } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles3/GLES3PipelineState.cpp b/native/cocos/renderer/gfx-gles3/GLES3PipelineState.cpp index 2394ab0548..774215fce6 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3PipelineState.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3PipelineState.cpp @@ -60,7 +60,7 @@ GLES3PipelineState::~GLES3PipelineState() { } void GLES3PipelineState::doInit(const PipelineStateInfo & /*info*/) { - _gpuPipelineState = CC_NEW(GLES3GPUPipelineState); + _gpuPipelineState = ccnew GLES3GPUPipelineState; _gpuPipelineState->glPrimitive = GLE_S3_PRIMITIVES[static_cast(_primitive)]; _gpuPipelineState->gpuShader = static_cast(_shader)->gpuShader(); _gpuPipelineState->rs = _rasterizerState; @@ -77,10 +77,7 @@ void GLES3PipelineState::doInit(const PipelineStateInfo & /*info*/) { } void GLES3PipelineState::doDestroy() { - if (_gpuPipelineState) { - CC_DELETE(_gpuPipelineState); - _gpuPipelineState = nullptr; - } + CC_SAFE_DELETE(_gpuPipelineState); } } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles3/GLES3QueryPool.cpp b/native/cocos/renderer/gfx-gles3/GLES3QueryPool.cpp index 7b298a81ff..a30c4674ae 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3QueryPool.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3QueryPool.cpp @@ -42,7 +42,7 @@ GLES3QueryPool::~GLES3QueryPool() { void GLES3QueryPool::doInit(const QueryPoolInfo & /*info*/) { GLES3Device *device = GLES3Device::getInstance(); if (device->getCapabilities().supportQuery) { - _gpuQueryPool = CC_NEW(GLES3GPUQueryPool); + _gpuQueryPool = ccnew GLES3GPUQueryPool; _gpuQueryPool->type = _type; _gpuQueryPool->maxQueryObjects = _maxQueryObjects; _gpuQueryPool->forceWait = _forceWait; @@ -55,7 +55,7 @@ void GLES3QueryPool::doInit(const QueryPoolInfo & /*info*/) { void GLES3QueryPool::doDestroy() { if (_gpuQueryPool) { cmdFuncGLES3DestroyQueryPool(GLES3Device::getInstance(), _gpuQueryPool); - CC_DELETE(_gpuQueryPool); + delete _gpuQueryPool; _gpuQueryPool = nullptr; } } diff --git a/native/cocos/renderer/gfx-gles3/GLES3RenderPass.cpp b/native/cocos/renderer/gfx-gles3/GLES3RenderPass.cpp index bcff8236ea..69413dd007 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3RenderPass.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3RenderPass.cpp @@ -42,7 +42,7 @@ GLES3RenderPass::~GLES3RenderPass() { } void GLES3RenderPass::doInit(const RenderPassInfo & /*info*/) { - _gpuRenderPass = CC_NEW(GLES3GPURenderPass); + _gpuRenderPass = ccnew GLES3GPURenderPass; _gpuRenderPass->colorAttachments = _colorAttachments; _gpuRenderPass->depthStencilAttachment = _depthStencilAttachment; _gpuRenderPass->subpasses = _subpasses; @@ -77,7 +77,7 @@ void GLES3RenderPass::doInit(const RenderPassInfo & /*info*/) { void GLES3RenderPass::doDestroy() { if (_gpuRenderPass) { cmdFuncGLES3DestroyRenderPass(GLES3Device::getInstance(), _gpuRenderPass); - CC_DELETE(_gpuRenderPass); + delete _gpuRenderPass; _gpuRenderPass = nullptr; } } diff --git a/native/cocos/renderer/gfx-gles3/GLES3Shader.cpp b/native/cocos/renderer/gfx-gles3/GLES3Shader.cpp index 5eb427aabe..e767b94818 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Shader.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Shader.cpp @@ -41,7 +41,7 @@ GLES3Shader::~GLES3Shader() { } void GLES3Shader::doInit(const ShaderInfo & /*info*/) { - _gpuShader = CC_NEW(GLES3GPUShader); + _gpuShader = ccnew GLES3GPUShader; _gpuShader->name = _name; _gpuShader->blocks = _blocks; _gpuShader->buffers = _buffers; @@ -61,7 +61,7 @@ void GLES3Shader::doInit(const ShaderInfo & /*info*/) { void GLES3Shader::doDestroy() { if (_gpuShader) { cmdFuncGLES3DestroyShader(GLES3Device::getInstance(), _gpuShader); - CC_DELETE(_gpuShader); + delete _gpuShader; _gpuShader = nullptr; } } diff --git a/native/cocos/renderer/gfx-gles3/GLES3Swapchain.cpp b/native/cocos/renderer/gfx-gles3/GLES3Swapchain.cpp index 1349dfd67c..2821c9be6b 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Swapchain.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Swapchain.cpp @@ -53,7 +53,7 @@ GLES3Swapchain::~GLES3Swapchain() { void GLES3Swapchain::doInit(const SwapchainInfo &info) { const auto *context = GLES3Device::getInstance()->context(); - _gpuSwapchain = CC_NEW(GLES3GPUSwapchain); + _gpuSwapchain = ccnew GLES3GPUSwapchain; #if CC_PLATFORM == CC_PLATFORM_LINUX auto window = reinterpret_cast(info.windowHandle); #else @@ -113,8 +113,8 @@ void GLES3Swapchain::doInit(const SwapchainInfo &info) { ///////////////////// Texture Creation ///////////////////// - _colorTexture = CC_NEW(GLES3Texture); - _depthStencilTexture = CC_NEW(GLES3Texture); + _colorTexture = ccnew GLES3Texture; + _depthStencilTexture = ccnew GLES3Texture; SwapchainTextureInfo textureInfo; textureInfo.swapchain = this; diff --git a/native/cocos/renderer/gfx-gles3/GLES3Texture.cpp b/native/cocos/renderer/gfx-gles3/GLES3Texture.cpp index a2884d8b46..e7a325e75c 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Texture.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Texture.cpp @@ -44,7 +44,7 @@ GLES3Texture::~GLES3Texture() { } void GLES3Texture::doInit(const TextureInfo & /*info*/) { - _gpuTexture = CC_NEW(GLES3GPUTexture); + _gpuTexture = ccnew GLES3GPUTexture; _gpuTexture->type = _info.type; _gpuTexture->format = _info.format; _gpuTexture->usage = _info.usage; @@ -66,7 +66,7 @@ void GLES3Texture::doInit(const TextureInfo & /*info*/) { CC_PROFILE_MEMORY_INC(Texture, _size); } - _gpuTextureView = CC_NEW(GLES3GPUTextureView); + _gpuTextureView = ccnew GLES3GPUTextureView; createTextureView(); } @@ -75,7 +75,7 @@ void GLES3Texture::doInit(const TextureViewInfo & /*info*/) { CC_ASSERT(_viewInfo.texture->getFormat() == _viewInfo.format); - _gpuTextureView = CC_NEW(GLES3GPUTextureView); + _gpuTextureView = ccnew GLES3GPUTextureView; createTextureView(); } @@ -88,10 +88,7 @@ void GLES3Texture::createTextureView() { } void GLES3Texture::doDestroy() { - if (_gpuTextureView) { - CC_DELETE(_gpuTextureView); - _gpuTextureView = nullptr; - } + CC_SAFE_DELETE(_gpuTextureView); if (_gpuTexture) { if (!_isTextureView) { if (!_gpuTexture->memoryless) { @@ -101,7 +98,7 @@ void GLES3Texture::doDestroy() { cmdFuncGLES3DestroyTexture(GLES3Device::getInstance(), _gpuTexture); GLES3Device::getInstance()->framebufferHub()->disengage(_gpuTexture); - CC_DELETE(_gpuTexture); + delete _gpuTexture; } _gpuTexture = nullptr; } @@ -131,7 +128,7 @@ void GLES3Texture::doResize(uint32_t width, uint32_t height, uint32_t size) { ///////////////////////////// Swapchain Specific ///////////////////////////// void GLES3Texture::doInit(const SwapchainTextureInfo & /*info*/) { - _gpuTexture = CC_NEW(GLES3GPUTexture); + _gpuTexture = ccnew GLES3GPUTexture; _gpuTexture->type = _info.type; _gpuTexture->format = _info.format; _gpuTexture->usage = _info.usage; @@ -145,7 +142,7 @@ void GLES3Texture::doInit(const SwapchainTextureInfo & /*info*/) { _gpuTexture->size = _size; _gpuTexture->memoryless = true; _gpuTexture->swapchain = static_cast(_swapchain)->gpuSwapchain(); - _gpuTextureView = CC_NEW(GLES3GPUTextureView); + _gpuTextureView = ccnew GLES3GPUTextureView; createTextureView(); } diff --git a/native/cocos/renderer/gfx-gles3/states/GLES3GeneralBarrier.cpp b/native/cocos/renderer/gfx-gles3/states/GLES3GeneralBarrier.cpp index deccbe113b..9dcda963d0 100644 --- a/native/cocos/renderer/gfx-gles3/states/GLES3GeneralBarrier.cpp +++ b/native/cocos/renderer/gfx-gles3/states/GLES3GeneralBarrier.cpp @@ -33,7 +33,7 @@ namespace gfx { GLES3GeneralBarrier::GLES3GeneralBarrier(const GeneralBarrierInfo &info) : GeneralBarrier(info) { _typedID = generateObjectID(); - _gpuBarrier = CC_NEW(GLES3GPUGeneralBarrier); + _gpuBarrier = ccnew GLES3GPUGeneralBarrier; _gpuBarrier->prevAccesses = info.prevAccesses; _gpuBarrier->nextAccesses = info.nextAccesses; diff --git a/native/cocos/renderer/gfx-gles3/states/GLES3Sampler.cpp b/native/cocos/renderer/gfx-gles3/states/GLES3Sampler.cpp index f8b4c8ae9a..442ae118a9 100644 --- a/native/cocos/renderer/gfx-gles3/states/GLES3Sampler.cpp +++ b/native/cocos/renderer/gfx-gles3/states/GLES3Sampler.cpp @@ -33,7 +33,7 @@ namespace gfx { GLES3Sampler::GLES3Sampler(const SamplerInfo &info) : Sampler(info) { _typedID = generateObjectID(); - _gpuSampler = CC_NEW(GLES3GPUSampler); + _gpuSampler = ccnew GLES3GPUSampler; _gpuSampler->minFilter = _info.minFilter; _gpuSampler->magFilter = _info.magFilter; _gpuSampler->mipFilter = _info.mipFilter; @@ -46,10 +46,7 @@ GLES3Sampler::GLES3Sampler(const SamplerInfo &info) : Sampler(info) { } GLES3Sampler::~GLES3Sampler() { - if (_gpuSampler) { - CC_DELETE(_gpuSampler); - _gpuSampler = nullptr; - } + CC_SAFE_DELETE(_gpuSampler); } } // namespace gfx diff --git a/native/cocos/renderer/gfx-metal/MTLBuffer.mm b/native/cocos/renderer/gfx-metal/MTLBuffer.mm index 147e3a2778..87fcb25a68 100644 --- a/native/cocos/renderer/gfx-metal/MTLBuffer.mm +++ b/native/cocos/renderer/gfx-metal/MTLBuffer.mm @@ -47,7 +47,7 @@ CCMTLBuffer::~CCMTLBuffer() { } void CCMTLBuffer::doInit(const BufferInfo &info) { - _gpuBuffer = CC_NEW(CCMTLGPUBuffer); + _gpuBuffer = ccnew CCMTLGPUBuffer; _gpuBuffer->count = _count; _gpuBuffer->mappedData = nullptr; _gpuBuffer->size = _size; diff --git a/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm b/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm index 50e02ca26c..6f7979143d 100644 --- a/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm +++ b/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm @@ -63,14 +63,11 @@ CCMTLCommandBuffer::~CCMTLCommandBuffer() { } void CCMTLCommandBuffer::doInit(const CommandBufferInfo &info) { - _gpuCommandBufferObj = CC_NEW(CCMTLGPUCommandBufferObject); + _gpuCommandBufferObj = ccnew CCMTLGPUCommandBufferObject; } void CCMTLCommandBuffer::doDestroy() { - if(_texCopySemaphore) { - CC_DELETE(_texCopySemaphore); - _texCopySemaphore = nullptr; - } + CC_SAFE_DELETE(_texCopySemaphore); if(_commandBufferBegan) { if(_gpuCommandBufferObj && _gpuCommandBufferObj->mtlCommandBuffer) { @@ -959,7 +956,7 @@ void CCMTLCommandBuffer::copyTextureToBuffers(Texture *src, uint8_t *const *buff stagingAddrs[i] = {stagingBuffer.mappedData, bytesPerImage}; } if(!_texCopySemaphore) { - _texCopySemaphore = CC_NEW(CCMTLSemaphore(0)); + _texCopySemaphore = ccnew CCMTLSemaphore(0); } [mtlCommandBuffer addCompletedHandler:^(id commandBuffer) { diff --git a/native/cocos/renderer/gfx-metal/MTLDescriptorSet.mm b/native/cocos/renderer/gfx-metal/MTLDescriptorSet.mm index 5a3df57b6f..78ad18f89e 100644 --- a/native/cocos/renderer/gfx-metal/MTLDescriptorSet.mm +++ b/native/cocos/renderer/gfx-metal/MTLDescriptorSet.mm @@ -41,7 +41,7 @@ void CCMTLDescriptorSet::doInit(const DescriptorSetInfo &info) { const auto descriptorCount = gpuDescriptorSetLayout->descriptorCount; const auto bindingCount = gpuDescriptorSetLayout->bindings.size(); - _gpuDescriptorSet = CC_NEW(CCMTLGPUDescriptorSet); + _gpuDescriptorSet = ccnew CCMTLGPUDescriptorSet; _gpuDescriptorSet->descriptorIndices = &gpuDescriptorSetLayout->descriptorIndices; _gpuDescriptorSet->gpuDescriptors.resize(descriptorCount); for (auto i = 0u, k = 0u; i < bindingCount; i++) { diff --git a/native/cocos/renderer/gfx-metal/MTLDescriptorSetLayout.mm b/native/cocos/renderer/gfx-metal/MTLDescriptorSetLayout.mm index b0ec88c90b..c15ba154aa 100644 --- a/native/cocos/renderer/gfx-metal/MTLDescriptorSetLayout.mm +++ b/native/cocos/renderer/gfx-metal/MTLDescriptorSetLayout.mm @@ -38,7 +38,7 @@ CCMTLDescriptorSetLayout::~CCMTLDescriptorSetLayout () { } void CCMTLDescriptorSetLayout::doInit(const DescriptorSetLayoutInfo &info) { - _gpuDescriptorSetLayout = CC_NEW(CCMTLGPUDescriptorSetLayout); + _gpuDescriptorSetLayout = ccnew CCMTLGPUDescriptorSetLayout; _gpuDescriptorSetLayout->descriptorCount = _descriptorCount; _gpuDescriptorSetLayout->descriptorIndices = _descriptorIndices; diff --git a/native/cocos/renderer/gfx-metal/MTLDevice.mm b/native/cocos/renderer/gfx-metal/MTLDevice.mm index 1674213e8c..d469369d67 100644 --- a/native/cocos/renderer/gfx-metal/MTLDevice.mm +++ b/native/cocos/renderer/gfx-metal/MTLDevice.mm @@ -73,8 +73,8 @@ CCMTLDevice::~CCMTLDevice() { } bool CCMTLDevice::doInit(const DeviceInfo &info) { - _gpuDeviceObj = CC_NEW(CCMTLGPUDeviceObject); - _inFlightSemaphore = CC_NEW(CCMTLSemaphore(MAX_FRAMES_IN_FLIGHT)); + _gpuDeviceObj = ccnew CCMTLGPUDeviceObject; + _inFlightSemaphore = ccnew CCMTLSemaphore(MAX_FRAMES_IN_FLIGHT); _currentFrameIndex = 0; id mtlDevice = MTLCreateSystemDefaultDevice(); @@ -97,7 +97,7 @@ bool CCMTLDevice::doInit(const DeviceInfo &info) { _isSamplerDescriptorCompareFunctionSupported = mu::isSamplerDescriptorCompareFunctionSupported(gpuFamily); for (int i = 0; i < MAX_FRAMES_IN_FLIGHT; ++i) { - _gpuStagingBufferPools[i] = CC_NEW(CCMTLGPUStagingBufferPool(mtlDevice)); + _gpuStagingBufferPools[i] = ccnew CCMTLGPUStagingBufferPool(mtlDevice); } initFormatFeatures(gpuFamily); @@ -154,7 +154,7 @@ void CCMTLDevice::doDestroy() { // _memoryAlarmListenerId = 0; // } - CC_DELETE(_gpuDeviceObj); + CC_SAFE_DELETE(_gpuDeviceObj); CC_SAFE_DESTROY_AND_DELETE(_queryPool) CC_SAFE_DESTROY_AND_DELETE(_queue); @@ -247,63 +247,63 @@ void CCMTLDevice::onPresentCompleted() { } Queue *CCMTLDevice::createQueue() { - return CC_NEW(CCMTLQueue); + return ccnew CCMTLQueue; } QueryPool *CCMTLDevice::createQueryPool() { - return CC_NEW(CCMTLQueryPool); + return ccnew CCMTLQueryPool; } CommandBuffer *CCMTLDevice::createCommandBuffer(const CommandBufferInfo &info, bool /*hasAgent*/) { - return CC_NEW(CCMTLCommandBuffer); + return ccnew CCMTLCommandBuffer; } Buffer *CCMTLDevice::createBuffer() { - return CC_NEW(CCMTLBuffer); + return ccnew CCMTLBuffer; } Texture *CCMTLDevice::createTexture() { - return CC_NEW(CCMTLTexture); + return ccnew CCMTLTexture; } Shader *CCMTLDevice::createShader() { - return CC_NEW(CCMTLShader); + return ccnew CCMTLShader; } InputAssembler *CCMTLDevice::createInputAssembler() { - return CC_NEW(CCMTLInputAssembler); + return ccnew CCMTLInputAssembler; } RenderPass *CCMTLDevice::createRenderPass() { - return CC_NEW(CCMTLRenderPass); + return ccnew CCMTLRenderPass; } Framebuffer *CCMTLDevice::createFramebuffer() { - return CC_NEW(CCMTLFramebuffer); + return ccnew CCMTLFramebuffer; } DescriptorSet *CCMTLDevice::createDescriptorSet() { - return CC_NEW(CCMTLDescriptorSet); + return ccnew CCMTLDescriptorSet; } DescriptorSetLayout *CCMTLDevice::createDescriptorSetLayout() { - return CC_NEW(CCMTLDescriptorSetLayout); + return ccnew CCMTLDescriptorSetLayout; } PipelineLayout *CCMTLDevice::createPipelineLayout() { - return CC_NEW(CCMTLPipelineLayout); + return ccnew CCMTLPipelineLayout; } PipelineState *CCMTLDevice::createPipelineState() { - return CC_NEW(CCMTLPipelineState); + return ccnew CCMTLPipelineState; } Sampler *CCMTLDevice::createSampler(const SamplerInfo &info) { - return new CCMTLSampler(info); + return ccnew CCMTLSampler(info); } Swapchain *CCMTLDevice::createSwapchain() { - return new CCMTLSwapchain(); + return ccnew CCMTLSwapchain; } void CCMTLDevice::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) { diff --git a/native/cocos/renderer/gfx-metal/MTLInputAssembler.mm b/native/cocos/renderer/gfx-metal/MTLInputAssembler.mm index 87f22a0213..f039c95a62 100644 --- a/native/cocos/renderer/gfx-metal/MTLInputAssembler.mm +++ b/native/cocos/renderer/gfx-metal/MTLInputAssembler.mm @@ -39,7 +39,7 @@ CCMTLInputAssembler::~CCMTLInputAssembler() { } void CCMTLInputAssembler::doInit(const InputAssemblerInfo &info) { - _GPUInputAssembler = CC_NEW(CCMTLGPUInputAssembler); + _GPUInputAssembler = ccnew CCMTLGPUInputAssembler; if (!_GPUInputAssembler) { return; } diff --git a/native/cocos/renderer/gfx-metal/MTLPipelineLayout.mm b/native/cocos/renderer/gfx-metal/MTLPipelineLayout.mm index f600770825..b991cdd3ad 100644 --- a/native/cocos/renderer/gfx-metal/MTLPipelineLayout.mm +++ b/native/cocos/renderer/gfx-metal/MTLPipelineLayout.mm @@ -39,7 +39,7 @@ CCMTLPipelineLayout::~CCMTLPipelineLayout() { void CCMTLPipelineLayout::doInit(const PipelineLayoutInfo &info) { const auto setCount = _setLayouts.size(); - _gpuPipelineLayout = CC_NEW(CCMTLGPUPipelineLayout); + _gpuPipelineLayout = ccnew CCMTLGPUPipelineLayout; _gpuPipelineLayout->dynamicOffsetIndices.resize(setCount); for (size_t i = 0; i < setCount; i++) { diff --git a/native/cocos/renderer/gfx-metal/MTLPipelineState.mm b/native/cocos/renderer/gfx-metal/MTLPipelineState.mm index 5cae94e5da..4c14a361bb 100644 --- a/native/cocos/renderer/gfx-metal/MTLPipelineState.mm +++ b/native/cocos/renderer/gfx-metal/MTLPipelineState.mm @@ -109,9 +109,9 @@ void CCMTLPipelineState::check(CCMTLRenderPass *renderPass) { } bool CCMTLPipelineState::createGPUPipelineState() { - _GPUPipelineState = CC_NEW(CCMTLGPUPipelineState); + _GPUPipelineState = ccnew CCMTLGPUPipelineState; if (!_GPUPipelineState) { - CC_LOG_ERROR("CCMTLPipelineState: CC_NEW CCMTLGPUPipelineState failed."); + CC_LOG_ERROR("CCMTLPipelineState: new CCMTLGPUPipelineState failed."); return false; } diff --git a/native/cocos/renderer/gfx-metal/MTLQueryPool.mm b/native/cocos/renderer/gfx-metal/MTLQueryPool.mm index d8059a12bb..fd11f5a0ce 100644 --- a/native/cocos/renderer/gfx-metal/MTLQueryPool.mm +++ b/native/cocos/renderer/gfx-metal/MTLQueryPool.mm @@ -44,12 +44,12 @@ CCMTLQueryPool::~CCMTLQueryPool() { void CCMTLQueryPool::doInit(const QueryPoolInfo& info) { id mtlDevice = id(CCMTLDevice::getInstance()->getMTLDevice()); - _gpuQueryPool = CC_NEW(CCMTLGPUQueryPool); + _gpuQueryPool = ccnew CCMTLGPUQueryPool; _gpuQueryPool->type = _type; _gpuQueryPool->maxQueryObjects = _maxQueryObjects; _gpuQueryPool->forceWait = _forceWait; _gpuQueryPool->visibilityResultBuffer = [mtlDevice newBufferWithLength:_maxQueryObjects * sizeof(uint64_t) options:MTLResourceStorageModeShared]; - _gpuQueryPool->semaphore = CC_NEW(CCMTLSemaphore(1)); + _gpuQueryPool->semaphore = ccnew CCMTLSemaphore(1); } void CCMTLQueryPool::doDestroy() { diff --git a/native/cocos/renderer/gfx-metal/MTLQueue.mm b/native/cocos/renderer/gfx-metal/MTLQueue.mm index d793feab7d..3c4ed793af 100644 --- a/native/cocos/renderer/gfx-metal/MTLQueue.mm +++ b/native/cocos/renderer/gfx-metal/MTLQueue.mm @@ -42,7 +42,7 @@ CCMTLQueue::~CCMTLQueue() { } void CCMTLQueue::doInit(const QueueInfo &info) { - _gpuQueueObj = CC_NEW(CCMTLGPUQueueObject); + _gpuQueueObj = ccnew CCMTLGPUQueueObject; auto device = static_cast>(CCMTLDevice::getInstance()->getMTLDevice()); _gpuQueueObj->mtlCommandQueue = [device newCommandQueue]; } diff --git a/native/cocos/renderer/gfx-metal/MTLSampler.mm b/native/cocos/renderer/gfx-metal/MTLSampler.mm index 1fc84b856f..1207b9c89a 100644 --- a/native/cocos/renderer/gfx-metal/MTLSampler.mm +++ b/native/cocos/renderer/gfx-metal/MTLSampler.mm @@ -73,7 +73,7 @@ CCMTLSampler::~CCMTLSampler() { CCMTLSampler* CCMTLSampler::getDefaultSampler() { if(!defaultSampler) { SamplerInfo info; - defaultSampler = new CCMTLSampler(info); + defaultSampler = ccnew CCMTLSampler(info); } return defaultSampler; } diff --git a/native/cocos/renderer/gfx-metal/MTLShader.mm b/native/cocos/renderer/gfx-metal/MTLShader.mm index 05c8490b06..7f06ed8a54 100644 --- a/native/cocos/renderer/gfx-metal/MTLShader.mm +++ b/native/cocos/renderer/gfx-metal/MTLShader.mm @@ -44,7 +44,7 @@ CCMTLShader::~CCMTLShader() { } void CCMTLShader::doInit(const ShaderInfo &info) { - _gpuShader = CC_NEW(CCMTLGPUShader); + _gpuShader = ccnew CCMTLGPUShader; _specializedFragFuncs = [[NSMutableDictionary alloc] init]; for (const auto &stage : _stages) { diff --git a/native/cocos/renderer/gfx-metal/MTLSwapchain.mm b/native/cocos/renderer/gfx-metal/MTLSwapchain.mm index 7bcbfc7ba5..ada4a267ff 100644 --- a/native/cocos/renderer/gfx-metal/MTLSwapchain.mm +++ b/native/cocos/renderer/gfx-metal/MTLSwapchain.mm @@ -53,7 +53,7 @@ CCMTLSwapchain::~CCMTLSwapchain() { } void CCMTLSwapchain::doInit(const SwapchainInfo &info) { - _gpuSwapchainObj = CC_NEW(CCMTLGPUSwapChainObject); + _gpuSwapchainObj = ccnew CCMTLGPUSwapChainObject; //----------------------acquire layer----------------------------------- #if CC_EDITOR @@ -105,8 +105,8 @@ void CCMTLSwapchain::doInit(const SwapchainInfo &info) { Format colorFmt = Format::BGRA8; Format depthStencilFmt = Format::DEPTH_STENCIL; - _colorTexture = CC_NEW(CCMTLTexture); - _depthStencilTexture = CC_NEW(CCMTLTexture); + _colorTexture = ccnew CCMTLTexture; + _depthStencilTexture = ccnew CCMTLTexture; SwapchainTextureInfo textureInfo; textureInfo.swapchain = this; diff --git a/native/cocos/renderer/gfx-metal/MTLTexture.mm b/native/cocos/renderer/gfx-metal/MTLTexture.mm index a947be95f9..eb5cde1f5d 100644 --- a/native/cocos/renderer/gfx-metal/MTLTexture.mm +++ b/native/cocos/renderer/gfx-metal/MTLTexture.mm @@ -304,7 +304,7 @@ CCMTLTexture* CCMTLTexture::getDefaultTexture() { info.width = 2; info.height = 2; - defaultTexture = new CCMTLTexture(); + defaultTexture = ccnew CCMTLTexture(); defaultTexture->initialize(info); } return defaultTexture; diff --git a/native/cocos/renderer/gfx-metal/MTLUtils.mm b/native/cocos/renderer/gfx-metal/MTLUtils.mm index d884ea2c4b..6ab2b88da8 100644 --- a/native/cocos/renderer/gfx-metal/MTLUtils.mm +++ b/native/cocos/renderer/gfx-metal/MTLUtils.mm @@ -414,7 +414,7 @@ CCMTLGPUPipelineState *getClearRenderPassPipelineState(CCMTLDevice *device, Rend PipelineState *pipelineState = device->createPipelineState(std::move(pipelineInfo)); pipelineMap.emplace(std::make_pair(curPass->getHash(), pipelineState)); ((CCMTLPipelineState*)pipelineState)->check(); - CC_DELETE(pipelineInfo.shader); + delete pipelineInfo.shader; return static_cast(pipelineState)->getGPUPipelineState(); } } @@ -1766,14 +1766,14 @@ void mu::clearUtilResource() { for (auto& pass : renderPassMap) { //TODO: create and destroy not in the same level pass.second->destroy(); - CC_DELETE(pass.second); + delete pass.second; } renderPassMap.clear(); } if(!pipelineMap.empty()) { for (auto& pipeline : pipelineMap) { pipeline.second->destroy(); - CC_DELETE(pipeline.second); + delete pipeline.second; } pipelineMap.clear(); } diff --git a/native/cocos/renderer/gfx-validator/DeviceValidator.cpp b/native/cocos/renderer/gfx-validator/DeviceValidator.cpp index f0b521b30b..2eaf736025 100644 --- a/native/cocos/renderer/gfx-validator/DeviceValidator.cpp +++ b/native/cocos/renderer/gfx-validator/DeviceValidator.cpp @@ -80,9 +80,9 @@ bool DeviceValidator::doInit(const DeviceInfo &info) { _api = _actor->getGfxAPI(); _deviceName = _actor->getDeviceName(); - _queue = CC_NEW(QueueValidator(_actor->getQueue())); - _queryPool = CC_NEW(QueryPoolValidator(_actor->getQueryPool())); - _cmdBuff = CC_NEW(CommandBufferValidator(_actor->getCommandBuffer())); + _queue = ccnew QueueValidator(_actor->getQueue()); + _queryPool = ccnew QueryPoolValidator(_actor->getQueryPool()); + _cmdBuff = ccnew CommandBufferValidator(_actor->getCommandBuffer()); _renderer = _actor->getRenderer(); _vendor = _actor->getVendor(); _caps = _actor->_caps; @@ -107,17 +107,17 @@ void DeviceValidator::doDestroy() { if (_cmdBuff) { static_cast(_cmdBuff)->destroyValidator(); static_cast(_cmdBuff)->_actor = nullptr; - CC_DELETE(_cmdBuff); + delete _cmdBuff; _cmdBuff = nullptr; } if (_queryPool) { static_cast(_queryPool)->_actor = nullptr; - CC_DELETE(_queryPool); + delete _queryPool; _queryPool = nullptr; } if (_queue) { static_cast(_queue)->_actor = nullptr; - CC_DELETE(_queue); + delete _queue; _queue = nullptr; } @@ -161,98 +161,98 @@ void DeviceValidator::present() { CommandBuffer *DeviceValidator::createCommandBuffer(const CommandBufferInfo &info, bool hasAgent) { CommandBuffer *actor = _actor->createCommandBuffer(info, hasAgent); - CommandBuffer *result = CC_NEW(CommandBufferValidator(actor)); + CommandBuffer *result = ccnew CommandBufferValidator(actor); DeviceResourceTracker::push(result); return result; } Queue *DeviceValidator::createQueue() { Queue *actor = _actor->createQueue(); - Queue *result = CC_NEW(QueueValidator(actor)); + Queue *result = ccnew QueueValidator(actor); DeviceResourceTracker::push(result); return result; } QueryPool *DeviceValidator::createQueryPool() { QueryPool *actor = _actor->createQueryPool(); - QueryPool *result = CC_NEW(QueryPoolValidator(actor)); + QueryPool *result = ccnew QueryPoolValidator(actor); DeviceResourceTracker::push(result); return result; } Swapchain *DeviceValidator::createSwapchain() { Swapchain *actor = _actor->createSwapchain(); - Swapchain *result = CC_NEW(SwapchainValidator(actor)); + Swapchain *result = ccnew SwapchainValidator(actor); DeviceResourceTracker::push(result); return result; } Buffer *DeviceValidator::createBuffer() { Buffer *actor = _actor->createBuffer(); - Buffer *result = CC_NEW(BufferValidator(actor)); + Buffer *result = ccnew BufferValidator(actor); DeviceResourceTracker::push(result); return result; } Texture *DeviceValidator::createTexture() { Texture *actor = _actor->createTexture(); - Texture *result = CC_NEW(TextureValidator(actor)); + Texture *result = ccnew TextureValidator(actor); DeviceResourceTracker::push(result); return result; } Shader *DeviceValidator::createShader() { Shader *actor = _actor->createShader(); - Shader *result = CC_NEW(ShaderValidator(actor)); + Shader *result = ccnew ShaderValidator(actor); DeviceResourceTracker::push(result); return result; } InputAssembler *DeviceValidator::createInputAssembler() { InputAssembler *actor = _actor->createInputAssembler(); - InputAssembler *result = CC_NEW(InputAssemblerValidator(actor)); + InputAssembler *result = ccnew InputAssemblerValidator(actor); DeviceResourceTracker::push(result); return result; } RenderPass *DeviceValidator::createRenderPass() { RenderPass *actor = _actor->createRenderPass(); - RenderPass *result = CC_NEW(RenderPassValidator(actor)); + RenderPass *result = ccnew RenderPassValidator(actor); DeviceResourceTracker::push(result); return result; } Framebuffer *DeviceValidator::createFramebuffer() { Framebuffer *actor = _actor->createFramebuffer(); - Framebuffer *result = CC_NEW(FramebufferValidator(actor)); + Framebuffer *result = ccnew FramebufferValidator(actor); DeviceResourceTracker::push(result); return result; } DescriptorSet *DeviceValidator::createDescriptorSet() { DescriptorSet *actor = _actor->createDescriptorSet(); - DescriptorSet *result = CC_NEW(DescriptorSetValidator(actor)); + DescriptorSet *result = ccnew DescriptorSetValidator(actor); DeviceResourceTracker::push(result); return result; } DescriptorSetLayout *DeviceValidator::createDescriptorSetLayout() { DescriptorSetLayout *actor = _actor->createDescriptorSetLayout(); - DescriptorSetLayout *result = CC_NEW(DescriptorSetLayoutValidator(actor)); + DescriptorSetLayout *result = ccnew DescriptorSetLayoutValidator(actor); DeviceResourceTracker::push(result); return result; } PipelineLayout *DeviceValidator::createPipelineLayout() { PipelineLayout *actor = _actor->createPipelineLayout(); - PipelineLayout *result = CC_NEW(PipelineLayoutValidator(actor)); + PipelineLayout *result = ccnew PipelineLayoutValidator(actor); DeviceResourceTracker::push(result); return result; } PipelineState *DeviceValidator::createPipelineState() { PipelineState *actor = _actor->createPipelineState(); - PipelineState *result = CC_NEW(PipelineStateValidator(actor)); + PipelineState *result = ccnew PipelineStateValidator(actor); DeviceResourceTracker::push(result); return result; } diff --git a/native/cocos/renderer/gfx-validator/SwapchainValidator.cpp b/native/cocos/renderer/gfx-validator/SwapchainValidator.cpp index 777829c4c8..8bf9b4436a 100644 --- a/native/cocos/renderer/gfx-validator/SwapchainValidator.cpp +++ b/native/cocos/renderer/gfx-validator/SwapchainValidator.cpp @@ -51,12 +51,12 @@ void SwapchainValidator::doInit(const SwapchainInfo &info) { _actor->initialize(info); - auto *colorTexture = CC_NEW(TextureValidator(_actor->getColorTexture())); + auto *colorTexture = ccnew TextureValidator(_actor->getColorTexture()); colorTexture->renounceOwnership(); _colorTexture = colorTexture; DeviceResourceTracker::push(_colorTexture.get()); - auto *depthStencilTexture = CC_NEW(TextureValidator(_actor->getDepthStencilTexture())); + auto *depthStencilTexture = ccnew TextureValidator(_actor->getDepthStencilTexture()); depthStencilTexture->renounceOwnership(); _depthStencilTexture = depthStencilTexture; DeviceResourceTracker::push(_depthStencilTexture.get()); diff --git a/native/cocos/renderer/gfx-vulkan/VKBuffer.cpp b/native/cocos/renderer/gfx-vulkan/VKBuffer.cpp index 21e37bbc91..46d135d414 100644 --- a/native/cocos/renderer/gfx-vulkan/VKBuffer.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKBuffer.cpp @@ -41,7 +41,7 @@ CCVKBuffer::~CCVKBuffer() { } void CCVKBuffer::doInit(const BufferInfo & /*info*/) { - _gpuBuffer = CC_NEW(CCVKGPUBuffer); + _gpuBuffer = ccnew CCVKGPUBuffer; _gpuBuffer->usage = _usage; _gpuBuffer->memUsage = _memUsage; _gpuBuffer->size = _size; @@ -58,14 +58,14 @@ void CCVKBuffer::doInit(const BufferInfo & /*info*/) { CCVKDevice::getInstance()->getMemoryStatus().bufferSize += _size; CC_PROFILE_MEMORY_INC(Buffer, _size); - _gpuBufferView = CC_NEW(CCVKGPUBufferView); + _gpuBufferView = ccnew CCVKGPUBufferView; createBufferView(); } void CCVKBuffer::doInit(const BufferViewInfo &info) { auto *buffer = static_cast(info.buffer); _gpuBuffer = buffer->gpuBuffer(); - _gpuBufferView = CC_NEW(CCVKGPUBufferView); + _gpuBufferView = ccnew CCVKGPUBufferView; createBufferView(); } @@ -81,7 +81,7 @@ void CCVKBuffer::createBufferView() { void CCVKBuffer::doDestroy() { if (_gpuBufferView) { CCVKDevice::getInstance()->gpuDescriptorHub()->disengage(_gpuBufferView); - CC_DELETE(_gpuBufferView); + delete _gpuBufferView; _gpuBufferView = nullptr; } @@ -90,7 +90,7 @@ void CCVKBuffer::doDestroy() { CCVKDevice::getInstance()->gpuBufferHub()->erase(_gpuBuffer); CCVKDevice::getInstance()->gpuRecycleBin()->collect(_gpuBuffer); CCVKDevice::getInstance()->gpuBarrierManager()->cancel(_gpuBuffer); - CC_DELETE(_gpuBuffer); + delete _gpuBuffer; CCVKDevice::getInstance()->getMemoryStatus().bufferSize -= _size; CC_PROFILE_MEMORY_DEC(Buffer, _size); } diff --git a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp index 5fc1723ab9..bad94700b8 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp @@ -51,7 +51,7 @@ CCVKCommandBuffer::~CCVKCommandBuffer() { } void CCVKCommandBuffer::doInit(const CommandBufferInfo & /*info*/) { - _gpuCommandBuffer = CC_NEW(CCVKGPUCommandBuffer); + _gpuCommandBuffer = ccnew CCVKGPUCommandBuffer; _gpuCommandBuffer->level = mapVkCommandBufferLevel(_type); _gpuCommandBuffer->queueFamilyIndex = static_cast(_queue)->gpuQueue()->queueFamilyIndex; @@ -62,10 +62,7 @@ void CCVKCommandBuffer::doInit(const CommandBufferInfo & /*info*/) { } void CCVKCommandBuffer::doDestroy() { - if (_gpuCommandBuffer) { - CC_DELETE(_gpuCommandBuffer); - _gpuCommandBuffer = nullptr; - } + CC_SAFE_DELETE(_gpuCommandBuffer); } void CCVKCommandBuffer::begin(RenderPass *renderPass, uint32_t subpass, Framebuffer *frameBuffer) { diff --git a/native/cocos/renderer/gfx-vulkan/VKCommands.cpp b/native/cocos/renderer/gfx-vulkan/VKCommands.cpp index 03fda93cfe..ada9032f1a 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommands.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKCommands.cpp @@ -47,7 +47,7 @@ constexpr bool ENABLE_LAZY_ALLOCATION = true; CCVKGPUCommandBufferPool *CCVKGPUDevice::getCommandBufferPool() { static thread_local size_t threadID = std::hash{}(std::this_thread::get_id()); if (!_commandBufferPools.count(threadID)) { - _commandBufferPools[threadID] = CC_NEW(CCVKGPUCommandBufferPool(this)); + _commandBufferPools[threadID] = ccnew CCVKGPUCommandBufferPool(this); } return _commandBufferPools[threadID]; } @@ -1498,49 +1498,49 @@ void CCVKGPURecycleBin::clear() { case RecycledType::QUERY_POOL: if (res.gpuQueryPool) { cmdFuncCCVKDestroyQueryPool(_device, res.gpuQueryPool); - CC_DELETE(res.gpuQueryPool); + delete res.gpuQueryPool; res.gpuQueryPool = nullptr; } break; case RecycledType::RENDER_PASS: if (res.gpuRenderPass) { cmdFuncCCVKDestroyRenderPass(_device, res.gpuRenderPass); - CC_DELETE(res.gpuRenderPass); + delete res.gpuRenderPass; res.gpuRenderPass = nullptr; } break; case RecycledType::SAMPLER: if (res.gpuSampler) { cmdFuncCCVKDestroySampler(_device, res.gpuSampler); - CC_DELETE(res.gpuSampler); + delete res.gpuSampler; res.gpuSampler = nullptr; } break; case RecycledType::SHADER: if (res.gpuShader) { cmdFuncCCVKDestroyShader(_device, res.gpuShader); - CC_DELETE(res.gpuShader); + delete res.gpuShader; res.gpuShader = nullptr; } break; case RecycledType::DESCRIPTOR_SET_LAYOUT: if (res.gpuDescriptorSetLayout) { cmdFuncCCVKDestroyDescriptorSetLayout(_device, res.gpuDescriptorSetLayout); - CC_DELETE(res.gpuDescriptorSetLayout); + delete res.gpuDescriptorSetLayout; res.gpuDescriptorSetLayout = nullptr; } break; case RecycledType::PIPELINE_LAYOUT: if (res.gpuPipelineLayout) { cmdFuncCCVKDestroyPipelineLayout(_device, res.gpuPipelineLayout); - CC_DELETE(res.gpuPipelineLayout); + delete res.gpuPipelineLayout; res.gpuPipelineLayout = nullptr; } break; case RecycledType::PIPELINE_STATE: if (res.gpuPipelineState) { cmdFuncCCVKDestroyPipelineState(_device, res.gpuPipelineState); - CC_DELETE(res.gpuPipelineState); + delete res.gpuPipelineState; res.gpuPipelineState = nullptr; } break; diff --git a/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp b/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp index 61f9eaac36..7bcaf02a23 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp @@ -49,7 +49,7 @@ void CCVKDescriptorSet::doInit(const DescriptorSetInfo & /*info*/) { uint32_t bindingCount = utils::toUint(gpuDescriptorSetLayout->bindings.size()); uint32_t descriptorCount = gpuDescriptorSetLayout->descriptorCount; - _gpuDescriptorSet = CC_NEW(CCVKGPUDescriptorSet); + _gpuDescriptorSet = ccnew CCVKGPUDescriptorSet; _gpuDescriptorSet->gpuDescriptors.resize(descriptorCount, {}); _gpuDescriptorSet->layoutID = gpuDescriptorSetLayout->id; @@ -184,7 +184,7 @@ void CCVKDescriptorSet::doDestroy() { CCVKDevice::getInstance()->gpuDescriptorSetHub()->erase(_gpuDescriptorSet); - CC_DELETE(_gpuDescriptorSet); + delete _gpuDescriptorSet; _gpuDescriptorSet = nullptr; } } diff --git a/native/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.cpp b/native/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.cpp index a001b6e604..a455753615 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.cpp @@ -39,7 +39,7 @@ CCVKDescriptorSetLayout::~CCVKDescriptorSetLayout() { } void CCVKDescriptorSetLayout::doInit(const DescriptorSetLayoutInfo & /*info*/) { - _gpuDescriptorSetLayout = CC_NEW(CCVKGPUDescriptorSetLayout); + _gpuDescriptorSetLayout = ccnew CCVKGPUDescriptorSetLayout; _gpuDescriptorSetLayout->id = generateID(); _gpuDescriptorSetLayout->descriptorCount = _descriptorCount; _gpuDescriptorSetLayout->bindingIndices = _bindingIndices; diff --git a/native/cocos/renderer/gfx-vulkan/VKDevice.cpp b/native/cocos/renderer/gfx-vulkan/VKDevice.cpp index 057680f18f..13dd57f8db 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDevice.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKDevice.cpp @@ -95,7 +95,7 @@ CCVKDevice::~CCVKDevice() { } bool CCVKDevice::doInit(const DeviceInfo & /*info*/) { - _gpuContext = CC_NEW(CCVKGPUContext); + _gpuContext = ccnew CCVKGPUContext; if (!_gpuContext->initialize()) { CC_SAFE_DESTROY_AND_DELETE(_gpuContext) return false; @@ -108,7 +108,7 @@ bool CCVKDevice::doInit(const DeviceInfo & /*info*/) { ///////////////////// Device Creation ///////////////////// - _gpuDevice = CC_NEW(CCVKGPUDevice); + _gpuDevice = ccnew CCVKGPUDevice; _gpuDevice->minorVersion = _gpuContext->minorVersion; // only enable the absolute essentials @@ -385,18 +385,18 @@ bool CCVKDevice::doInit(const DeviceInfo & /*info*/) { uint32_t backBufferCount = _gpuDevice->backBufferCount; for (uint32_t i = 0U; i < backBufferCount; i++) { - _gpuFencePools.push_back(CC_NEW(CCVKGPUFencePool(_gpuDevice))); - _gpuRecycleBins.push_back(CC_NEW(CCVKGPURecycleBin(_gpuDevice))); - _gpuStagingBufferPools.push_back(CC_NEW(CCVKGPUStagingBufferPool(_gpuDevice))); + _gpuFencePools.push_back(ccnew CCVKGPUFencePool(_gpuDevice)); + _gpuRecycleBins.push_back(ccnew CCVKGPURecycleBin(_gpuDevice)); + _gpuStagingBufferPools.push_back(ccnew CCVKGPUStagingBufferPool(_gpuDevice)); } - _gpuBufferHub = CC_NEW(CCVKGPUBufferHub(_gpuDevice)); - _gpuTransportHub = CC_NEW(CCVKGPUTransportHub(_gpuDevice, static_cast(_queue)->gpuQueue())); - _gpuDescriptorHub = CC_NEW(CCVKGPUDescriptorHub(_gpuDevice)); - _gpuSemaphorePool = CC_NEW(CCVKGPUSemaphorePool(_gpuDevice)); - _gpuBarrierManager = CC_NEW(CCVKGPUBarrierManager(_gpuDevice)); - _gpuFramebufferHub = CC_NEW(CCVKGPUFramebufferHub); - _gpuDescriptorSetHub = CC_NEW(CCVKGPUDescriptorSetHub(_gpuDevice)); + _gpuBufferHub = ccnew CCVKGPUBufferHub(_gpuDevice); + _gpuTransportHub = ccnew CCVKGPUTransportHub(_gpuDevice, static_cast(_queue)->gpuQueue()); + _gpuDescriptorHub = ccnew CCVKGPUDescriptorHub(_gpuDevice); + _gpuSemaphorePool = ccnew CCVKGPUSemaphorePool(_gpuDevice); + _gpuBarrierManager = ccnew CCVKGPUBarrierManager(_gpuDevice); + _gpuFramebufferHub = ccnew CCVKGPUFramebufferHub; + _gpuDescriptorSetHub = ccnew CCVKGPUDescriptorSetHub(_gpuDevice); _gpuDescriptorHub->link(_gpuDescriptorSetHub); @@ -558,7 +558,7 @@ void CCVKDevice::doDestroy() { _gpuDevice->vkDevice = VK_NULL_HANDLE; } - CC_DELETE(_gpuDevice); + delete _gpuDevice; _gpuDevice = nullptr; } @@ -723,9 +723,9 @@ void CCVKDevice::waitAllFences() { void CCVKDevice::updateBackBufferCount(uint32_t backBufferCount) { if (backBufferCount <= _gpuDevice->backBufferCount) return; for (uint32_t i = _gpuDevice->backBufferCount; i < backBufferCount; i++) { - _gpuFencePools.push_back(CC_NEW(CCVKGPUFencePool(_gpuDevice))); - _gpuRecycleBins.push_back(CC_NEW(CCVKGPURecycleBin(_gpuDevice))); - _gpuStagingBufferPools.push_back(CC_NEW(CCVKGPUStagingBufferPool(_gpuDevice))); + _gpuFencePools.push_back(ccnew CCVKGPUFencePool(_gpuDevice)); + _gpuRecycleBins.push_back(ccnew CCVKGPURecycleBin(_gpuDevice)); + _gpuStagingBufferPools.push_back(ccnew CCVKGPUStagingBufferPool(_gpuDevice)); } _gpuBufferHub->updateBackBufferCount(backBufferCount); _gpuDescriptorSetHub->updateBackBufferCount(backBufferCount); @@ -771,71 +771,71 @@ void CCVKDevice::initFormatFeature() { } CommandBuffer *CCVKDevice::createCommandBuffer(const CommandBufferInfo & /*info*/, bool /*hasAgent*/) { - return CC_NEW(CCVKCommandBuffer); + return ccnew CCVKCommandBuffer; } Queue *CCVKDevice::createQueue() { - return CC_NEW(CCVKQueue); + return ccnew CCVKQueue; } QueryPool *CCVKDevice::createQueryPool() { - return CC_NEW(CCVKQueryPool); + return ccnew CCVKQueryPool; } Swapchain *CCVKDevice::createSwapchain() { - return CC_NEW(CCVKSwapchain); + return ccnew CCVKSwapchain; } Buffer *CCVKDevice::createBuffer() { - return CC_NEW(CCVKBuffer); + return ccnew CCVKBuffer; } Texture *CCVKDevice::createTexture() { - return CC_NEW(CCVKTexture); + return ccnew CCVKTexture; } Shader *CCVKDevice::createShader() { - return CC_NEW(CCVKShader); + return ccnew CCVKShader; } InputAssembler *CCVKDevice::createInputAssembler() { - return CC_NEW(CCVKInputAssembler); + return ccnew CCVKInputAssembler; } RenderPass *CCVKDevice::createRenderPass() { - return CC_NEW(CCVKRenderPass); + return ccnew CCVKRenderPass; } Framebuffer *CCVKDevice::createFramebuffer() { - return CC_NEW(CCVKFramebuffer); + return ccnew CCVKFramebuffer; } DescriptorSet *CCVKDevice::createDescriptorSet() { - return CC_NEW(CCVKDescriptorSet); + return ccnew CCVKDescriptorSet; } DescriptorSetLayout *CCVKDevice::createDescriptorSetLayout() { - return CC_NEW(CCVKDescriptorSetLayout); + return ccnew CCVKDescriptorSetLayout; } PipelineLayout *CCVKDevice::createPipelineLayout() { - return CC_NEW(CCVKPipelineLayout); + return ccnew CCVKPipelineLayout; } PipelineState *CCVKDevice::createPipelineState() { - return CC_NEW(CCVKPipelineState); + return ccnew CCVKPipelineState; } Sampler *CCVKDevice::createSampler(const SamplerInfo &info) { - return CC_NEW(CCVKSampler(info)); + return ccnew CCVKSampler(info); } GeneralBarrier *CCVKDevice::createGeneralBarrier(const GeneralBarrierInfo &info) { - return CC_NEW(CCVKGeneralBarrier(info)); + return ccnew CCVKGeneralBarrier(info); } TextureBarrier *CCVKDevice::createTextureBarrier(const TextureBarrierInfo &info) { - return CC_NEW(CCVKTextureBarrier(info)); + return ccnew CCVKTextureBarrier(info); } void CCVKDevice::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) { diff --git a/native/cocos/renderer/gfx-vulkan/VKFramebuffer.cpp b/native/cocos/renderer/gfx-vulkan/VKFramebuffer.cpp index 2c9bb9231b..ef2b3de3df 100644 --- a/native/cocos/renderer/gfx-vulkan/VKFramebuffer.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKFramebuffer.cpp @@ -41,7 +41,7 @@ CCVKFramebuffer::~CCVKFramebuffer() { } void CCVKFramebuffer::doInit(const FramebufferInfo & /*info*/) { - _gpuFBO = CC_NEW(CCVKGPUFramebuffer); + _gpuFBO = ccnew CCVKGPUFramebuffer; _gpuFBO->gpuRenderPass = static_cast(_renderPass)->gpuRenderPass(); _gpuFBO->gpuColorViews.resize(_colorTextures.size()); @@ -73,7 +73,7 @@ void CCVKFramebuffer::doDestroy() { } CCVKDevice::getInstance()->gpuRecycleBin()->collect(_gpuFBO); - CC_SAFE_DELETE(_gpuFBO); + delete _gpuFBO; _gpuFBO = nullptr; } } diff --git a/native/cocos/renderer/gfx-vulkan/VKInputAssembler.cpp b/native/cocos/renderer/gfx-vulkan/VKInputAssembler.cpp index 175c9b2fb2..8c3217b1a4 100644 --- a/native/cocos/renderer/gfx-vulkan/VKInputAssembler.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKInputAssembler.cpp @@ -42,7 +42,7 @@ CCVKInputAssembler::~CCVKInputAssembler() { void CCVKInputAssembler::doInit(const InputAssemblerInfo &info) { size_t vbCount = _vertexBuffers.size(); - _gpuInputAssembler = CC_NEW(CCVKGPUInputAssembler); + _gpuInputAssembler = ccnew CCVKGPUInputAssembler; _gpuInputAssembler->attributes = _attributes; _gpuInputAssembler->gpuVertexBuffers.resize(vbCount); @@ -73,7 +73,7 @@ void CCVKInputAssembler::doDestroy() { if (_gpuInputAssembler) { _gpuInputAssembler->vertexBuffers.clear(); _gpuInputAssembler->vertexBufferOffsets.clear(); - CC_DELETE(_gpuInputAssembler); + delete _gpuInputAssembler; _gpuInputAssembler = nullptr; } } diff --git a/native/cocos/renderer/gfx-vulkan/VKPipelineLayout.cpp b/native/cocos/renderer/gfx-vulkan/VKPipelineLayout.cpp index 575bc743e3..0c7c549f6e 100644 --- a/native/cocos/renderer/gfx-vulkan/VKPipelineLayout.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKPipelineLayout.cpp @@ -40,7 +40,7 @@ CCVKPipelineLayout::~CCVKPipelineLayout() { } void CCVKPipelineLayout::doInit(const PipelineLayoutInfo & /*info*/) { - _gpuPipelineLayout = CC_NEW(CCVKGPUPipelineLayout); + _gpuPipelineLayout = ccnew CCVKGPUPipelineLayout; uint32_t offset = 0U; for (auto *setLayout : _setLayouts) { diff --git a/native/cocos/renderer/gfx-vulkan/VKPipelineState.cpp b/native/cocos/renderer/gfx-vulkan/VKPipelineState.cpp index 5328e08834..405eb682ee 100644 --- a/native/cocos/renderer/gfx-vulkan/VKPipelineState.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKPipelineState.cpp @@ -42,7 +42,7 @@ CCVKPipelineState::~CCVKPipelineState() { } void CCVKPipelineState::doInit(const PipelineStateInfo & /*info*/) { - _gpuPipelineState = CC_NEW(CCVKGPUPipelineState); + _gpuPipelineState = ccnew CCVKGPUPipelineState; _gpuPipelineState->bindPoint = _bindPoint; _gpuPipelineState->primitive = _primitive; _gpuPipelineState->gpuShader = static_cast(_shader)->gpuShader(); diff --git a/native/cocos/renderer/gfx-vulkan/VKQueryPool.cpp b/native/cocos/renderer/gfx-vulkan/VKQueryPool.cpp index fb2add38cc..578bdb5bfe 100644 --- a/native/cocos/renderer/gfx-vulkan/VKQueryPool.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKQueryPool.cpp @@ -41,7 +41,7 @@ CCVKQueryPool::~CCVKQueryPool() { void CCVKQueryPool::doInit(const QueryPoolInfo & /*info*/) { CCVKDevice *device = CCVKDevice::getInstance(); - _gpuQueryPool = CC_NEW(CCVKGPUQueryPool); + _gpuQueryPool = ccnew CCVKGPUQueryPool; _gpuQueryPool->type = _type; _gpuQueryPool->maxQueryObjects = _maxQueryObjects; _gpuQueryPool->forceWait = _forceWait; diff --git a/native/cocos/renderer/gfx-vulkan/VKQueue.cpp b/native/cocos/renderer/gfx-vulkan/VKQueue.cpp index 09bc6d7202..30dedbd601 100644 --- a/native/cocos/renderer/gfx-vulkan/VKQueue.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKQueue.cpp @@ -42,7 +42,7 @@ CCVKQueue::~CCVKQueue() { } void CCVKQueue::doInit(const QueueInfo & /*info*/) { - _gpuQueue = CC_NEW(CCVKGPUQueue); + _gpuQueue = ccnew CCVKGPUQueue; _gpuQueue->type = _type; cmdFuncCCVKGetDeviceQueue(CCVKDevice::getInstance(), _gpuQueue); } @@ -50,7 +50,7 @@ void CCVKQueue::doInit(const QueueInfo & /*info*/) { void CCVKQueue::doDestroy() { if (_gpuQueue) { _gpuQueue->vkQueue = VK_NULL_HANDLE; - CC_DELETE(_gpuQueue); + delete _gpuQueue; _gpuQueue = nullptr; } } diff --git a/native/cocos/renderer/gfx-vulkan/VKRenderPass.cpp b/native/cocos/renderer/gfx-vulkan/VKRenderPass.cpp index c33ab82cf0..011cd02494 100644 --- a/native/cocos/renderer/gfx-vulkan/VKRenderPass.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKRenderPass.cpp @@ -39,7 +39,7 @@ CCVKRenderPass::~CCVKRenderPass() { } void CCVKRenderPass::doInit(const RenderPassInfo & /*info*/) { - _gpuRenderPass = CC_NEW(CCVKGPURenderPass); + _gpuRenderPass = ccnew CCVKGPURenderPass; _gpuRenderPass->colorAttachments = _colorAttachments; _gpuRenderPass->depthStencilAttachment = _depthStencilAttachment; _gpuRenderPass->subpasses = _subpasses; diff --git a/native/cocos/renderer/gfx-vulkan/VKShader.cpp b/native/cocos/renderer/gfx-vulkan/VKShader.cpp index 85a7edc1fa..b717948037 100644 --- a/native/cocos/renderer/gfx-vulkan/VKShader.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKShader.cpp @@ -41,7 +41,7 @@ CCVKShader::~CCVKShader() { } void CCVKShader::doInit(const ShaderInfo & /*info*/) { - _gpuShader = CC_NEW(CCVKGPUShader); + _gpuShader = ccnew CCVKGPUShader; _gpuShader->name = _name; _gpuShader->attributes = _attributes; for (ShaderStage &stage : _stages) { diff --git a/native/cocos/renderer/gfx-vulkan/VKSwapchain.cpp b/native/cocos/renderer/gfx-vulkan/VKSwapchain.cpp index d4b8129001..d56c308de9 100644 --- a/native/cocos/renderer/gfx-vulkan/VKSwapchain.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKSwapchain.cpp @@ -53,7 +53,7 @@ CCVKSwapchain::~CCVKSwapchain() { void CCVKSwapchain::doInit(const SwapchainInfo &info) { auto * gpuDevice = CCVKDevice::getInstance()->gpuDevice(); const auto *gpuContext = CCVKDevice::getInstance()->gpuContext(); - _gpuSwapchain = CC_NEW(CCVKGPUSwapchain); + _gpuSwapchain = ccnew CCVKGPUSwapchain; gpuDevice->swapchains.insert(_gpuSwapchain); createVkSurface(); @@ -199,8 +199,8 @@ void CCVKSwapchain::doInit(const SwapchainInfo &info) { ///////////////////// Texture Creation ///////////////////// - _colorTexture = CC_NEW(CCVKTexture); - _depthStencilTexture = CC_NEW(CCVKTexture); + _colorTexture = ccnew CCVKTexture; + _depthStencilTexture = ccnew CCVKTexture; SwapchainTextureInfo textureInfo; textureInfo.swapchain = this; diff --git a/native/cocos/renderer/gfx-vulkan/VKTexture.cpp b/native/cocos/renderer/gfx-vulkan/VKTexture.cpp index 6f0e473db7..cccd3f3e8d 100644 --- a/native/cocos/renderer/gfx-vulkan/VKTexture.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKTexture.cpp @@ -42,7 +42,7 @@ CCVKTexture::~CCVKTexture() { } void CCVKTexture::doInit(const TextureInfo & /*info*/) { - _gpuTexture = CC_NEW(CCVKGPUTexture); + _gpuTexture = ccnew CCVKGPUTexture; _gpuTexture->type = _info.type; _gpuTexture->format = _info.format; _gpuTexture->usage = _info.usage; @@ -62,14 +62,14 @@ void CCVKTexture::doInit(const TextureInfo & /*info*/) { CC_PROFILE_MEMORY_INC(Texture, _size); } - _gpuTextureView = CC_NEW(CCVKGPUTextureView); + _gpuTextureView = ccnew CCVKGPUTextureView; createTextureView(); } void CCVKTexture::doInit(const TextureViewInfo &info) { _gpuTexture = static_cast(info.texture)->gpuTexture(); - _gpuTextureView = CC_NEW(CCVKGPUTextureView); + _gpuTextureView = ccnew CCVKGPUTextureView; createTextureView(); } @@ -88,7 +88,7 @@ void CCVKTexture::doDestroy() { if (_gpuTextureView) { CCVKDevice::getInstance()->gpuRecycleBin()->collect(_gpuTextureView); CCVKDevice::getInstance()->gpuDescriptorHub()->disengage(_gpuTextureView); - CC_DELETE(_gpuTextureView); + delete _gpuTextureView; _gpuTextureView = nullptr; } @@ -101,7 +101,7 @@ void CCVKTexture::doDestroy() { CCVKDevice::getInstance()->gpuRecycleBin()->collect(_gpuTexture); CCVKDevice::getInstance()->gpuBarrierManager()->cancel(_gpuTexture); CCVKDevice::getInstance()->gpuFramebufferHub()->disengage(_gpuTexture); - CC_DELETE(_gpuTexture); + delete _gpuTexture; } _gpuTexture = nullptr; } @@ -138,7 +138,7 @@ void CCVKTexture::doResize(uint32_t width, uint32_t height, uint32_t size) { ///////////////////////////// Swapchain Specific ///////////////////////////// void CCVKTexture::doInit(const SwapchainTextureInfo & /*info*/) { - _gpuTexture = CC_NEW(CCVKGPUTexture); + _gpuTexture = ccnew CCVKGPUTexture; _gpuTexture->type = _info.type; _gpuTexture->format = _info.format; _gpuTexture->usage = _info.usage; @@ -154,7 +154,7 @@ void CCVKTexture::doInit(const SwapchainTextureInfo & /*info*/) { _gpuTexture->swapchain = static_cast(_swapchain)->gpuSwapchain(); _gpuTexture->memoryless = true; - _gpuTextureView = CC_NEW(CCVKGPUTextureView); + _gpuTextureView = ccnew CCVKGPUTextureView; _gpuTextureView->gpuTexture = _gpuTexture; _gpuTextureView->type = _viewInfo.type; _gpuTextureView->format = _viewInfo.format; diff --git a/native/cocos/renderer/gfx-vulkan/states/VKGeneralBarrier.cpp b/native/cocos/renderer/gfx-vulkan/states/VKGeneralBarrier.cpp index 5b0b358d19..1274985944 100644 --- a/native/cocos/renderer/gfx-vulkan/states/VKGeneralBarrier.cpp +++ b/native/cocos/renderer/gfx-vulkan/states/VKGeneralBarrier.cpp @@ -33,7 +33,7 @@ namespace gfx { CCVKGeneralBarrier::CCVKGeneralBarrier(const GeneralBarrierInfo &info) : GeneralBarrier(info) { _typedID = generateObjectID(); - _gpuBarrier = CC_NEW(CCVKGPUGeneralBarrier); + _gpuBarrier = ccnew CCVKGPUGeneralBarrier; getAccessTypes(info.prevAccesses, _gpuBarrier->prevAccesses); getAccessTypes(info.nextAccesses, _gpuBarrier->nextAccesses); diff --git a/native/cocos/renderer/gfx-vulkan/states/VKSampler.cpp b/native/cocos/renderer/gfx-vulkan/states/VKSampler.cpp index f728f264de..bb423c8566 100644 --- a/native/cocos/renderer/gfx-vulkan/states/VKSampler.cpp +++ b/native/cocos/renderer/gfx-vulkan/states/VKSampler.cpp @@ -33,7 +33,7 @@ namespace gfx { CCVKSampler::CCVKSampler(const SamplerInfo &info) : Sampler(info) { _typedID = generateObjectID(); - _gpuSampler = CC_NEW(CCVKGPUSampler); + _gpuSampler = ccnew CCVKGPUSampler; _gpuSampler->minFilter = _info.minFilter; _gpuSampler->magFilter = _info.magFilter; _gpuSampler->mipFilter = _info.mipFilter; diff --git a/native/cocos/renderer/gfx-vulkan/states/VKTextureBarrier.cpp b/native/cocos/renderer/gfx-vulkan/states/VKTextureBarrier.cpp index c1b05d2b2b..d8da3e3ca7 100644 --- a/native/cocos/renderer/gfx-vulkan/states/VKTextureBarrier.cpp +++ b/native/cocos/renderer/gfx-vulkan/states/VKTextureBarrier.cpp @@ -33,7 +33,7 @@ namespace gfx { CCVKTextureBarrier::CCVKTextureBarrier(const TextureBarrierInfo &info) : TextureBarrier(info) { _typedID = generateObjectID(); - _gpuBarrier = CC_NEW(CCVKGPUTextureBarrier); + _gpuBarrier = ccnew CCVKGPUTextureBarrier; getAccessTypes(info.prevAccesses, _gpuBarrier->prevAccesses); getAccessTypes(info.nextAccesses, _gpuBarrier->nextAccesses); diff --git a/native/cocos/renderer/gfx-wgpu/WGPUBuffer.cpp b/native/cocos/renderer/gfx-wgpu/WGPUBuffer.cpp index cc7303277a..2dd4565042 100644 --- a/native/cocos/renderer/gfx-wgpu/WGPUBuffer.cpp +++ b/native/cocos/renderer/gfx-wgpu/WGPUBuffer.cpp @@ -43,7 +43,7 @@ CCWGPUBuffer::CCWGPUBuffer() : wrapper(val::object()) { } void CCWGPUBuffer::doInit(const BufferInfo &info) { - _gpuBufferObject = CC_NEW(CCWGPUBufferObject); + _gpuBufferObject = ccnew CCWGPUBufferObject; if (hasFlag(_usage, BufferUsageBit::INDIRECT)) { size_t drawInfoCount = _size / sizeof(DrawInfo); @@ -76,7 +76,7 @@ void CCWGPUBuffer::doInit(const BufferInfo &info) { } // namespace gfx void CCWGPUBuffer::doInit(const BufferViewInfo &info) { - _gpuBufferObject = CC_NEW(CCWGPUBufferObject); + _gpuBufferObject = ccnew CCWGPUBufferObject; _gpuBufferObject->wgpuBuffer = static_cast(info.buffer)->gpuBufferObject()->wgpuBuffer; _internalChanged = true; } @@ -86,7 +86,7 @@ void CCWGPUBuffer::doDestroy() { if (_gpuBufferObject->wgpuBuffer) { wgpuBufferDestroy(_gpuBufferObject->wgpuBuffer); } - CC_DELETE(_gpuBufferObject); + delete _gpuBufferObject; } _internalChanged = true; } @@ -216,7 +216,7 @@ CCWGPUBuffer *CCWGPUBuffer::defaultUniformBuffer() { .size = 4, .flags = BufferFlagBit::NONE, }; - anoymous::defaultUniformBuffer = CC_NEW(CCWGPUBuffer); + anoymous::defaultUniformBuffer = ccnew CCWGPUBuffer; anoymous::defaultUniformBuffer->initialize(info); } return anoymous::defaultUniformBuffer; @@ -230,7 +230,7 @@ CCWGPUBuffer *CCWGPUBuffer::defaultStorageBuffer() { .size = 4, .flags = BufferFlagBit::NONE, }; - anoymous::defaultStorageBuffer = CC_NEW(CCWGPUBuffer); + anoymous::defaultStorageBuffer = ccnew CCWGPUBuffer; anoymous::defaultStorageBuffer->initialize(info); } return anoymous::defaultStorageBuffer; diff --git a/native/cocos/renderer/gfx-wgpu/WGPUCommandBuffer.cpp b/native/cocos/renderer/gfx-wgpu/WGPUCommandBuffer.cpp index 130f2e771e..c28df80e77 100644 --- a/native/cocos/renderer/gfx-wgpu/WGPUCommandBuffer.cpp +++ b/native/cocos/renderer/gfx-wgpu/WGPUCommandBuffer.cpp @@ -51,7 +51,7 @@ CCWGPUCommandBuffer::CCWGPUCommandBuffer() : wrapper(val::object( } void CCWGPUCommandBuffer::doInit(const CommandBufferInfo &info) { - _gpuCommandBufferObj = CC_NEW(CCWGPUCommandBufferObject); + _gpuCommandBufferObj = ccnew CCWGPUCommandBufferObject; _gpuCommandBufferObj->type = info.type; _gpuCommandBufferObj->queue = static_cast(info.queue); } @@ -126,7 +126,7 @@ void CCWGPUCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *f renderPassDesc.label = "attachments"; for (size_t i = 0; i < colorConfigs.size(); i++) { - WGPURenderPassColorAttachment *colorAttchments = new WGPURenderPassColorAttachment[colorConfigs.size()]; + WGPURenderPassColorAttachment *colorAttchments = ccnew WGPURenderPassColorAttachment[colorConfigs.size()]; WGPURenderPassColorAttachment color = { .view = static_cast(textures[i])->gpuTextureObject()->selfView, .resolveTarget = nullptr, //TODO_Zeqiang: wgpu offscr msaa @@ -379,7 +379,7 @@ void CCWGPUCommandBuffer::bindStates() { .size = maxAttrLen, .flags = BufferFlagBit::NONE, }; - buffer = CC_NEW(CCWGPUBuffer); + buffer = ccnew CCWGPUBuffer; buffer->initialize(info); _gpuCommandBufferObj->redundantVertexBufferMap.insert({maxAttrLen, buffer}); } diff --git a/native/cocos/renderer/gfx-wgpu/WGPUDescriptorSet.cpp b/native/cocos/renderer/gfx-wgpu/WGPUDescriptorSet.cpp index 9c65ad608b..083acb6700 100644 --- a/native/cocos/renderer/gfx-wgpu/WGPUDescriptorSet.cpp +++ b/native/cocos/renderer/gfx-wgpu/WGPUDescriptorSet.cpp @@ -46,7 +46,7 @@ CCWGPUDescriptorSet::CCWGPUDescriptorSet() : wrapper(val::object( } void CCWGPUDescriptorSet::doInit(const DescriptorSetInfo &info) { - _gpuBindGroupObj = CC_NEW(CCWGPUBindGroupObject); + _gpuBindGroupObj = ccnew CCWGPUBindGroupObject; auto * dsLayout = static_cast(_layout); CCWGPUBindGroupLayoutObject *layoutEntries = dsLayout->gpuLayoutEntryObject(); @@ -109,7 +109,7 @@ void CCWGPUDescriptorSet::doInit(const DescriptorSetInfo &info) { } // namespace gfx void CCWGPUDescriptorSet::doDestroy() { - CC_DELETE(_gpuBindGroupObj); + delete _gpuBindGroupObj; } void CCWGPUDescriptorSet::update() { diff --git a/native/cocos/renderer/gfx-wgpu/WGPUDescriptorSetLayout.cpp b/native/cocos/renderer/gfx-wgpu/WGPUDescriptorSetLayout.cpp index 067cafa534..9d97dc3636 100644 --- a/native/cocos/renderer/gfx-wgpu/WGPUDescriptorSetLayout.cpp +++ b/native/cocos/renderer/gfx-wgpu/WGPUDescriptorSetLayout.cpp @@ -50,7 +50,7 @@ CCWGPUDescriptorSetLayout::CCWGPUDescriptorSetLayout() : wrapper(val::object()) { CCWGPUDevice::~CCWGPUDevice() { instance = nullptr; - CC_DELETE(_gpuDeviceObj); + delete _gpuDeviceObj; delete this; } bool CCWGPUDevice::doInit(const DeviceInfo &info) { - _gpuDeviceObj = CC_NEW(CCWGPUDeviceObject); + _gpuDeviceObj = ccnew CCWGPUDeviceObject; _gpuDeviceObj->wgpuDevice = emscripten_webgpu_get_device(); _gpuDeviceObj->wgpuQueue = wgpuDeviceGetQueue(_gpuDeviceObj->wgpuDevice); @@ -111,55 +111,55 @@ void CCWGPUDevice::doDestroy() { } Swapchain *CCWGPUDevice::createSwapchain() { - return new CCWGPUSwapchain(this); + return ccnew CCWGPUSwapchain(this); } Queue *CCWGPUDevice::createQueue() { - return CC_NEW(CCWGPUQueue); + return ccnew CCWGPUQueue; } Buffer *CCWGPUDevice::createBuffer() { - return CC_NEW(CCWGPUBuffer); + return ccnew CCWGPUBuffer; } Texture *CCWGPUDevice::createTexture() { - return CC_NEW(CCWGPUTexture); + return ccnew CCWGPUTexture; } Shader *CCWGPUDevice::createShader() { - return CC_NEW(CCWGPUShader); + return ccnew CCWGPUShader; } InputAssembler *CCWGPUDevice::createInputAssembler() { - return CC_NEW(CCWGPUInputAssembler); + return ccnew CCWGPUInputAssembler; } RenderPass *CCWGPUDevice::createRenderPass() { - return CC_NEW(CCWGPURenderPass); + return ccnew CCWGPURenderPass; } Framebuffer *CCWGPUDevice::createFramebuffer() { - return CC_NEW(CCWGPUFramebuffer); + return ccnew CCWGPUFramebuffer; } DescriptorSet *CCWGPUDevice::createDescriptorSet() { - return CC_NEW(CCWGPUDescriptorSet); + return ccnew CCWGPUDescriptorSet; } DescriptorSetLayout *CCWGPUDevice::createDescriptorSetLayout() { - return CC_NEW(CCWGPUDescriptorSetLayout); + return ccnew CCWGPUDescriptorSetLayout; } PipelineLayout *CCWGPUDevice::createPipelineLayout() { - return CC_NEW(CCWGPUPipelineLayout); + return ccnew CCWGPUPipelineLayout; } PipelineState *CCWGPUDevice::createPipelineState() { - return CC_NEW(CCWGPUPipelineState); + return ccnew CCWGPUPipelineState; } CommandBuffer *CCWGPUDevice::createCommandBuffer(const CommandBufferInfo &info, bool hasAgent) { - return CC_NEW(CCWGPUCommandBuffer); + return ccnew CCWGPUCommandBuffer; } void CCWGPUDevice::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) { @@ -288,7 +288,7 @@ emscripten::val CCWGPUDevice::copyTextureToBuffers(Texture *src, const BufferTex wgpuQueueSubmit(CCWGPUDevice::getInstance()->gpuDeviceObject()->wgpuQueue, 1, &wgpuCommandBuffer); printf("Q submit\n"); Semaphore sem{0}; - BufferMapData *bufferMapData = new BufferMapData{ + BufferMapData *bufferMapData = ccnew BufferMapData{ &sem, buffer, nullptr, @@ -315,17 +315,17 @@ void CCWGPUDevice::acquire(Swapchain *const *swapchains, uint32_t count) { } Shader *CCWGPUDevice::createShader(const SPVShaderInfoInstance &info) { - CCWGPUShader *shader = CC_NEW(CCWGPUShader); + CCWGPUShader *shader = ccnew CCWGPUShader; shader->initialize(info); return shader; } QueryPool *CCWGPUDevice::createQueryPool() { - return CC_NEW(CCWGPUQueryPool); + return ccnew CCWGPUQueryPool; } Sampler *CCWGPUDevice::createSampler(const SamplerInfo &info) { - return new CCWGPUSampler(info); + return ccnew CCWGPUSampler(info); } void CCWGPUDevice::present() { diff --git a/native/cocos/renderer/gfx-wgpu/WGPUInputAssembler.cpp b/native/cocos/renderer/gfx-wgpu/WGPUInputAssembler.cpp index c8594d934e..8e591ec0e3 100644 --- a/native/cocos/renderer/gfx-wgpu/WGPUInputAssembler.cpp +++ b/native/cocos/renderer/gfx-wgpu/WGPUInputAssembler.cpp @@ -34,7 +34,7 @@ CCWGPUInputAssembler::CCWGPUInputAssembler() : wrapper(val::obje } void CCWGPUInputAssembler::doInit(const InputAssemblerInfo &info) { - _gpuInputAssemblerObj = CC_NEW(CCWGPUInputAssemblerObject); + _gpuInputAssemblerObj = ccnew CCWGPUInputAssemblerObject; // // typedef struct WGPUVertexState { // // WGPUChainedStruct const * nextInChain; // // WGPUShaderModule module; diff --git a/native/cocos/renderer/gfx-wgpu/WGPUPipelineLayout.cpp b/native/cocos/renderer/gfx-wgpu/WGPUPipelineLayout.cpp index 29ba69874c..a3c49f00ec 100644 --- a/native/cocos/renderer/gfx-wgpu/WGPUPipelineLayout.cpp +++ b/native/cocos/renderer/gfx-wgpu/WGPUPipelineLayout.cpp @@ -39,7 +39,7 @@ CCWGPUPipelineLayout::CCWGPUPipelineLayout() : wrapper(val::obje } void CCWGPUPipelineLayout::doInit(const PipelineLayoutInfo &info) { - _gpuPipelineLayoutObj = CC_NEW(CCWGPUPipelineLayoutObject); + _gpuPipelineLayoutObj = ccnew CCWGPUPipelineLayoutObject; } void CCWGPUPipelineLayout::prepare(const ccstd::set &setInUse) { @@ -75,7 +75,7 @@ void CCWGPUPipelineLayout::doDestroy() { if (_gpuPipelineLayoutObj->wgpuPipelineLayout) { wgpuPipelineLayoutRelease(_gpuPipelineLayoutObj->wgpuPipelineLayout); } - CC_DELETE(_gpuPipelineLayoutObj); + delete _gpuPipelineLayoutObj; } } diff --git a/native/cocos/renderer/gfx-wgpu/WGPUPipelineState.cpp b/native/cocos/renderer/gfx-wgpu/WGPUPipelineState.cpp index a12c0982eb..9bfb929ce8 100644 --- a/native/cocos/renderer/gfx-wgpu/WGPUPipelineState.cpp +++ b/native/cocos/renderer/gfx-wgpu/WGPUPipelineState.cpp @@ -44,7 +44,7 @@ CCWGPUPipelineState::CCWGPUPipelineState() : wrapper(val::object( } void CCWGPUPipelineState::doInit(const PipelineStateInfo &info) { - _gpuPipelineStateObj = CC_NEW(CCWGPUPipelineStateObject); + _gpuPipelineStateObj = ccnew CCWGPUPipelineStateObject; } void CCWGPUPipelineState::check(RenderPass *renderPass) { @@ -290,7 +290,7 @@ void CCWGPUPipelineState::doDestroy() { wgpuComputePipelineRelease(_gpuPipelineStateObj->wgpuComputePipeline); } - CC_DELETE(_gpuPipelineStateObj); + delete _gpuPipelineStateObj; } } diff --git a/native/cocos/renderer/gfx-wgpu/WGPUQueryPool.cpp b/native/cocos/renderer/gfx-wgpu/WGPUQueryPool.cpp index f85c6d44b1..79aef6a70c 100644 --- a/native/cocos/renderer/gfx-wgpu/WGPUQueryPool.cpp +++ b/native/cocos/renderer/gfx-wgpu/WGPUQueryPool.cpp @@ -41,7 +41,7 @@ CCWGPUQueryPool::~CCWGPUQueryPool() { void CCWGPUQueryPool::doInit(const QueryPoolInfo & /*info*/) { CCWGPUDevice *device = CCWGPUDevice::getInstance(); - _gpuQueryPool = CC_NEW(CCWGPUQueryPoolObject); + _gpuQueryPool = ccnew CCWGPUQueryPoolObject; _gpuQueryPool->type = _type; _gpuQueryPool->maxQueryObjects = _maxQueryObjects; _gpuQueryPool->idPool.resize(_maxQueryObjects, 0U); @@ -54,7 +54,7 @@ void CCWGPUQueryPool::doInit(const QueryPoolInfo & /*info*/) { void CCWGPUQueryPool::doDestroy() { if (_gpuQueryPool) { //cmdFuncGLES3DestroyQuery(GLES3Device::getInstance(), _gpuQueryPool); - CC_DELETE(_gpuQueryPool); + delete _gpuQueryPool; _gpuQueryPool = nullptr; } } diff --git a/native/cocos/renderer/gfx-wgpu/WGPUQueue.cpp b/native/cocos/renderer/gfx-wgpu/WGPUQueue.cpp index bd8c1f1c43..e506e6fa46 100644 --- a/native/cocos/renderer/gfx-wgpu/WGPUQueue.cpp +++ b/native/cocos/renderer/gfx-wgpu/WGPUQueue.cpp @@ -39,7 +39,7 @@ CCWGPUQueue::CCWGPUQueue() : wrapper(val::object()) { } void CCWGPUQueue::doInit(const QueueInfo &info) { - _gpuQueueObject = CC_NEW(CCWGPUQueueObject); + _gpuQueueObject = ccnew CCWGPUQueueObject; _gpuQueueObject->type = info.type; _gpuQueueObject->wgpuQueue = wgpuDeviceGetQueue(CCWGPUDevice::getInstance()->gpuDeviceObject()->wgpuDevice); } @@ -49,7 +49,7 @@ void CCWGPUQueue::doDestroy() { if (_gpuQueueObject->wgpuQueue) { wgpuQueueRelease(_gpuQueueObject->wgpuQueue); } - CC_DELETE(_gpuQueueObject); + delete _gpuQueueObject; } } diff --git a/native/cocos/renderer/gfx-wgpu/WGPURenderPass.cpp b/native/cocos/renderer/gfx-wgpu/WGPURenderPass.cpp index cea4803273..3d35a8d5e1 100644 --- a/native/cocos/renderer/gfx-wgpu/WGPURenderPass.cpp +++ b/native/cocos/renderer/gfx-wgpu/WGPURenderPass.cpp @@ -58,7 +58,7 @@ public: if (samples == SampleCount::ONE) samples = info.depthStencilAttachment.sampleCount; - renderPassDesc = new WGPURenderPassDescriptor; + renderPassDesc = ccnew WGPURenderPassDescriptor; //TODO_Zeqiang: Metal-like subpass renderPassDesc->colorAttachmentCount = info.colorAttachments.size(); @@ -85,8 +85,8 @@ CCWGPURenderPass::CCWGPURenderPass() : wrapper(val::object()) { } void CCWGPURenderPass::doInit(const RenderPassInfo &info) { - _renderPassObject = new CCWGPURenderPassObject(); - _rpHelper = new CCWGPURenderPassHelper(info); + _renderPassObject = ccnew CCWGPURenderPassObject(); + _rpHelper = ccnew CCWGPURenderPassHelper(info); _renderPassObject->wgpuRenderPassDesc = _rpHelper->renderPassDesc; _renderPassObject->sampleCount = _rpHelper->sampleCount; } diff --git a/native/cocos/renderer/gfx-wgpu/WGPUSampler.cpp b/native/cocos/renderer/gfx-wgpu/WGPUSampler.cpp index fc3b486e06..46cba58cbf 100644 --- a/native/cocos/renderer/gfx-wgpu/WGPUSampler.cpp +++ b/native/cocos/renderer/gfx-wgpu/WGPUSampler.cpp @@ -74,7 +74,7 @@ CCWGPUSampler *CCWGPUSampler::defaultSampler() { .maxAnisotropy = 0, .cmpFunc = ComparisonFunc::ALWAYS, }; - anoymous::defaultSampler = new CCWGPUSampler(info); + anoymous::defaultSampler = ccnew CCWGPUSampler(info); } return anoymous::defaultSampler; } diff --git a/native/cocos/renderer/gfx-wgpu/WGPUShader.cpp b/native/cocos/renderer/gfx-wgpu/WGPUShader.cpp index d616819195..884aa4fa43 100644 --- a/native/cocos/renderer/gfx-wgpu/WGPUShader.cpp +++ b/native/cocos/renderer/gfx-wgpu/WGPUShader.cpp @@ -38,7 +38,7 @@ CCWGPUShader::CCWGPUShader() : wrapper(val::object()) { } void CCWGPUShader::initialize(const SPVShaderInfoInstance &spvInfo) { - _gpuShaderObject = CC_NEW(CCWGPUShaderObject); + _gpuShaderObject = ccnew CCWGPUShaderObject; const ShaderInfo &info = spvInfo.info; _name = info.name; @@ -91,7 +91,7 @@ void CCWGPUShader::doDestroy() { if (_gpuShaderObject->wgpuShaderComputeModule) { wgpuShaderModuleRelease(_gpuShaderObject->wgpuShaderComputeModule); } - CC_DELETE(_gpuShaderObject); + delete _gpuShaderObject; } } diff --git a/native/cocos/renderer/gfx-wgpu/WGPUSwapchain.cpp b/native/cocos/renderer/gfx-wgpu/WGPUSwapchain.cpp index b751c1b4fc..9760665dd2 100644 --- a/native/cocos/renderer/gfx-wgpu/WGPUSwapchain.cpp +++ b/native/cocos/renderer/gfx-wgpu/WGPUSwapchain.cpp @@ -81,7 +81,7 @@ void CCWGPUSwapchain::doInit(const SwapchainInfo &info) { CCWGPUDeviceObject *gpuDeviceObj = device->gpuDeviceObject(); WGPUSwapChain swapChain = wgpuDeviceCreateSwapChain(gpuDeviceObj->wgpuDevice, surface, &swapChainDesc); - _gpuSwapchainObj = CC_NEW(CCWGPUSwapchainObject); + _gpuSwapchainObj = ccnew CCWGPUSwapchainObject; _gpuSwapchainObj->wgpuSwapChain = swapChain; _gpuSwapchainObj->wgpuSurface = surface; @@ -92,10 +92,10 @@ void CCWGPUSwapchain::doInit(const SwapchainInfo &info) { .height = info.height, }; - _colorTexture = _gpuSwapchainObj->swapchainColor = CC_NEW(CCWGPUTexture); + _colorTexture = _gpuSwapchainObj->swapchainColor = ccnew CCWGPUTexture; initTexture(textureInfo, _gpuSwapchainObj->swapchainColor); textureInfo.format = Format::DEPTH_STENCIL; - _depthStencilTexture = _gpuSwapchainObj->swapchainDepthStencil = CC_NEW(CCWGPUTexture); + _depthStencilTexture = _gpuSwapchainObj->swapchainDepthStencil = ccnew CCWGPUTexture; initTexture(textureInfo, _gpuSwapchainObj->swapchainDepthStencil); // TODO: wgpuInstance @@ -109,9 +109,9 @@ void CCWGPUSwapchain::doDestroy() { CCWGPUDevice::getInstance()->unRegisterSwapchain(this); - CC_DELETE(_gpuSwapchainObj->swapchainColor); - CC_DELETE(_gpuSwapchainObj->swapchainDepthStencil); - CC_DELETE(_gpuSwapchainObj); + delete _gpuSwapchainObj->swapchainColor; + delete _gpuSwapchainObj->swapchainDepthStencil; + delete _gpuSwapchainObj; } void CCWGPUSwapchain::doResize(uint32_t width, uint32_t height, SurfaceTransform transform) { diff --git a/native/cocos/renderer/gfx-wgpu/WGPUTexture.cpp b/native/cocos/renderer/gfx-wgpu/WGPUTexture.cpp index f73e9e4041..e05d8564f0 100644 --- a/native/cocos/renderer/gfx-wgpu/WGPUTexture.cpp +++ b/native/cocos/renderer/gfx-wgpu/WGPUTexture.cpp @@ -41,7 +41,7 @@ CCWGPUTexture *defaultStorageTexture = nullptr; using namespace emscripten; CCWGPUTexture::CCWGPUTexture() : wrapper(val::object()) { - _gpuTextureObj = CC_NEW(CCWGPUTextureObject); + _gpuTextureObj = ccnew CCWGPUTextureObject; } void CCWGPUTexture::doInit(const TextureInfo &info) { @@ -145,7 +145,7 @@ void CCWGPUTexture::doDestroy() { if (_gpuTextureObj->selfView) { wgpuTextureViewRelease(_gpuTextureObj->selfView); } - CC_DELETE(_gpuTextureObj); + delete _gpuTextureObj; } _internalChanged = true; } @@ -218,7 +218,7 @@ CCWGPUTexture *CCWGPUTexture::defaultCommonTexture() { .depth = 1, .externalRes = nullptr, }; - anoymous::defaultCommonTexture = CC_NEW(CCWGPUTexture); + anoymous::defaultCommonTexture = ccnew CCWGPUTexture; anoymous::defaultCommonTexture->initialize(info); } @@ -240,7 +240,7 @@ CCWGPUTexture *CCWGPUTexture::defaultStorageTexture() { .depth = 1, .externalRes = nullptr, }; - anoymous::defaultStorageTexture = CC_NEW(CCWGPUTexture); + anoymous::defaultStorageTexture = ccnew CCWGPUTexture; anoymous::defaultStorageTexture->initialize(info); } diff --git a/native/cocos/renderer/pipeline/BatchedBuffer.cpp b/native/cocos/renderer/pipeline/BatchedBuffer.cpp index 50d514a8ef..214863156a 100644 --- a/native/cocos/renderer/pipeline/BatchedBuffer.cpp +++ b/native/cocos/renderer/pipeline/BatchedBuffer.cpp @@ -41,7 +41,7 @@ BatchedBuffer * BatchedBuffer *BatchedBuffer::get(scene::Pass *pass, uint extraKey) { auto &record = BatchedBuffer::buffers[pass]; auto &buffer = record[extraKey]; - if (buffer == nullptr) buffer = CC_NEW(BatchedBuffer(pass)); + if (buffer == nullptr) buffer = ccnew BatchedBuffer(pass); return buffer; } diff --git a/native/cocos/renderer/pipeline/GeometryRenderer.cpp b/native/cocos/renderer/pipeline/GeometryRenderer.cpp index 8e735e8373..684744ad40 100644 --- a/native/cocos/renderer/pipeline/GeometryRenderer.cpp +++ b/native/cocos/renderer/pipeline/GeometryRenderer.cpp @@ -139,7 +139,7 @@ GeometryRendererInfo::GeometryRendererInfo() } GeometryRenderer::GeometryRenderer() { - _buffers = new GeometryVertexBuffers(); + _buffers = ccnew GeometryVertexBuffers(); } GeometryRenderer::~GeometryRenderer() { diff --git a/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.cpp b/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.cpp index cc670319c4..278951033a 100644 --- a/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.cpp +++ b/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.cpp @@ -65,7 +65,7 @@ void GlobalDSManager::activate(gfx::Device *device) { if (_globalDescriptorSet) { _globalDescriptorSet->destroy(); - CC_DELETE(_globalDescriptorSet); + delete _globalDescriptorSet; } _globalDescriptorSet = device->createDescriptorSet({_descriptorSetLayout}); } diff --git a/native/cocos/renderer/pipeline/InstancedBuffer.cpp b/native/cocos/renderer/pipeline/InstancedBuffer.cpp index 3e54d884c7..b6305a4cc6 100644 --- a/native/cocos/renderer/pipeline/InstancedBuffer.cpp +++ b/native/cocos/renderer/pipeline/InstancedBuffer.cpp @@ -40,7 +40,7 @@ InstancedBuffer * InstancedBuffer *InstancedBuffer::get(scene::Pass *pass, uint extraKey) { auto &record = buffers[pass]; auto &buffer = record[extraKey]; - if (buffer == nullptr) buffer = CC_NEW(InstancedBuffer(pass)); + if (buffer == nullptr) buffer = ccnew InstancedBuffer(pass); return buffer; } diff --git a/native/cocos/renderer/pipeline/PipelineSceneData.cpp b/native/cocos/renderer/pipeline/PipelineSceneData.cpp index 805f0455db..d3285f2997 100644 --- a/native/cocos/renderer/pipeline/PipelineSceneData.cpp +++ b/native/cocos/renderer/pipeline/PipelineSceneData.cpp @@ -41,11 +41,11 @@ namespace cc { namespace pipeline { PipelineSceneData::PipelineSceneData() { - _fog = new scene::Fog(); // cjh how to delete? - _ambient = new scene::Ambient(); - _skybox = new scene::Skybox(); - _shadow = new scene::Shadows(); - _octree = new scene::Octree(); + _fog = ccnew scene::Fog(); // cjh how to delete? + _ambient = ccnew scene::Ambient(); + _skybox = ccnew scene::Skybox(); + _shadow = ccnew scene::Shadows(); + _octree = ccnew scene::Octree(); } PipelineSceneData::~PipelineSceneData() { @@ -83,7 +83,7 @@ void PipelineSceneData::initOcclusionQuery() { } if (!_occlusionQueryMaterial) { - _occlusionQueryMaterial = new Material(); + _occlusionQueryMaterial = ccnew Material(); _occlusionQueryMaterial->setUuid("default-occlusion-query-material"); IMaterialInfo info; info.effectName = "occlusion-query"; @@ -99,7 +99,7 @@ void PipelineSceneData::initGeometryRenderer() { _geometryRendererShaders.reserve(GEOMETRY_RENDERER_TECHNIQUE_COUNT); for (uint32_t tech = 0; tech < GEOMETRY_RENDERER_TECHNIQUE_COUNT; tech++) { - _geometryRendererMaterials[tech] = new Material(); + _geometryRendererMaterials[tech] = ccnew Material(); std::stringstream ss; ss << "geometry-renderer-material-" << tech; @@ -120,7 +120,7 @@ void PipelineSceneData::initGeometryRenderer() { void PipelineSceneData::initDebugRenderer() { if (!_debugRendererMaterial) { - _debugRendererMaterial = new Material(); + _debugRendererMaterial = ccnew Material(); _debugRendererMaterial->setUuid("default-debug-renderer-material"); IMaterialInfo info; info.effectName = "debug-renderer"; diff --git a/native/cocos/renderer/pipeline/PlanarShadowQueue.cpp b/native/cocos/renderer/pipeline/PlanarShadowQueue.cpp index 4b9d2e48a5..9219e5ac39 100644 --- a/native/cocos/renderer/pipeline/PlanarShadowQueue.cpp +++ b/native/cocos/renderer/pipeline/PlanarShadowQueue.cpp @@ -44,7 +44,7 @@ namespace pipeline { PlanarShadowQueue::PlanarShadowQueue(RenderPipeline *pipeline) : _pipeline(pipeline) { - _instancedQueue = CC_NEW(RenderInstancedQueue); + _instancedQueue = ccnew RenderInstancedQueue; } PlanarShadowQueue::~PlanarShadowQueue() = default; diff --git a/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp b/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp index c7c89f29b0..bd2d1c4a1b 100644 --- a/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp +++ b/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp @@ -53,8 +53,8 @@ namespace cc { namespace pipeline { RenderAdditiveLightQueue::RenderAdditiveLightQueue(RenderPipeline *pipeline) : _pipeline(pipeline), - _instancedQueue(CC_NEW(RenderInstancedQueue)), - _batchedQueue(CC_NEW(RenderBatchedQueue)) { + _instancedQueue(ccnew RenderInstancedQueue), + _batchedQueue(ccnew RenderBatchedQueue) { auto * device = gfx::Device::getInstance(); const auto alignment = device->getCapabilities().uboOffsetAlignment; _lightBufferStride = ((UBOForwardLight::SIZE + alignment - 1) / alignment) * alignment; diff --git a/native/cocos/renderer/pipeline/RenderPipeline.cpp b/native/cocos/renderer/pipeline/RenderPipeline.cpp index 375209aeab..889cb37dca 100644 --- a/native/cocos/renderer/pipeline/RenderPipeline.cpp +++ b/native/cocos/renderer/pipeline/RenderPipeline.cpp @@ -59,8 +59,8 @@ RenderPipeline::RenderPipeline() : _device(gfx::Device::getInstance()) { RenderPipeline::instance = this; - _globalDSManager = new GlobalDSManager(); - _pipelineUBO = new PipelineUBO(); + _globalDSManager = ccnew GlobalDSManager(); + _pipelineUBO = ccnew PipelineUBO(); } RenderPipeline::~RenderPipeline() { diff --git a/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp b/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp index 86266eecf1..7294d9c9fb 100644 --- a/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp +++ b/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp @@ -47,8 +47,8 @@ ShadowMapBatchedQueue::ShadowMapBatchedQueue(RenderPipeline *pipeline) : _phaseID(getPhaseID("shadow-caster")) { _pipeline = pipeline; _buffer = pipeline->getDescriptorSet()->getBuffer(UBOShadow::BINDING); - _instancedQueue = CC_NEW(RenderInstancedQueue); - _batchedQueue = CC_NEW(RenderBatchedQueue); + _instancedQueue = ccnew RenderInstancedQueue; + _batchedQueue = ccnew RenderBatchedQueue; } ShadowMapBatchedQueue::~ShadowMapBatchedQueue() = default; diff --git a/native/cocos/renderer/pipeline/custom/GraphTypes.h b/native/cocos/renderer/pipeline/custom/GraphTypes.h index ceef18b267..adf4413754 100644 --- a/native/cocos/renderer/pipeline/custom/GraphTypes.h +++ b/native/cocos/renderer/pipeline/custom/GraphTypes.h @@ -24,16 +24,17 @@ ****************************************************************************/ #pragma once -#include "cocos/base/Variant.h" -#include "cocos/base/std/container/list.h" -#include "cocos/base/std/container/string.h" -#include "cocos/renderer/pipeline/custom/Overload.h" #include #include #include #include #include +#include "base/Variant.h" +#include "base/memory/Memory.h" +#include "base/std/container/list.h" +#include "base/std/container/string.h" +#include "renderer/pipeline/custom/Overload.h" namespace boost { @@ -197,7 +198,7 @@ template class StoredEdgeWithProperty : public StoredEdge { public: StoredEdgeWithProperty(VertexDescriptor target, const EdgeProperty &p) - : StoredEdge(target), property(new EdgeProperty(p)) {} + : StoredEdge(target), property(ccnew EdgeProperty(p)) {} StoredEdgeWithProperty(VertexDescriptor target, std::unique_ptr &&ptr) : StoredEdge(target), property(std::move(ptr)) {} StoredEdgeWithProperty(VertexDescriptor target) // NOLINT(google-explicit-constructor) diff --git a/native/cocos/renderer/pipeline/custom/NativePipelineImpl.cpp b/native/cocos/renderer/pipeline/custom/NativePipelineImpl.cpp index 0dc45572df..e7123bea88 100644 --- a/native/cocos/renderer/pipeline/custom/NativePipelineImpl.cpp +++ b/native/cocos/renderer/pipeline/custom/NativePipelineImpl.cpp @@ -44,7 +44,7 @@ namespace cc { namespace render { NativePipeline::NativePipeline() noexcept -: device(gfx::Device::getInstance()), globalDSManager(std::make_unique()), pipelineSceneData(new pipeline::PipelineSceneData()) // NOLINT +: device(gfx::Device::getInstance()), globalDSManager(std::make_unique()), pipelineSceneData(ccnew pipeline::PipelineSceneData()) // NOLINT { } diff --git a/native/cocos/renderer/pipeline/custom/RenderInterfaceImpl.cpp b/native/cocos/renderer/pipeline/custom/RenderInterfaceImpl.cpp index 443c2ae8fc..2f5cab1d29 100644 --- a/native/cocos/renderer/pipeline/custom/RenderInterfaceImpl.cpp +++ b/native/cocos/renderer/pipeline/custom/RenderInterfaceImpl.cpp @@ -31,7 +31,7 @@ namespace cc { namespace render { Pipeline* Factory::createPipeline() { - return new NativePipeline(); + return ccnew NativePipeline(); } DescriptorHierarchy* Factory::createDescriptorHierarchy() { diff --git a/native/cocos/renderer/pipeline/deferred/DeferredPipeline.cpp b/native/cocos/renderer/pipeline/deferred/DeferredPipeline.cpp index 5885f0756e..c099b8a728 100644 --- a/native/cocos/renderer/pipeline/deferred/DeferredPipeline.cpp +++ b/native/cocos/renderer/pipeline/deferred/DeferredPipeline.cpp @@ -57,7 +57,7 @@ namespace pipeline { (dst)[(offset) + 3] = (src).w; DeferredPipeline::DeferredPipeline() { - _pipelineSceneData = new DeferredPipelineSceneData(); + _pipelineSceneData = ccnew DeferredPipelineSceneData(); } DeferredPipeline::~DeferredPipeline() = default; @@ -76,11 +76,11 @@ bool DeferredPipeline::initialize(const RenderPipelineInfo &info) { RenderPipeline::initialize(info); if (_flows.empty()) { - auto *shadowFlow = CC_NEW(ShadowFlow); + auto *shadowFlow = ccnew ShadowFlow; shadowFlow->initialize(ShadowFlow::getInitializeInfo()); _flows.emplace_back(shadowFlow); - auto *mainFlow = CC_NEW(MainFlow); + auto *mainFlow = ccnew MainFlow; mainFlow->initialize(MainFlow::getInitializeInfo()); _flows.emplace_back(mainFlow); } @@ -189,7 +189,7 @@ bool DeferredPipeline::activeRenderer(gfx::Swapchain *swapchain) { if (_clusterEnabled) { // cluster component resource - _clusterComp = new ClusterLightCulling(this); + _clusterComp = ccnew ClusterLightCulling(this); _clusterComp->initialize(this->getDevice()); } diff --git a/native/cocos/renderer/pipeline/deferred/DeferredPipelineSceneData.cpp b/native/cocos/renderer/pipeline/deferred/DeferredPipelineSceneData.cpp index 375834b1fb..1cee6e40c0 100644 --- a/native/cocos/renderer/pipeline/deferred/DeferredPipelineSceneData.cpp +++ b/native/cocos/renderer/pipeline/deferred/DeferredPipelineSceneData.cpp @@ -21,7 +21,7 @@ void DeferredPipelineSceneData::updatePipelineSceneData() { void DeferredPipelineSceneData::initPipelinePassInfo() { // builtin deferred material - _lightingMaterial = new Material(); + _lightingMaterial = ccnew Material(); _lightingMaterial->setUuid("builtin-deferred-material"); IMaterialInfo materialInfo; materialInfo.effectName = "deferred-lighting"; @@ -30,7 +30,7 @@ void DeferredPipelineSceneData::initPipelinePassInfo() { pass->tryCompile(); } - _bloomMaterial = new Material(); + _bloomMaterial = ccnew Material(); _bloomMaterial->setUuid("builtin-bloom-material"); materialInfo.effectName = "bloom"; _bloomMaterial->initialize(materialInfo); @@ -38,7 +38,7 @@ void DeferredPipelineSceneData::initPipelinePassInfo() { pass->tryCompile(); } - _postProcessMaterial = new Material(); + _postProcessMaterial = ccnew Material(); _postProcessMaterial->setUuid("builtin-post-process-material"); #if ENABLE_ANTIALIAS_FXAA > 0 _antiAliasing = AntiAliasing::FXAA; @@ -59,7 +59,7 @@ void DeferredPipelineSceneData::setAntiAliasing(AntiAliasing value) { if (_postProcessMaterial) { auto &defines = (*_postProcessMaterial->getPasses())[0]->getDefines(); defines.emplace("ANTIALIAS_TYPE", static_cast(value)); - auto * renderMat = new Material(); + auto * renderMat = ccnew Material(); IMaterialInfo materialInfo; materialInfo.effectAsset = _postProcessMaterial->getEffectAsset(); materialInfo.defines = defines; diff --git a/native/cocos/renderer/pipeline/deferred/GbufferStage.cpp b/native/cocos/renderer/pipeline/deferred/GbufferStage.cpp index 6f53c144c9..721119b030 100644 --- a/native/cocos/renderer/pipeline/deferred/GbufferStage.cpp +++ b/native/cocos/renderer/pipeline/deferred/GbufferStage.cpp @@ -52,8 +52,8 @@ RenderStageInfo GbufferStage::initInfo = { const RenderStageInfo &GbufferStage::getInitializeInfo() { return GbufferStage::initInfo; } GbufferStage::GbufferStage() { - _batchedQueue = CC_NEW(RenderBatchedQueue); - _instancedQueue = CC_NEW(RenderInstancedQueue); + _batchedQueue = ccnew RenderBatchedQueue; + _instancedQueue = ccnew RenderInstancedQueue; } GbufferStage::~GbufferStage() = default; @@ -72,9 +72,9 @@ void GbufferStage::activate(RenderPipeline *pipeline, RenderFlow *flow) { uint phase = convertPhase(descriptor.stages); RenderQueueSortFunc sortFunc = convertQueueSortFunc(descriptor.sortMode); RenderQueueCreateInfo info = {descriptor.isTransparent, phase, sortFunc}; - _renderQueues.emplace_back(CC_NEW(RenderQueue(_pipeline, std::move(info), true))); + _renderQueues.emplace_back(ccnew RenderQueue(_pipeline, std::move(info), true)); } - _planarShadowQueue = CC_NEW(PlanarShadowQueue(_pipeline)); + _planarShadowQueue = ccnew PlanarShadowQueue(_pipeline); } void GbufferStage::destroy() { diff --git a/native/cocos/renderer/pipeline/deferred/LightingStage.cpp b/native/cocos/renderer/pipeline/deferred/LightingStage.cpp index a589a00e6e..ed0d8d7ad7 100644 --- a/native/cocos/renderer/pipeline/deferred/LightingStage.cpp +++ b/native/cocos/renderer/pipeline/deferred/LightingStage.cpp @@ -271,7 +271,7 @@ void LightingStage::activate(RenderPipeline *pipeline, RenderFlow *flow) { uint phase = convertPhase(descriptor.stages); RenderQueueSortFunc sortFunc = convertQueueSortFunc(descriptor.sortMode); RenderQueueCreateInfo info = {descriptor.isTransparent, phase, sortFunc}; - _renderQueues.emplace_back(CC_NEW(RenderQueue(_pipeline, std::move(info), true))); + _renderQueues.emplace_back(ccnew RenderQueue(_pipeline, std::move(info), true)); } // not use cluster shading, go normal deferred render path @@ -287,14 +287,14 @@ void LightingStage::activate(RenderPipeline *pipeline, RenderFlow *flow) { initLightingBuffer(); } - _planarShadowQueue = CC_NEW(PlanarShadowQueue(_pipeline)); + _planarShadowQueue = ccnew PlanarShadowQueue(_pipeline); // create reflection resource RenderQueueCreateInfo info = {true, _reflectionPhaseID, transparentCompareFn}; - _reflectionComp = new ReflectionComp(); + _reflectionComp = ccnew ReflectionComp(); _reflectionComp->init(_device, 8, 8); - _reflectionRenderQueue = CC_NEW(RenderQueue(_pipeline, std::move(info))); + _reflectionRenderQueue = ccnew RenderQueue(_pipeline, std::move(info)); _defaultSampler = pipeline->getGlobalDSManager()->getPointSampler(); } diff --git a/native/cocos/renderer/pipeline/deferred/MainFlow.cpp b/native/cocos/renderer/pipeline/deferred/MainFlow.cpp index 54cf574c95..888b4928ca 100644 --- a/native/cocos/renderer/pipeline/deferred/MainFlow.cpp +++ b/native/cocos/renderer/pipeline/deferred/MainFlow.cpp @@ -50,16 +50,16 @@ bool MainFlow::initialize(const RenderFlowInfo &info) { RenderFlow::initialize(info); if (_stages.empty()) { - auto *gbufferStage = CC_NEW(GbufferStage); + auto *gbufferStage = ccnew GbufferStage; gbufferStage->initialize(GbufferStage::getInitializeInfo()); _stages.emplace_back(gbufferStage); - auto *lightingStage = CC_NEW(LightingStage); + auto *lightingStage = ccnew LightingStage; lightingStage->initialize(LightingStage::getInitializeInfo()); _stages.emplace_back(lightingStage); - auto *bloomStage = CC_NEW(BloomStage); + auto *bloomStage = ccnew BloomStage; bloomStage->initialize(BloomStage::getInitializeInfo()); _stages.emplace_back(bloomStage); - auto *postProcessStage = CC_NEW(PostProcessStage); + auto *postProcessStage = ccnew PostProcessStage; postProcessStage->initialize(PostProcessStage::getInitializeInfo()); _stages.emplace_back(postProcessStage); } diff --git a/native/cocos/renderer/pipeline/deferred/PostProcessStage.cpp b/native/cocos/renderer/pipeline/deferred/PostProcessStage.cpp index cb379a24cc..7eecf132c6 100644 --- a/native/cocos/renderer/pipeline/deferred/PostProcessStage.cpp +++ b/native/cocos/renderer/pipeline/deferred/PostProcessStage.cpp @@ -60,7 +60,7 @@ RenderStageInfo PostProcessStage::initInfo = { const RenderStageInfo &PostProcessStage::getInitializeInfo() { return PostProcessStage::initInfo; } PostProcessStage::PostProcessStage() { - _uiPhase = CC_NEW(UIPhase); + _uiPhase = ccnew UIPhase; } bool PostProcessStage::initialize(const RenderStageInfo &info) { @@ -93,7 +93,7 @@ void PostProcessStage::activate(RenderPipeline *pipeline, RenderFlow *flow) { } RenderQueueCreateInfo info = {descriptor.isTransparent, phase, sortFunc}; - _renderQueues.emplace_back(CC_NEW(RenderQueue(_pipeline, std::move(info)))); + _renderQueues.emplace_back(ccnew RenderQueue(_pipeline, std::move(info))); } } diff --git a/native/cocos/renderer/pipeline/forward/ForwardFlow.cpp b/native/cocos/renderer/pipeline/forward/ForwardFlow.cpp index b7e0e81ded..5d7062b0d0 100644 --- a/native/cocos/renderer/pipeline/forward/ForwardFlow.cpp +++ b/native/cocos/renderer/pipeline/forward/ForwardFlow.cpp @@ -45,7 +45,7 @@ bool ForwardFlow::initialize(const RenderFlowInfo &info) { RenderFlow::initialize(info); if (_stages.empty()) { - auto *forwardStage = CC_NEW(ForwardStage); + auto *forwardStage = ccnew ForwardStage; forwardStage->initialize(ForwardStage::getInitializeInfo()); _stages.emplace_back(forwardStage); } diff --git a/native/cocos/renderer/pipeline/forward/ForwardPipeline.cpp b/native/cocos/renderer/pipeline/forward/ForwardPipeline.cpp index de0ebf3b8f..252f764d40 100644 --- a/native/cocos/renderer/pipeline/forward/ForwardPipeline.cpp +++ b/native/cocos/renderer/pipeline/forward/ForwardPipeline.cpp @@ -50,7 +50,7 @@ namespace { } // namespace ForwardPipeline::ForwardPipeline() { - _pipelineSceneData = new PipelineSceneData(); + _pipelineSceneData = ccnew PipelineSceneData(); } framegraph::StringHandle ForwardPipeline::fgStrHandleForwardColorTexture = framegraph::FrameGraph::stringToHandle("forwardColorTexture"); @@ -61,11 +61,11 @@ bool ForwardPipeline::initialize(const RenderPipelineInfo &info) { RenderPipeline::initialize(info); if (_flows.empty()) { - auto *shadowFlow = CC_NEW(ShadowFlow); + auto *shadowFlow = ccnew ShadowFlow; shadowFlow->initialize(ShadowFlow::getInitializeInfo()); _flows.emplace_back(shadowFlow); - auto *forwardFlow = CC_NEW(ForwardFlow); + auto *forwardFlow = ccnew ForwardFlow; forwardFlow->initialize(ForwardFlow::getInitializeInfo()); _flows.emplace_back(forwardFlow); } diff --git a/native/cocos/renderer/pipeline/forward/ForwardStage.cpp b/native/cocos/renderer/pipeline/forward/ForwardStage.cpp index cd7d94a7db..b589515505 100644 --- a/native/cocos/renderer/pipeline/forward/ForwardStage.cpp +++ b/native/cocos/renderer/pipeline/forward/ForwardStage.cpp @@ -55,9 +55,9 @@ RenderStageInfo ForwardStage::initInfo = { const RenderStageInfo &ForwardStage::getInitializeInfo() { return ForwardStage::initInfo; } ForwardStage::ForwardStage() { - _batchedQueue = CC_NEW(RenderBatchedQueue); - _instancedQueue = CC_NEW(RenderInstancedQueue); - _uiPhase = CC_NEW(UIPhase); + _batchedQueue = ccnew RenderBatchedQueue; + _instancedQueue = ccnew RenderInstancedQueue; + _uiPhase = ccnew UIPhase; } ForwardStage::~ForwardStage() = default; @@ -76,11 +76,11 @@ void ForwardStage::activate(RenderPipeline *pipeline, RenderFlow *flow) { uint phase = convertPhase(descriptor.stages); RenderQueueSortFunc sortFunc = convertQueueSortFunc(descriptor.sortMode); RenderQueueCreateInfo info = {descriptor.isTransparent, phase, sortFunc}; - _renderQueues.emplace_back(CC_NEW(RenderQueue(_pipeline, std::move(info), true))); + _renderQueues.emplace_back(ccnew RenderQueue(_pipeline, std::move(info), true)); } - _additiveLightQueue = CC_NEW(RenderAdditiveLightQueue(_pipeline)); - _planarShadowQueue = CC_NEW(PlanarShadowQueue(_pipeline)); + _additiveLightQueue = ccnew RenderAdditiveLightQueue(_pipeline); + _planarShadowQueue = ccnew PlanarShadowQueue(_pipeline); _uiPhase->activate(pipeline); } diff --git a/native/cocos/renderer/pipeline/shadow/ShadowFlow.cpp b/native/cocos/renderer/pipeline/shadow/ShadowFlow.cpp index 4da4f949b0..7ae7169ab7 100644 --- a/native/cocos/renderer/pipeline/shadow/ShadowFlow.cpp +++ b/native/cocos/renderer/pipeline/shadow/ShadowFlow.cpp @@ -57,7 +57,7 @@ ShadowFlow::~ShadowFlow() = default; bool ShadowFlow::initialize(const RenderFlowInfo &info) { RenderFlow::initialize(info); if (_stages.empty()) { - auto *shadowStage = CC_NEW(ShadowStage); + auto *shadowStage = ccnew ShadowStage; shadowStage->initialize(ShadowStage::getInitializeInfo()); _stages.emplace_back(shadowStage); } @@ -186,7 +186,7 @@ void ShadowFlow::resizeShadowMap() { auto renderTargets = framebuffer->getColorTextures(); for (const auto *renderTarget : renderTargets) { - CC_DELETE(renderTarget); + delete renderTarget; } renderTargets.clear(); renderTargets.emplace_back(gfx::Device::getInstance()->createTexture({ @@ -201,7 +201,7 @@ void ShadowFlow::resizeShadowMap() { } auto *depth = framebuffer->getDepthStencilTexture(); - CC_DELETE(depth); + delete depth; depth = device->createTexture({ gfx::TextureType::TEX2D, gfx::TextureUsageBit::DEPTH_STENCIL_ATTACHMENT, @@ -301,7 +301,7 @@ void ShadowFlow::initShadowFrameBuffer(RenderPipeline *pipeline, const scene::Li void ShadowFlow::destroy() { _renderPass = nullptr; for (const auto &rpPair : renderPassHashMap) { - CC_DELETE(rpPair.second); + delete rpPair.second; } renderPassHashMap.clear(); diff --git a/native/cocos/renderer/pipeline/shadow/ShadowStage.cpp b/native/cocos/renderer/pipeline/shadow/ShadowStage.cpp index b135fa17af..a4c9370ea1 100644 --- a/native/cocos/renderer/pipeline/shadow/ShadowStage.cpp +++ b/native/cocos/renderer/pipeline/shadow/ShadowStage.cpp @@ -60,7 +60,7 @@ bool ShadowStage::initialize(const RenderStageInfo &info) { void ShadowStage::activate(RenderPipeline *pipeline, RenderFlow *flow) { RenderStage::activate(pipeline, flow); - _additiveShadowQueue = CC_NEW(ShadowMapBatchedQueue(pipeline)); + _additiveShadowQueue = ccnew ShadowMapBatchedQueue(pipeline); } void ShadowStage::render(scene::Camera *camera) { diff --git a/native/cocos/scene/Camera.cpp b/native/cocos/scene/Camera.cpp index 3c4b004cf7..fd4992e711 100644 --- a/native/cocos/scene/Camera.cpp +++ b/native/cocos/scene/Camera.cpp @@ -68,11 +68,11 @@ Camera::Camera(gfx::Device *device) _isoValue = Camera::ISOS[static_cast(_iso)]; _aspect = _screenScale = 1.F; - _frustum = new geometry::Frustum(); + _frustum = ccnew geometry::Frustum(); _frustum->addRef(); _frustum->setAccurate(true); - _geometryRenderer = new pipeline::GeometryRenderer(); + _geometryRenderer = ccnew pipeline::GeometryRenderer(); _geometryRenderer->activate(device); if (correctionMatrices.empty()) { diff --git a/native/cocos/scene/Model.cpp b/native/cocos/scene/Model.cpp index 3ecfbe8dc4..150ae699ca 100644 --- a/native/cocos/scene/Model.cpp +++ b/native/cocos/scene/Model.cpp @@ -269,18 +269,18 @@ void Model::createBoundingShape(const cc::optional &minPos, const cc::opti } if (!_modelBounds) { - _modelBounds = new geometry::AABB(); + _modelBounds = ccnew geometry::AABB(); } geometry::AABB::fromPoints(minPos.value(), maxPos.value(), _modelBounds); if (!_worldBounds) { - _worldBounds = new geometry::AABB(); + _worldBounds = ccnew geometry::AABB(); } geometry::AABB::fromPoints(minPos.value(), maxPos.value(), _worldBounds); } SubModel *Model::createSubModel() { - return new SubModel(); + return ccnew SubModel(); } void Model::initSubModel(index_t idx, cc::RenderingSubMesh *subMeshData, Material *mat) { diff --git a/native/cocos/scene/Octree.cpp b/native/cocos/scene/Octree.cpp index 7efa14e433..a99fc60c66 100644 --- a/native/cocos/scene/Octree.cpp +++ b/native/cocos/scene/Octree.cpp @@ -126,7 +126,7 @@ BBox OctreeNode::getChildBox(uint32_t index) const { OctreeNode *OctreeNode::getOrCreateChild(uint32_t index) { if (!_children[index]) { BBox childBox = getChildBox(index); - auto *child = _children[index] = new OctreeNode(_owner, this); + auto *child = _children[index] = ccnew OctreeNode(_owner, this); child->setBox(childBox); child->setDepth(_depth + 1); child->setIndex(index); @@ -299,7 +299,7 @@ void OctreeNode::queryVisibilitySequentially(const Camera *camera, const geometr * Octree class */ Octree::Octree() { - _root = new OctreeNode(this, nullptr); + _root = ccnew OctreeNode(this, nullptr); } Octree::~Octree() { @@ -347,7 +347,7 @@ void Octree::resize(const Vec3 &minPos, const Vec3 &maxPos, uint32_t maxDepth) { _root->gatherModels(models); delete _root; - _root = new OctreeNode(this, nullptr); + _root = ccnew OctreeNode(this, nullptr); _root->setBox(BBox{minPos - expand, maxPos}); _root->setDepth(0); _root->setIndex(0); diff --git a/native/cocos/scene/Pass.cpp b/native/cocos/scene/Pass.cpp index cce6f1ec5c..1685242462 100644 --- a/native/cocos/scene/Pass.cpp +++ b/native/cocos/scene/Pass.cpp @@ -245,7 +245,7 @@ pipeline::InstancedBuffer *Pass::getInstancedBuffer(int32_t extraKey) { if (iter != _instancedBuffers.end()) { return iter->second.get(); } - auto *instancedBuffer = new pipeline::InstancedBuffer(this); + auto *instancedBuffer = ccnew pipeline::InstancedBuffer(this); _instancedBuffers[extraKey] = instancedBuffer; return instancedBuffer; } @@ -255,7 +255,7 @@ pipeline::BatchedBuffer *Pass::getBatchedBuffer(int32_t extraKey) { if (iter != _batchedBuffers.end()) { return iter->second.get(); } - auto *batchedBuffers = new pipeline::BatchedBuffer(this); + auto *batchedBuffers = ccnew pipeline::BatchedBuffer(this); _batchedBuffers[extraKey] = batchedBuffers; return batchedBuffers; } @@ -535,7 +535,7 @@ void Pass::doInit(const IPassInfoFull &info, bool /*copyDefines*/ /* = false */) // https://bugs.chromium.org/p/chromium/issues/detail?id=988988 bufferInfo.size = static_cast(std::ceil(static_cast(totalSize) / 16.F)) * 16; _rootBuffer = device->createBuffer(bufferInfo); - _rootBlock = new ArrayBuffer(totalSize); + _rootBlock = ccnew ArrayBuffer(totalSize); } gfx::BufferViewInfo bufferViewInfo; diff --git a/native/cocos/scene/Shadow.cpp b/native/cocos/scene/Shadow.cpp index 570f9f8cac..9f3055cd30 100644 --- a/native/cocos/scene/Shadow.cpp +++ b/native/cocos/scene/Shadow.cpp @@ -166,7 +166,7 @@ void Shadows::updatePlanarInfo() { } void Shadows::createInstanceMaterial() { - _instancingMaterial = new Material(); + _instancingMaterial = ccnew Material(); IMaterialInfo materialInfo; materialInfo.effectName = "planar-shadow"; @@ -176,7 +176,7 @@ void Shadows::createInstanceMaterial() { } void Shadows::createMaterial() { - _material = new Material(); + _material = ccnew Material(); IMaterialInfo materialInfo; materialInfo.effectName = "planar-shadow"; diff --git a/native/cocos/scene/Skybox.cpp b/native/cocos/scene/Skybox.cpp index d0fcb4c3fb..10516a4637 100644 --- a/native/cocos/scene/Skybox.cpp +++ b/native/cocos/scene/Skybox.cpp @@ -238,7 +238,7 @@ void Skybox::activate() { bool isRGBE = envmap != nullptr ? envmap->isRGBE : _default->isRGBE; if (!skyboxMaterial) { - auto * mat = new Material(); + auto * mat = ccnew Material(); MacroRecord defines{{"USE_RGBE_CUBEMAP", isRGBE}}; IMaterialInfo matInfo; matInfo.effectName = ccstd::string{"skybox"}; @@ -246,7 +246,7 @@ void Skybox::activate() { mat->initialize({matInfo}); IMaterialInstanceInfo matInstInfo; matInstInfo.parent = mat; - skyboxMaterial = new MaterialInstance(matInstInfo); + skyboxMaterial = ccnew MaterialInstance(matInstInfo); skyboxMaterial->addRef(); EventDispatcher::addCustomEventListener(EVENT_CLOSE, [](const CustomEvent & /*unused*/) { skyboxMaterial->release(); diff --git a/native/cocos/scene/SpotLight.cpp b/native/cocos/scene/SpotLight.cpp index bac3860b37..d7fbf28ac4 100644 --- a/native/cocos/scene/SpotLight.cpp +++ b/native/cocos/scene/SpotLight.cpp @@ -36,9 +36,9 @@ namespace cc { namespace scene { SpotLight::SpotLight() { _type = LightType::SPOT; - _aabb = new geometry::AABB(); + _aabb = ccnew geometry::AABB(); _aabb->addRef(); - _frustum = new geometry::Frustum(); + _frustum = ccnew geometry::Frustum(); _frustum->addRef(); } diff --git a/native/cocos/ui/webview/WebView-inl.h b/native/cocos/ui/webview/WebView-inl.h index 867ca42f8c..74f01afac7 100644 --- a/native/cocos/ui/webview/WebView-inl.h +++ b/native/cocos/ui/webview/WebView-inl.h @@ -39,7 +39,7 @@ static_assert(false, "WebView only supported on iOS & Android"); namespace cc { WebView::WebView() -: _impl(new WebViewImpl(this)), +: _impl(ccnew WebViewImpl(this)), _onJSCallback(nullptr), _onShouldStartLoading(nullptr), _onDidFinishLoading(nullptr), @@ -51,11 +51,10 @@ WebView::~WebView() { } WebView *WebView::create() { - auto webView = new (std::nothrow) WebView(); + auto webView = ccnew WebView(); if (webView) { return webView; } - CC_SAFE_DELETE(webView); return nullptr; } diff --git a/package-lock.json b/package-lock.json index b97c6a2a5b..de3de3f180 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1940,7 +1940,7 @@ }, "which-module": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", + "resolved": "https://registry.npm.taobao.org/which-module/download/which-module-2.0.0.tgz", "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", "dev": true }, @@ -3348,7 +3348,7 @@ }, "@rollup/pluginutils": { "version": "4.1.2", - "resolved": "https://registry.npmmirror.com/@rollup/pluginutils/download/@rollup/pluginutils-4.1.2.tgz", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-4.1.2.tgz", "integrity": "sha512-ROn4qvkxP9SyPeHaf7uQC/GPFY6L/OWy9+bd9AwcjOAWQwxRscoEyAUD8qCY5o5iL4jqQwoLk2kaTKJPb/HwzQ==", "dev": true, "requires": { @@ -13088,7 +13088,7 @@ }, "path-exists": { "version": "3.0.0", - "resolved": "https://registry.npm.taobao.org/path-exists/download/path-exists-3.0.0.tgz", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", "dev": true },