From cb1234b63a4b34e1d22c2cef87e17e0778129a69 Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 21 Apr 2022 13:52:20 +0800 Subject: [PATCH] Revert "fix memory leak (#10804)" (#10823) This reverts commit 3374c7e41c6f5e3496df6add74c6fb40943754f7. --- .../cocos/application/ApplicationManager.cpp | 15 +----- native/cocos/application/ApplicationManager.h | 7 +-- native/cocos/base/Scheduler.cpp | 2 +- native/cocos/base/memory/CallStack.h | 2 +- native/cocos/base/memory/MemoryHook.cpp | 54 ++----------------- native/cocos/base/memory/MemoryHook.h | 6 +-- .../bindings/jswrapper/v8/ScriptEngine.cpp | 9 +--- .../cocos/bindings/manual/jsb_global_init.cpp | 18 +++---- native/cocos/core/Root.cpp | 3 ++ native/cocos/core/geometry/Frustum.h | 5 ++ native/cocos/engine/Engine.cpp | 45 ++++++++-------- native/cocos/platform/UniversalPlatform.cpp | 14 +++-- .../cocos/platform/win32/WindowsPlatform.cpp | 2 +- .../renderer/gfx-gles2/GLES2GPUContext.cpp | 2 - .../renderer/gfx-gles2/GLES2Wrangler.cpp | 35 ------------ .../cocos/renderer/gfx-gles2/GLES2Wrangler.h | 3 +- .../renderer/gfx-gles3/GLES3GPUContext.cpp | 2 - .../renderer/gfx-gles3/GLES3Wrangler.cpp | 35 ------------ .../cocos/renderer/gfx-gles3/GLES3Wrangler.h | 3 +- native/cocos/renderer/pipeline/RenderFlow.cpp | 5 +- .../renderer/pipeline/RenderPipeline.cpp | 2 +- .../cocos/renderer/pipeline/SceneCulling.cpp | 3 +- native/cocos/scene/Camera.cpp | 10 ++-- 23 files changed, 68 insertions(+), 214 deletions(-) diff --git a/native/cocos/application/ApplicationManager.cpp b/native/cocos/application/ApplicationManager.cpp index 4b09498083..0cc78e62b1 100644 --- a/native/cocos/application/ApplicationManager.cpp +++ b/native/cocos/application/ApplicationManager.cpp @@ -33,12 +33,6 @@ ApplicationManager *ApplicationManager::getInstance() { return &mgr; } -void ApplicationManager::closeAllApplications() { - for (auto &app : _apps) { - app->close(); - } -} - void ApplicationManager::releseAllApplications() { _apps.clear(); } @@ -56,14 +50,9 @@ ApplicationManager::ApplicationPtr ApplicationManager::getCurrentAppSafe() const } } // namespace cc -void cocos_close() { // NOLINT(readability-identifier-naming) - // Called in the platform layer, because the platform layer is isolated from the application layer - // It is the platform layer to drive applications and reclaim resources. - cc::ApplicationManager::getInstance()->closeAllApplications(); -} - +// void cocos_destory() { // NOLINT(readability-identifier-naming) // Called in the platform layer, because the platform layer is isolated from the application layer // It is the platform layer to drive applications and reclaim resources. cc::ApplicationManager::getInstance()->releseAllApplications(); -} +} \ No newline at end of file diff --git a/native/cocos/application/ApplicationManager.h b/native/cocos/application/ApplicationManager.h index 5801d7d1f9..7a12ed4e5e 100644 --- a/native/cocos/application/ApplicationManager.h +++ b/native/cocos/application/ApplicationManager.h @@ -48,11 +48,6 @@ public: return app; } - /** - * @brief close all generated applications before being destroyed. - */ - void closeAllApplications(); - /** * @brief Release all generated applications. */ @@ -92,6 +87,6 @@ private: } while (0) #define CC_REGISTER_APPLICATION(className) \ - int cocos_main(int argc, const char **argv) { \ + int cocos_main(int argc, const char** argv) { \ CC_START_APPLICATION(className); \ } diff --git a/native/cocos/base/Scheduler.cpp b/native/cocos/base/Scheduler.cpp index 58ed32ae87..4af2bf8946 100644 --- a/native/cocos/base/Scheduler.cpp +++ b/native/cocos/base/Scheduler.cpp @@ -140,7 +140,7 @@ void Scheduler::removeHashElement(HashTimerEntry *element) { element->timers.clear(); _hashForTimers.erase(element->target); - delete element; + free(element); } } diff --git a/native/cocos/base/memory/CallStack.h b/native/cocos/base/memory/CallStack.h index 4b06a55557..1c1276b969 100644 --- a/native/cocos/base/memory/CallStack.h +++ b/native/cocos/base/memory/CallStack.h @@ -38,7 +38,7 @@ namespace cc { - #define MAX_STACK_FRAMES 64 + #define MAX_STACK_FRAMES 32 #define MAX_SYMBOL_LENGTH 255 /** diff --git a/native/cocos/base/memory/MemoryHook.cpp b/native/cocos/base/memory/MemoryHook.cpp index 7a3a52d597..840e0cca41 100644 --- a/native/cocos/base/memory/MemoryHook.cpp +++ b/native/cocos/base/memory/MemoryHook.cpp @@ -190,34 +190,6 @@ void MemoryHook::removeRecord(uint64_t address) { _hooking = false; } -static bool isIgnored(const StackFrame &frame) { - static const ccstd::vector ignoreModules = { - "SDL2", - "SogouPy"}; - - static const ccstd::vector ignoreFunctions = { - "eglGetProcAddress", - "eglWaitSync", - "gles3wOpen", - "gles2wOpen", - "type_info::name", - "DrvValidateVersion"}; - - for (auto &module : ignoreModules) { - if (frame.module.find(module) != ccstd::string::npos) { - return true; - } - } - - for (auto &function : ignoreFunctions) { - if (frame.function.find(function) != ccstd::string::npos) { - return true; - } - } - - return false; -} - void MemoryHook::dumpMemoryLeak() { std::lock_guard lock(_mutex); #if CC_PLATFORM == CC_PLATFORM_WINDOWS @@ -238,26 +210,8 @@ void MemoryHook::dumpMemoryLeak() { log(stream.str()); } - uint32_t i = 0; - size_t skipSize = 0; - uint32_t skipCount = 0; - + int i = 0; for (const auto &iter : _records) { - bool skip = false; - auto frames = CallStack::backtraceSymbols(iter.second.callstack); - for (auto &frame : frames) { - if (isIgnored(frame)) { - skip = true; - break; - } - } - - if (skip) { - skipSize += iter.second.size; - skipCount++; - continue; - } - std::stringstream stream; int k = 0; @@ -265,7 +219,7 @@ void MemoryHook::dumpMemoryLeak() { stream << "<" << ++i << ">:" << "leak " << iter.second.size << " bytes at 0x" << std::hex << iter.second.address << std::dec << std::endl; stream << "\tcallstack:" << std::endl; - + auto frames = CallStack::backtraceSymbols(iter.second.callstack); for (auto &frame : frames) { stream << "\t[" << ++k << "]:" << frame.toString() << std::endl; } @@ -275,9 +229,7 @@ void MemoryHook::dumpMemoryLeak() { std::stringstream endStream; endStream << std::endl - << "Total leak count: " << _records.size() << " with " << _totalSize << " bytes, " - << "Total skip count: " << skipCount << " with " << skipSize << " bytes" << std::endl; - + << "Total Leak: " << _totalSize << " bytes" << std::endl; endStream << "---------------------------------------------------------------------------------------------------------" << std::endl; endStream << "--------------------------------------memory leak report end---------------------------------------------" << std::endl; endStream << "---------------------------------------------------------------------------------------------------------" << std::endl; diff --git a/native/cocos/base/memory/MemoryHook.h b/native/cocos/base/memory/MemoryHook.h index 4b1f715b47..7be9a2da3c 100644 --- a/native/cocos/base/memory/MemoryHook.h +++ b/native/cocos/base/memory/MemoryHook.h @@ -58,9 +58,9 @@ public: */ using RecordMap = ccstd::unordered_map; - void addRecord(uint64_t address, size_t size); - void removeRecord(uint64_t address); - inline size_t getTotalSize() const { return _totalSize; } + void addRecord(uint64_t address, size_t size); + void removeRecord(uint64_t address); + size_t getTotalSize() const { return _totalSize; } private: /** diff --git a/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp b/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp index 033dbca5fb..1390d48570 100644 --- a/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp +++ b/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp @@ -509,14 +509,7 @@ ScriptEngine::ScriptEngine() #endif } -ScriptEngine::~ScriptEngine() { - #if !CC_EDITOR - if (gSharedV8) { - delete gSharedV8; - gSharedV8 = nullptr; - } - #endif -} +ScriptEngine::~ScriptEngine() = default; bool ScriptEngine::postInit() { v8::HandleScope hs(_isolate); diff --git a/native/cocos/bindings/manual/jsb_global_init.cpp b/native/cocos/bindings/manual/jsb_global_init.cpp index bc1ec2078f..915ef6eef5 100644 --- a/native/cocos/bindings/manual/jsb_global_init.cpp +++ b/native/cocos/bindings/manual/jsb_global_init.cpp @@ -66,22 +66,18 @@ static ccstd::string removeFileExt(const ccstd::string &filePath) { return filePath; } -static void walkCb(uv_handle_t *handle, void * /*arg*/) { - uv_close(handle, nullptr); -} - static int selectPort(int port) { struct sockaddr_in addr; static uv_tcp_t server; - uv_loop_t loop; - uv_loop_init(&loop); - int tryTimes = 200; - int startPort = port; + uv_loop_t * loop = uv_loop_new(); + int tryTimes = 200; + int startPort = port; while (tryTimes-- > 0) { - uv_tcp_init(&loop, &server); + uv_tcp_init(loop, &server); uv_ip4_addr("0.0.0.0", startPort, &addr); uv_tcp_bind(&server, reinterpret_cast(&addr), 0); int r = uv_listen(reinterpret_cast(&server), 5, nullptr); + uv_close(reinterpret_cast(&server), nullptr); if (r) { SE_LOGD("Failed to listen port %d, error: %s. Try next port\n", startPort, uv_strerror(r)); startPort += 1; @@ -89,9 +85,7 @@ static int selectPort(int port) { break; } } - uv_walk(&loop, walkCb, nullptr); - uv_run(&loop, UV_RUN_DEFAULT); - uv_loop_close(&loop); + uv_loop_close(loop); return startPort; } diff --git a/native/cocos/core/Root.cpp b/native/cocos/core/Root.cpp index 5764c6f712..d7db7049b1 100644 --- a/native/cocos/core/Root.cpp +++ b/native/cocos/core/Root.cpp @@ -57,6 +57,8 @@ Root::Root(gfx::Device *device) _eventProcessor = new CallbacksInvoker(); // TODO(minggo): // this._dataPoolMgr = legacyCC.internal.DataPoolManager && new legacyCC.internal.DataPoolManager(device) as DataPoolManager; + _cameraPool = new memop::Pool([this]() { return new scene::Camera(_device); }, + 4); _cameraList.reserve(6); _swapchains.reserve(2); @@ -64,6 +66,7 @@ Root::Root(gfx::Device *device) Root::~Root() { instance = nullptr; + delete _cameraPool; CC_SAFE_DELETE(_eventProcessor); } diff --git a/native/cocos/core/geometry/Frustum.h b/native/cocos/core/geometry/Frustum.h index 1f6fa3895d..d87857877f 100644 --- a/native/cocos/core/geometry/Frustum.h +++ b/native/cocos/core/geometry/Frustum.h @@ -154,6 +154,11 @@ public: void split(float start, float end, float aspect, float fov, const Mat4 &transform); void updatePlanes(); void update(const Mat4 &m, const Mat4 &inv); + Frustum clone() const { + Frustum tmp; + copy(&tmp, *this); + return tmp; + } }; } // namespace geometry diff --git a/native/cocos/engine/Engine.cpp b/native/cocos/engine/Engine.cpp index f54a560dfd..253dbfcf71 100644 --- a/native/cocos/engine/Engine.cpp +++ b/native/cocos/engine/Engine.cpp @@ -44,12 +44,6 @@ #if CC_USE_SOCKET #include "cocos/network/WebSocket.h" #endif -#if CC_USE_DRAGONBONES - #include "editor-support/dragonbones-creator-support/ArmatureCacheMgr.h" -#endif -#if CC_USE_SPINE - #include "editor-support/spine-creator-support/SkeletonCacheMgr.h" -#endif #include "application/ApplicationManager.h" #include "application/BaseApplication.h" @@ -106,28 +100,22 @@ Engine::~Engine() { AudioEngine::end(); #endif -#if CC_USE_DRAGONBONES - dragonBones::ArmatureCacheMgr::destroyInstance(); -#endif + Root::getInstance()->getPipeline()->destroy(); -#if CC_USE_SPINE - spine::SkeletonCacheMgr::destroyInstance(); -#endif - network::HttpClient::destroyInstance(); EventDispatcher::destroy(); + se::ScriptEngine::destroyInstance(); ProgramLib::destroyInstance(); BuiltinResMgr::destroyInstance(); - Root::getInstance()->getPipeline()->destroy(); + gfx::DeviceManager::destroy(); + + CCObject::deferredDestroy(); + + BasePlatform *platform = BasePlatform::getPlatform(); + platform->setHandleEventCallback(nullptr); + CC_PROFILER_DESTROY; DebugRenderer::destroyInstance(); FreeTypeFontFace::destroyFreeType(); - cc::EventDispatcher::destroy(); - FileUtils::destroyInstance(); - - se::ScriptEngine::getInstance()->cleanup(); - se::ScriptEngine::destroyInstance(); - gfx::DeviceManager::destroy(); - CCObject::deferredDestroy(); } int32_t Engine::init() { @@ -166,6 +154,12 @@ int Engine::restart() { } void Engine::close() { // NOLINT + if (cc::EventDispatcher::initialized()) { + cc::EventDispatcher::dispatchCloseEvent(); + } + + auto *scriptEngine = se::ScriptEngine::getInstance(); + cc::DeferredReleasePool::clear(); #if CC_USE_AUDIO cc::AudioEngine::stopAll(); @@ -173,11 +167,16 @@ void Engine::close() { // NOLINT //#if CC_USE_SOCKET // cc::network::WebSocket::closeAllConnections(); //#endif + cc::network::HttpClient::destroyInstance(); + _scheduler->removeAllFunctionsToBePerformedInCocosThread(); _scheduler->unscheduleAll(); - BasePlatform *platform = BasePlatform::getPlatform(); - platform->setHandleEventCallback(nullptr); + scriptEngine->cleanup(); + cc::EventDispatcher::destroy(); + + // exit + exit(0); } uint Engine::getTotalFrames() const { diff --git a/native/cocos/platform/UniversalPlatform.cpp b/native/cocos/platform/UniversalPlatform.cpp index 5907619277..fb7e805320 100644 --- a/native/cocos/platform/UniversalPlatform.cpp +++ b/native/cocos/platform/UniversalPlatform.cpp @@ -27,8 +27,7 @@ #include "platform/interfaces/OSInterface.h" -extern int cocos_main(int argc, const char **argv); // NOLINT(readability-identifier-naming) -extern void cocos_close(); // NOLINT(readability-identifier-naming) +extern int cocos_main(int argc, const char** argv); // NOLINT(readability-identifier-naming) extern void cocos_destory(); // NOLINT(readability-identifier-naming) namespace cc { @@ -36,7 +35,7 @@ UniversalPlatform::OSType UniversalPlatform::getOSType() const { return getInterface()->getOSType(); } -void UniversalPlatform::dispatchEvent(const OSEvent &ev) { +void UniversalPlatform::dispatchEvent(const OSEvent& ev) { bool isHandled = false; if (_handleEventCallback) { isHandled = (_handleEventCallback)(ev); @@ -52,10 +51,10 @@ void UniversalPlatform::dispatchEvent(const OSEvent &ev) { } } -void UniversalPlatform::dispatchTouchEvent(const OSEvent &ev) { +void UniversalPlatform::dispatchTouchEvent(const OSEvent& ev) { } -void UniversalPlatform::handleDefaultEvent(const OSEvent &ev) { +void UniversalPlatform::handleDefaultEvent(const OSEvent& ev) { // TODO(cc) : Follow-up support } @@ -67,7 +66,7 @@ void UniversalPlatform::setHandleDefaultEventCallback(HandleEventCallback cb) { _handleDefaultEventCallback = cb; } -int32_t UniversalPlatform::run(int argc, const char **argv) { +int32_t UniversalPlatform::run(int argc, const char** argv) { if (cocos_main(argc, argv) != 0) { return -1; } @@ -78,7 +77,7 @@ int UniversalPlatform::getSdkVersion() const { return 0; } -void UniversalPlatform::runInPlatformThread(const ThreadCallback &task) { +void UniversalPlatform::runInPlatformThread(const ThreadCallback& task) { _mainTask = task; } @@ -106,7 +105,6 @@ void UniversalPlatform::onResume() { } void UniversalPlatform::onClose() { - cocos_close(); } void UniversalPlatform::onDestory() { diff --git a/native/cocos/platform/win32/WindowsPlatform.cpp b/native/cocos/platform/win32/WindowsPlatform.cpp index 4317ae3054..4ffda82553 100644 --- a/native/cocos/platform/win32/WindowsPlatform.cpp +++ b/native/cocos/platform/win32/WindowsPlatform.cpp @@ -80,6 +80,7 @@ namespace cc { WindowsPlatform::WindowsPlatform() { } WindowsPlatform::~WindowsPlatform() { + #ifdef USE_WIN32_CONSOLE FreeConsole(); #endif @@ -159,7 +160,6 @@ int32_t WindowsPlatform::loop() { if (wTimerRes != 0) timeEndPeriod(wTimerRes); - onClose(); onDestory(); return 0; } diff --git a/native/cocos/renderer/gfx-gles2/GLES2GPUContext.cpp b/native/cocos/renderer/gfx-gles2/GLES2GPUContext.cpp index 61e0b29ff6..e1ae6e4710 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2GPUContext.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2GPUContext.cpp @@ -271,8 +271,6 @@ void GLES2GPUContext::destroy() { EGL_CHECK(eglTerminate(eglDisplay)); eglDisplay = EGL_NO_DISPLAY; } - - gles2wExit(); } void GLES2GPUContext::bindContext(bool bound) { diff --git a/native/cocos/renderer/gfx-gles2/GLES2Wrangler.cpp b/native/cocos/renderer/gfx-gles2/GLES2Wrangler.cpp index 71770476e4..dc9919bf48 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Wrangler.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Wrangler.cpp @@ -38,21 +38,6 @@ bool gles2wOpen() { return (libegl && libgles); } -bool gles2wClose() { - bool ret = true; - if (libegl) { - ret &= FreeLibrary(libegl) ? true : false; - libegl = NULL; - } - - if (libgles) { - ret &= FreeLibrary(libgles) ? true : false; - libgles = NULL; - } - - return ret; -} - void *gles2wLoad(const char *proc) { void *res = nullptr; if (eglGetProcAddress) res = (void *)eglGetProcAddress(proc); @@ -61,7 +46,6 @@ void *gles2wLoad(const char *proc) { } #elif defined(__EMSCRIPTEN__) bool gles2wOpen() { return true; } -bool gles2wClose() { return true; } void *gles2wLoad(const char *proc) { return (void *)eglGetProcAddress(proc); } @@ -81,21 +65,6 @@ bool gles2wOpen() { return (libegl && libgles); } -bool gles2wClose() { - bool ret = true; - if (libegl) { - ret &= dlclose(libegl) == 0; - libegl = nullptr; - } - - if (libgles) { - ret &= dlclose(libgles) == 0; - libgles = nullptr; - } - - return ret; -} - void *gles2wLoad(const char *proc) { void *res = nullptr; if (eglGetProcAddress) res = reinterpret_cast(eglGetProcAddress(proc)); @@ -114,7 +83,3 @@ bool gles2wInit() { return true; } - -bool gles2wExit() { - return gles2wClose(); -} diff --git a/native/cocos/renderer/gfx-gles2/GLES2Wrangler.h b/native/cocos/renderer/gfx-gles2/GLES2Wrangler.h index d46bc2301b..7ac0a591c8 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Wrangler.h +++ b/native/cocos/renderer/gfx-gles2/GLES2Wrangler.h @@ -28,5 +28,4 @@ #include "../gfx-gles-common/eglw.h" #include "../gfx-gles-common/gles2w.h" -bool gles2wInit(); -bool gles2wExit(); +bool gles2wInit(); \ No newline at end of file diff --git a/native/cocos/renderer/gfx-gles3/GLES3GPUContext.cpp b/native/cocos/renderer/gfx-gles3/GLES3GPUContext.cpp index 7f376643ed..1c29dc849d 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3GPUContext.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3GPUContext.cpp @@ -279,8 +279,6 @@ void GLES3GPUContext::destroy() { EGL_CHECK(eglTerminate(eglDisplay)); eglDisplay = EGL_NO_DISPLAY; } - - gles3wExit(); } void GLES3GPUContext::bindContext(bool bound) { diff --git a/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp b/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp index 68f11291fa..aa7b32029d 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp @@ -38,21 +38,6 @@ bool gles3wOpen() { return (libegl && libgles); } -bool gles3wClose() { - bool ret = true; - if (libegl) { - ret &= FreeLibrary(libegl) ? true : false; - libegl = NULL; - } - - if (libgles) { - ret &= FreeLibrary(libgles) ? true : false; - libgles = NULL; - } - - return ret; -} - void *gles3wLoad(const char *proc) { void *res = nullptr; if (eglGetProcAddress) res = (void *)eglGetProcAddress(proc); @@ -61,7 +46,6 @@ void *gles3wLoad(const char *proc) { } #elif defined(__EMSCRIPTEN__) bool gles3wOpen() { return true; } -bool gles3wClose() { return true; } void *gles3wLoad(const char *proc) { return (void *)eglGetProcAddress(proc); } @@ -81,21 +65,6 @@ bool gles3wOpen() { return (libegl && libgles); } -bool gles3wClose() { - bool ret = true; - if (libegl) { - ret &= dlclose(libegl) == 0; - libegl = nullptr; - } - - if (libgles) { - ret &= dlclose(libgles) == 0; - libgles = nullptr; - } - - return ret; -} - void *gles3wLoad(const char *proc) { void *res = nullptr; if (eglGetProcAddress) res = reinterpret_cast(eglGetProcAddress(proc)); @@ -115,7 +84,3 @@ bool gles3wInit() { return true; } - -bool gles3wExit() { - return gles3wClose(); -} diff --git a/native/cocos/renderer/gfx-gles3/GLES3Wrangler.h b/native/cocos/renderer/gfx-gles3/GLES3Wrangler.h index feb2c437d7..479024ebb9 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Wrangler.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Wrangler.h @@ -29,5 +29,4 @@ #include "../gfx-gles-common/gles2w.h" #include "../gfx-gles-common/gles3w.h" -bool gles3wInit(); -bool gles3wExit(); +bool gles3wInit(); \ No newline at end of file diff --git a/native/cocos/renderer/pipeline/RenderFlow.cpp b/native/cocos/renderer/pipeline/RenderFlow.cpp index 660e9cc0e4..2826d65e2c 100644 --- a/native/cocos/renderer/pipeline/RenderFlow.cpp +++ b/native/cocos/renderer/pipeline/RenderFlow.cpp @@ -26,7 +26,6 @@ #include "RenderFlow.h" #include #include "RenderStage.h" -#include "base/memory/Memory.h" namespace cc { namespace pipeline { @@ -62,8 +61,8 @@ void RenderFlow::render(scene::Camera *camera) { } void RenderFlow::destroy() { - for (auto *stage : _stages) { - CC_SAFE_DESTROY_AND_DELETE(stage); + for (auto *const stage : _stages) { + stage->destroy(); } _stages.clear(); diff --git a/native/cocos/renderer/pipeline/RenderPipeline.cpp b/native/cocos/renderer/pipeline/RenderPipeline.cpp index 68c53c499a..375209aeab 100644 --- a/native/cocos/renderer/pipeline/RenderPipeline.cpp +++ b/native/cocos/renderer/pipeline/RenderPipeline.cpp @@ -126,7 +126,7 @@ void RenderPipeline::destroyQuadInputAssembler() { bool RenderPipeline::destroy() { for (auto *flow : _flows) { - CC_SAFE_DESTROY_AND_DELETE(flow); + flow->destroy(); } _flows.clear(); diff --git a/native/cocos/renderer/pipeline/SceneCulling.cpp b/native/cocos/renderer/pipeline/SceneCulling.cpp index 64d99edb66..e4230ebbd4 100644 --- a/native/cocos/renderer/pipeline/SceneCulling.cpp +++ b/native/cocos/renderer/pipeline/SceneCulling.cpp @@ -254,8 +254,7 @@ void quantizeDirLightShadowCamera(RenderPipeline *pipeline, const scene::Camera geometry::Frustum validFrustum; validFrustum.setType(geometry::ShapeEnum::SHAPE_FRUSTUM_ACCURATE); validFrustum.split(0.1F, mainLight->getShadowDistance(), camera->getAspect(), camera->getFov(), matWorldTrans); - geometry::Frustum lightViewFrustum; - geometry::Frustum::copy(&lightViewFrustum, validFrustum); + geometry::Frustum lightViewFrustum = validFrustum.clone(); // view matrix with range back. Mat4 matShadowTrans; diff --git a/native/cocos/scene/Camera.cpp b/native/cocos/scene/Camera.cpp index c8eb5c6658..3c4b004cf7 100644 --- a/native/cocos/scene/Camera.cpp +++ b/native/cocos/scene/Camera.cpp @@ -85,7 +85,7 @@ Camera::Camera(gfx::Device *device) } Camera::~Camera() { - destroy(); + _frustum->release(); } bool Camera::initialize(const ICameraInfo &info) { @@ -105,8 +105,12 @@ bool Camera::initialize(const ICameraInfo &info) { } void Camera::destroy() { - CC_SAFE_DESTROY_NULL(_geometryRenderer); - _frustum->release(); + if (_window) { + _window->detachCamera(this); + _window = nullptr; + } + _name.clear(); + _geometryRenderer->destroy(); } void Camera::attachToScene(RenderScene *scene) {