diff --git a/native/cocos/application/CocosApplication.cpp b/native/cocos/application/CocosApplication.cpp index 53dea7afbf..4a285bcd66 100644 --- a/native/cocos/application/CocosApplication.cpp +++ b/native/cocos/application/CocosApplication.cpp @@ -54,6 +54,9 @@ int CocosApplication::init() { if (_engine->init()) { return -1; } + _engine->on(BaseEngine::ON_START, [this]() { + this->onStart(); + }); _engine->on(BaseEngine::ON_RESUME, [this]() { this->onResume(); @@ -112,6 +115,10 @@ BaseEngine::Ptr CocosApplication::getEngine() const { return _engine; } +void CocosApplication::onStart() { + // TODO(cc): Handling engine start events +} + void CocosApplication::onPause() { // TODO(cc): Handling pause events } diff --git a/native/cocos/application/CocosApplication.h b/native/cocos/application/CocosApplication.h index df961ab6b0..14a948a546 100644 --- a/native/cocos/application/CocosApplication.h +++ b/native/cocos/application/CocosApplication.h @@ -66,6 +66,10 @@ public: */ BaseEngine::Ptr getEngine() const override; + /** + * @brief Processing engine start events. + */ + virtual void onStart(); /** * @brief Processing pause events.. */ diff --git a/native/cocos/engine/Engine.cpp b/native/cocos/engine/Engine.cpp index ef66aa7236..81f4485a85 100644 --- a/native/cocos/engine/Engine.cpp +++ b/native/cocos/engine/Engine.cpp @@ -96,10 +96,15 @@ bool setCanvasCallback(se::Object * /*global*/) { namespace cc { -Engine::Engine() = default; +Engine::Engine() { + _scriptEngine = ccnew se::ScriptEngine(); +} Engine::~Engine() { destroy(); + + delete _scriptEngine; + _scriptEngine = nullptr; } int32_t Engine::init() { @@ -118,7 +123,6 @@ int32_t Engine::init() { _profiler = ccnew Profiler(); #endif - _scriptEngine = ccnew se::ScriptEngine(); EventDispatcher::init(); BasePlatform *platform = BasePlatform::getPlatform(); @@ -148,7 +152,9 @@ void Engine::destroy() { // Should delete it before deleting DeviceManager as ScriptEngine will check gpu resource usage, // and ScriptEngine will hold gfx objects. - delete _scriptEngine; + // Because the user registration interface needs to be added during initialization. + // ScriptEngine cannot be released here. + _scriptEngine->cleanup(); #if CC_USE_PROFILER delete _profiler; @@ -223,8 +229,6 @@ void Engine::close() { // NOLINT _scheduler->removeAllFunctionsToBePerformedInCocosThread(); _scheduler->unscheduleAll(); BasePlatform::getPlatform()->setHandleEventCallback(nullptr); - - } uint Engine::getTotalFrames() const {