diff --git a/native/cocos/2d/renderer/Batcher2d.h b/native/cocos/2d/renderer/Batcher2d.h index bc413ec988..4749b4c0e2 100644 --- a/native/cocos/2d/renderer/Batcher2d.h +++ b/native/cocos/2d/renderer/Batcher2d.h @@ -74,7 +74,6 @@ private: bool _isInit = false; inline void fillIndexBuffers(RenderDrawInfo* drawInfo) { // NOLINT(readability-convert-member-functions-to-static) - uint32_t vertexOffset = drawInfo->getVertexOffset(); uint16_t* ib = drawInfo->getIDataBuffer(); UIMeshBuffer* buffer = drawInfo->getMeshBuffer(); diff --git a/native/cocos/2d/renderer/UIMeshBuffer.cpp b/native/cocos/2d/renderer/UIMeshBuffer.cpp index f5d52d08d5..5c24813f96 100644 --- a/native/cocos/2d/renderer/UIMeshBuffer.cpp +++ b/native/cocos/2d/renderer/UIMeshBuffer.cpp @@ -101,7 +101,6 @@ void UIMeshBuffer::uploadBuffers() { uint32_t indexCount = getIndexOffset(); uint32_t byteCount = getByteOffset(); - uint32_t dataCount = byteCount >> 2; gfx::InputAssembler* ia = _iaPool[0]; gfx::BufferList vBuffers = ia->getVertexBuffers(); diff --git a/native/cocos/3d/assets/Mesh.cpp b/native/cocos/3d/assets/Mesh.cpp index d72015b069..a58865c9dd 100644 --- a/native/cocos/3d/assets/Mesh.cpp +++ b/native/cocos/3d/assets/Mesh.cpp @@ -601,8 +601,6 @@ bool Mesh::merge(Mesh *mesh, const Mat4 *worldMatrix /* = nullptr */, bool valid // merge vertex buffer uint32_t vertCount = 0; uint32_t vertStride = 0; - uint32_t srcOffset = 0; - uint32_t dstOffset = 0; uint32_t srcAttrOffset = 0; uint32_t srcVBOffset = 0; @@ -620,18 +618,14 @@ bool Mesh::merge(Mesh *mesh, const Mat4 *worldMatrix /* = nullptr */, bool valid const auto &bundle = _struct.vertexBundles[i]; auto &dstBundle = mesh->_struct.vertexBundles[i]; - srcOffset = bundle.view.offset; - dstOffset = dstBundle.view.offset; vertStride = bundle.view.stride; vertCount = bundle.view.count + dstBundle.view.count; auto *vb = ccnew ArrayBuffer(vertCount * vertStride); Uint8Array vbView(vb); - Uint8Array srcVBView = _data.subarray(srcOffset, srcOffset + bundle.view.length); - srcOffset += srcVBView.length(); - Uint8Array dstVBView = mesh->_data.subarray(dstOffset, dstOffset + dstBundle.view.length); - dstOffset += dstVBView.length(); + Uint8Array srcVBView = _data.subarray(bundle.view.offset, bundle.view.offset + bundle.view.length); + Uint8Array dstVBView = mesh->_data.subarray(dstBundle.view.offset, dstBundle.view.offset + dstBundle.view.length); vbView.set(srcVBView); @@ -705,9 +699,6 @@ bool Mesh::merge(Mesh *mesh, const Mat4 *worldMatrix /* = nullptr */, bool valid idxCount = prim.indexView.value().count; idxCount += dstPrim.indexView.value().count; - srcOffset = prim.indexView.value().offset; - dstOffset = dstPrim.indexView.value().offset; - if (idxCount < 256) { idxStride = 1; } else if (idxCount < 65536) { @@ -732,11 +723,11 @@ bool Mesh::merge(Mesh *mesh, const Mat4 *worldMatrix /* = nullptr */, bool valid // merge src indices if (prim.indexView.value().stride == 2) { - srcIBView = Uint16Array(_data.buffer(), srcOffset, prim.indexView.value().count); + srcIBView = Uint16Array(_data.buffer(), prim.indexView.value().offset, prim.indexView.value().count); } else if (prim.indexView.value().stride == 1) { - srcIBView = Uint8Array(_data.buffer(), srcOffset, prim.indexView.value().count); + srcIBView = Uint8Array(_data.buffer(), prim.indexView.value().offset, prim.indexView.value().count); } else { // Uint32 - srcIBView = Uint32Array(_data.buffer(), srcOffset, prim.indexView.value().count); + srcIBView = Uint32Array(_data.buffer(), prim.indexView.value().offset, prim.indexView.value().count); } // if (idxStride == prim.indexView.value().stride) { @@ -762,16 +753,15 @@ bool Mesh::merge(Mesh *mesh, const Mat4 *worldMatrix /* = nullptr */, bool valid } } } - srcOffset += prim.indexView.value().length; // merge dst indices uint32_t indexViewStride = dstPrim.indexView.value().stride; if (indexViewStride == 2) { - dstIBView = Uint16Array(mesh->_data.buffer(), dstOffset, dstPrim.indexView->count); + dstIBView = Uint16Array(mesh->_data.buffer(), dstPrim.indexView.value().offset, dstPrim.indexView->count); } else if (indexViewStride == 1) { - dstIBView = Uint8Array(mesh->_data.buffer(), dstOffset, dstPrim.indexView->count); + dstIBView = Uint8Array(mesh->_data.buffer(), dstPrim.indexView.value().offset, dstPrim.indexView->count); } else { // Uint32 - dstIBView = Uint32Array(mesh->_data.buffer(), dstOffset, dstPrim.indexView->count); + dstIBView = Uint32Array(mesh->_data.buffer(), dstPrim.indexView.value().offset, dstPrim.indexView->count); } for (uint32_t n = 0; n < dstPrim.indexView.value().count; ++n) { if (idxStride == 2) { @@ -785,7 +775,6 @@ bool Mesh::merge(Mesh *mesh, const Mat4 *worldMatrix /* = nullptr */, bool valid vertBatchCount + getTypedArrayValue(dstIBView, n); } } - dstOffset += dstPrim.indexView.value().length; IBufferView indexView; indexView.offset = bufferBlob.getLength(); diff --git a/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp b/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp index 94e24ce32e..494de05183 100644 --- a/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp +++ b/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp @@ -438,14 +438,11 @@ void ScriptEngine::onPromiseRejectCallback(v8::PromiseRejectMessage msg) { ss << stackStr << std::endl; } //Check event immediately, for certain case throw exception. - const char *eventName; switch (event) { case v8::kPromiseRejectWithNoHandler: - eventName = "unhandledRejectedPromise"; getInstance()->pushPromiseExeception(msg.GetPromise(), "unhandledRejectedPromise", ss.str().c_str()); break; case v8::kPromiseHandlerAddedAfterReject: - eventName = "handlerAddedAfterPromiseRejected"; getInstance()->pushPromiseExeception(msg.GetPromise(), "handlerAddedAfterPromiseRejected", ss.str().c_str()); break; case v8::kPromiseRejectAfterResolved: diff --git a/native/cocos/bindings/manual/jsb_scene_manual.cpp b/native/cocos/bindings/manual/jsb_scene_manual.cpp index 6808cd2a4c..ac9b572c18 100644 --- a/native/cocos/bindings/manual/jsb_scene_manual.cpp +++ b/native/cocos/bindings/manual/jsb_scene_manual.cpp @@ -622,7 +622,6 @@ static bool js_Model_setInstancedAttribute(se::State &s) // NOLINT(readability-i SE_PRECONDITION2(cobj, false, "Invalid Native Object"); const auto &args = s.args(); size_t argc = args.size(); - auto *thiz = s.thisObject(); CC_UNUSED bool ok = true; if (argc == 2) { ccstd::string name; diff --git a/native/cocos/core/Root.cpp b/native/cocos/core/Root.cpp index 819b1bffbc..8a726c3ed1 100644 --- a/native/cocos/core/Root.cpp +++ b/native/cocos/core/Root.cpp @@ -221,7 +221,7 @@ bool Root::setRenderPipeline(pipeline::RenderPipeline *rppl /* = nullptr*/) { if (!_pipeline->activate(_mainWindow->getSwapchain())) { if (isCreateDefaultPipeline) { - CC_SAFE_DESTROY_AND_DELETE(_pipeline); + CC_SAFE_DESTROY(_pipeline); } _pipeline = nullptr; diff --git a/native/cocos/editor-support/dragonbones-creator-support/CCFactory.cpp b/native/cocos/editor-support/dragonbones-creator-support/CCFactory.cpp index 71c199f928..f656c7a082 100644 --- a/native/cocos/editor-support/dragonbones-creator-support/CCFactory.cpp +++ b/native/cocos/editor-support/dragonbones-creator-support/CCFactory.cpp @@ -95,11 +95,9 @@ DragonBonesData *CCFactory::loadDragonBonesData(const std::string &filePath, con } else { cc::Data cocos2dData; cc::FileUtils::getInstance()->getContents(fullpath, &cocos2dData); - const auto binary = (unsigned char *)malloc(sizeof(unsigned char) * cocos2dData.getSize()); - memcpy(binary, cocos2dData.getBytes(), cocos2dData.getSize()); - const auto data = parseDragonBonesData((char *)binary, name, scale); - - return data; + uint8_t *binary = cocos2dData.takeBuffer(); + // NOTE: binary is freed in DragonBonesData::_onClear + return parseDragonBonesData(reinterpret_cast(binary), name, scale); } } @@ -120,10 +118,9 @@ DragonBonesData *CCFactory::parseDragonBonesDataByPath(const std::string &filePa if (cc::FileUtils::getInstance()->isFileExist(filePath)) { cc::Data cocos2dData; cc::FileUtils::getInstance()->getContents(fullpath, &cocos2dData); - const auto binary = (unsigned char *)malloc(sizeof(unsigned char) * cocos2dData.getSize()); - memcpy(binary, cocos2dData.getBytes(), cocos2dData.getSize()); - - return parseDragonBonesData((char *)binary, name, scale); + uint8_t *binary = cocos2dData.takeBuffer(); + // NOTE: binary is freed in DragonBonesData::_onClear + return parseDragonBonesData(reinterpret_cast(binary), name, scale); } } else { return parseDragonBonesData(filePath.c_str(), name, scale); diff --git a/native/cocos/editor-support/dragonbones/animation/TimelineState.h b/native/cocos/editor-support/dragonbones/animation/TimelineState.h index 14213056c5..60f4382892 100644 --- a/native/cocos/editor-support/dragonbones/animation/TimelineState.h +++ b/native/cocos/editor-support/dragonbones/animation/TimelineState.h @@ -128,9 +128,9 @@ public: ~SlotColorTimelineState() { _onClear(); - delete _current; - delete _delta; - delete _result; + delete[] _current; + delete[] _delta; + delete[] _result; } protected: diff --git a/native/cocos/editor-support/dragonbones/model/DragonBonesData.cpp b/native/cocos/editor-support/dragonbones/model/DragonBonesData.cpp index 8be62eb83a..8257331d31 100644 --- a/native/cocos/editor-support/dragonbones/model/DragonBonesData.cpp +++ b/native/cocos/editor-support/dragonbones/model/DragonBonesData.cpp @@ -10,11 +10,13 @@ void DragonBonesData::_onClear() { } if (binary != nullptr) { - delete binary; + free(const_cast(binary)); + binary = nullptr; } if (userData != nullptr) { userData->returnToPool(); + userData = nullptr; } autoSearch = false; @@ -25,14 +27,13 @@ void DragonBonesData::_onClear() { cachedFrames.clear(); armatureNames.clear(); armatures.clear(); - binary = nullptr; + intArray = nullptr; floatArray = nullptr; frameIntArray = nullptr; frameFloatArray = nullptr; frameArray = nullptr; timelineArray = nullptr; - userData = nullptr; } void DragonBonesData::addArmature(ArmatureData* value) { diff --git a/native/cocos/editor-support/dragonbones/parser/JSONDataParser.cpp b/native/cocos/editor-support/dragonbones/parser/JSONDataParser.cpp index 822d6991ac..4a4d0cf702 100644 --- a/native/cocos/editor-support/dragonbones/parser/JSONDataParser.cpp +++ b/native/cocos/editor-support/dragonbones/parser/JSONDataParser.cpp @@ -1598,7 +1598,8 @@ DragonBonesData *JSONDataParser::_parseDragonBonesData(const rapidjson::Value &r const auto l5 = _frameArray.size() * 2; const auto l6 = _timelineArray.size() * 2; - auto binary = new char[l1 + l2 + l3 + l4 + l5 + l6]; + // NOTE: binary is freed in DragonBonesData::_onClear + char* binary = static_cast(malloc((l1 + l2 + l3 + l4 + l5 + l6) * sizeof(char))); auto intArray = (int16_t *)binary; auto floatArray = (float *)(binary + l1); auto frameIntArray = (int16_t *)(binary + l1 + l2); diff --git a/native/cocos/platform/apple/JsbBridgeWrapper.mm b/native/cocos/platform/apple/JsbBridgeWrapper.mm index 9e814d3e30..4d4b8e9135 100644 --- a/native/cocos/platform/apple/JsbBridgeWrapper.mm +++ b/native/cocos/platform/apple/JsbBridgeWrapper.mm @@ -57,7 +57,9 @@ static ICallback cb = ^void(NSString* _event, NSString* _arg) { - (void)addScriptEventListener:(NSString*)eventName listener:(OnScriptEventListener)listener { if (![cbDictionnary objectForKey:eventName]) { - [cbDictionnary setValue:[NSMutableArray new] forKey:eventName]; + NSMutableArray *newArr = [[NSMutableArray alloc] init]; + [cbDictionnary setValue:newArr forKey:eventName]; + [newArr release]; } NSMutableArray* arr = [cbDictionnary objectForKey:eventName]; if (![arr containsObject:listener]) { diff --git a/native/cocos/platform/mac/AppDelegate.mm b/native/cocos/platform/mac/AppDelegate.mm index 1b481e87de..4160ee49e9 100644 --- a/native/cocos/platform/mac/AppDelegate.mm +++ b/native/cocos/platform/mac/AppDelegate.mm @@ -57,6 +57,9 @@ ViewController* viewController = [[ViewController alloc] initWithSize:rect]; _window.contentViewController = viewController; _window.contentView = viewController.view; + [viewController release]; + viewController = nil; + [_window.contentView setWantsBestResolutionOpenGLSurface:YES]; [_window makeKeyAndOrderFront:nil]; [[NSNotificationCenter defaultCenter] addObserver:self diff --git a/native/cocos/renderer/gfx-metal/MTLShader.mm b/native/cocos/renderer/gfx-metal/MTLShader.mm index 6a85807821..33ae651d70 100644 --- a/native/cocos/renderer/gfx-metal/MTLShader.mm +++ b/native/cocos/renderer/gfx-metal/MTLShader.mm @@ -149,7 +149,6 @@ bool CCMTLShader::createMTLFunction(const ShaderStage& stage) { size_t unitSize = sizeof(std::remove_pointer::type); ccstd::string mtlShaderSrc = mu::spirv2MSL(spirv->getOutputData(), spirv->getOutputSize() / unitSize, stage.stage, _gpuShader); - NSString* rawSrc = [NSString stringWithUTF8String:stage.source.c_str()]; NSString* shader = [NSString stringWithUTF8String:mtlShaderSrc.c_str()]; NSError* error = nil; MTLCompileOptions* opts = [[MTLCompileOptions alloc] init]; @@ -163,12 +162,14 @@ bool CCMTLShader::createMTLFunction(const ShaderStage& stage) { if (!library) { CC_LOG_ERROR("Can not compile %s shader: %s", shaderStage.c_str(), [[error localizedDescription] UTF8String]); CC_LOG_ERROR("%s", stage.source.c_str()); + [opts release]; return false; } } else { //delayed instance and pretend tobe specialized function. _gpuShader->specializeColor = false; _gpuShader->shaderSrc = [shader retain]; + [opts release]; CC_ASSERT(_gpuShader->shaderSrc != nil); return true; } @@ -177,6 +178,7 @@ bool CCMTLShader::createMTLFunction(const ShaderStage& stage) { if (!library) { CC_LOG_ERROR("Can not compile %s shader: %s", shaderStage.c_str(), [[error localizedDescription] UTF8String]); CC_LOG_ERROR("%s", stage.source.c_str()); + [opts release]; return false; } } diff --git a/native/cocos/renderer/pipeline/SceneCulling.cpp b/native/cocos/renderer/pipeline/SceneCulling.cpp index e2b0c54989..31aae24490 100644 --- a/native/cocos/renderer/pipeline/SceneCulling.cpp +++ b/native/cocos/renderer/pipeline/SceneCulling.cpp @@ -272,7 +272,7 @@ void sceneCulling(const RenderPipeline* pipeline, scene::Camera* camera) { (visibility & static_cast(model->getVisFlags()))) { const auto *modelWorldBounds = model->getWorldBounds(); - if (!modelWorldBounds && skyBox->getModel() != model) { + if (!modelWorldBounds && (skyBox == nullptr || skyBox->getModel() != model)) { sceneData->addRenderObject(genRenderObject(model, camera)); } }