Fix memory leaks refreshed (#1638)

* Fix memory leaks when axmol apps exit on non-embed systems

    1. DriverBase no destroyInstance
    2. Every object inherited from ax::Ref shoud destory before ScriptEngineManager, otherwise will trigger it's reinit and leak
    3.  QuadCommand always leak isolated indices
    4. static singleton should'nt inhert from ax::Ref due to destory it before ScriptEngineManager impossible
    5. Make Director don't inherit from ax::Ref due to it also cause ScriptEngineManager re-init, because we destroy ScriptEngineManger in destructor of Director
    6. Explicit Director managed by Application and don't delete self at purgeDirector, since it will release at mainLoop and re-init in glView->pollEvents then leak
    7. Rename ApplicationProtocol to ApplicationBase
    8. Rename purgeDirector since we don't delete director self at it, maye rename to cleanup
    9. Change ShaderCache to new/delete singleton, managed by ProgramManager

---------

Co-authored-by: lich426 <lich426@gmail.com>
This commit is contained in:
Deal 2024-01-29 22:30:14 +08:00 committed by GitHub
parent c06bed508b
commit 9774d4751c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
35 changed files with 162 additions and 60 deletions

View File

@ -4,6 +4,7 @@ Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2011 Zynga Inc. Copyright (c) 2011 Zynga Inc.
Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
https://axmolengine.github.io/ https://axmolengine.github.io/
@ -48,7 +49,7 @@ AnimationCache* AnimationCache::getInstance()
void AnimationCache::destroyInstance() void AnimationCache::destroyInstance()
{ {
AX_SAFE_RELEASE_NULL(s_sharedAnimationCache); AX_SAFE_DELETE(s_sharedAnimationCache);
} }
bool AnimationCache::init() bool AnimationCache::init()

View File

@ -4,6 +4,7 @@ Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2011 Zynga Inc. Copyright (c) 2011 Zynga Inc.
Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
https://axmolengine.github.io/ https://axmolengine.github.io/
@ -52,7 +53,7 @@ Before v0.99.5, the recommend way was to save them on the Sprite. Since v0.99.5,
@since v0.99.5 @since v0.99.5
@js cc.animationCache @js cc.animationCache
*/ */
class AX_DLL AnimationCache : public Ref class AX_DLL AnimationCache
{ {
public: public:
/** /**

View File

@ -239,7 +239,7 @@ public:
* Particle emission mask cache. * Particle emission mask cache.
* @since axmol-1.0.0b8 * @since axmol-1.0.0b8
*/ */
class AX_DLL ParticleEmissionMaskCache : public ax::Ref class AX_DLL ParticleEmissionMaskCache
{ {
public: public:
static ParticleEmissionMaskCache* getInstance(); static ParticleEmissionMaskCache* getInstance();

View File

@ -6,6 +6,7 @@ Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2011 Zynga Inc. Copyright (c) 2011 Zynga Inc.
Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
https://axmolengine.github.io/ https://axmolengine.github.io/
@ -60,7 +61,7 @@ SpriteFrameCache* SpriteFrameCache::getInstance()
void SpriteFrameCache::destroyInstance() void SpriteFrameCache::destroyInstance()
{ {
AX_SAFE_RELEASE_NULL(_sharedSpriteFrameCache); AX_SAFE_DELETE(_sharedSpriteFrameCache);
} }
bool SpriteFrameCache::init() bool SpriteFrameCache::init()

View File

@ -6,6 +6,7 @@ Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2011 Zynga Inc. Copyright (c) 2011 Zynga Inc.
Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
https://axmolengine.github.io/ https://axmolengine.github.io/
@ -88,7 +89,7 @@ class PolygonInfo;
@since v0.9 @since v0.9
@js cc.spriteFrameCache @js cc.spriteFrameCache
*/ */
class AX_DLL SpriteFrameCache : public Ref class AX_DLL SpriteFrameCache
{ {
public: public:
/** Returns the shared instance of the Sprite Frame cache. /** Returns the shared instance of the Sprite Frame cache.

View File

@ -181,7 +181,7 @@ Configuration* Configuration::getInstance()
void Configuration::destroyInstance() void Configuration::destroyInstance()
{ {
AX_SAFE_RELEASE_NULL(s_sharedConfiguration); AX_SAFE_DELETE(s_sharedConfiguration);
} }
// //

View File

@ -3,6 +3,7 @@ Copyright (c) 2010 Ricardo Quesada
Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
https://axmolengine.github.io/ https://axmolengine.github.io/
@ -47,7 +48,7 @@ class EventCustom;
* @since v0.99.0 * @since v0.99.0
* @js NA * @js NA
*/ */
class AX_DLL Configuration : public Ref class AX_DLL Configuration
{ {
public: public:
/** Returns a shared instance of Configuration. /** Returns a shared instance of Configuration.

View File

@ -90,7 +90,7 @@ Director* Director::getInstance()
{ {
if (!s_SharedDirector) if (!s_SharedDirector)
{ {
s_SharedDirector = new Director; s_SharedDirector = new Director();
AXASSERT(s_SharedDirector, "FATAL: Not enough memory"); AXASSERT(s_SharedDirector, "FATAL: Not enough memory");
s_SharedDirector->init(); s_SharedDirector->init();
} }
@ -98,6 +98,11 @@ Director* Director::getInstance()
return s_SharedDirector; return s_SharedDirector;
} }
void Director::destroyInstance()
{
AX_SAFE_DELETE(s_SharedDirector);
}
Director::Director() {} Director::Director() {}
bool Director::init() bool Director::init()
@ -193,9 +198,15 @@ Director::~Director()
s_SharedDirector = nullptr; s_SharedDirector = nullptr;
backend::DriverBase::destroyInstance();
QuadCommand::destroyIsolatedIndices();
#if AX_ENABLE_SCRIPT_BINDING #if AX_ENABLE_SCRIPT_BINDING
ScriptEngineManager::destroyInstance(); ScriptEngineManager::destroyInstance();
#endif #endif
/** clean auto release pool. */
PoolManager::destroyInstance();
} }
void Director::setDefaultValues() void Director::setDefaultValues()
@ -953,7 +964,7 @@ void Director::popToSceneStackLevel(int level)
void Director::end() void Director::end()
{ {
_purgeDirectorInNextLoop = true; _cleanupDirectorInNextLoop = true;
} }
void Director::restart() void Director::restart()
@ -1044,6 +1055,7 @@ void Director::reset()
SpriteFrameCache::destroyInstance(); SpriteFrameCache::destroyInstance();
FileUtils::destroyInstance(); FileUtils::destroyInstance();
AsyncTaskPool::destroyInstance(); AsyncTaskPool::destroyInstance();
backend::ProgramStateRegistry::destroyInstance();
backend::ProgramManager::destroyInstance(); backend::ProgramManager::destroyInstance();
// axmol specific data structures // axmol specific data structures
@ -1053,7 +1065,7 @@ void Director::reset()
destroyTextureCache(); destroyTextureCache();
} }
void Director::purgeDirector() void Director::cleanupDirector()
{ {
reset(); reset();
@ -1066,9 +1078,6 @@ void Director::purgeDirector()
_glView = nullptr; _glView = nullptr;
} }
// delete Director
release();
#if AX_TARGET_PLATFORM == AX_PLATFORM_IOS || AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID #if AX_TARGET_PLATFORM == AX_PLATFORM_IOS || AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID
utils::killCurrentProcess(); utils::killCurrentProcess();
#endif #endif
@ -1523,10 +1532,10 @@ void Director::mainLoop()
processOperations(); processOperations();
#endif #endif
if (_purgeDirectorInNextLoop) if (_cleanupDirectorInNextLoop)
{ {
_purgeDirectorInNextLoop = false; _cleanupDirectorInNextLoop = false;
purgeDirector(); cleanupDirector();
} }
else if (_restartDirectorInNextLoop) else if (_restartDirectorInNextLoop)
{ {

View File

@ -77,7 +77,7 @@ class Console;
Since the Director is a singleton, the standard way to use it is by calling: Since the Director is a singleton, the standard way to use it is by calling:
_ Director::getInstance()->methodName(); _ Director::getInstance()->methodName();
*/ */
class AX_DLL Director : public Ref class AX_DLL Director
{ {
public: public:
/** Director will trigger an event before set next scene. */ /** Director will trigger an event before set next scene. */
@ -123,6 +123,7 @@ public:
* @js _getInstance * @js _getInstance
*/ */
static Director* getInstance(); static Director* getInstance();
static void destroyInstance();
/** /**
* @js ctor * @js ctor
@ -531,8 +532,8 @@ protected:
virtual void startAnimation(SetIntervalReason reason); virtual void startAnimation(SetIntervalReason reason);
virtual void setAnimationInterval(float interval, SetIntervalReason reason); virtual void setAnimationInterval(float interval, SetIntervalReason reason);
void purgeDirector(); void cleanupDirector();
bool _purgeDirectorInNextLoop = false; // this flag will be set to true in end() bool _cleanupDirectorInNextLoop = false; // this flag will be set to true in end()
void restartDirector(); void restartDirector();
bool _restartDirectorInNextLoop = false; // this flag will be set to true in restart() bool _restartDirectorInNextLoop = false; // this flag will be set to true in restart()

View File

@ -3,6 +3,7 @@ Copyright (c) 2010 Stuart Carnie
Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
https://axmolengine.github.io/ https://axmolengine.github.io/
@ -50,7 +51,7 @@ class ProfilingTimer;
To use it, enable set the AX_ENABLE_PROFILERS=1 in the ccConfig.h file To use it, enable set the AX_ENABLE_PROFILERS=1 in the ccConfig.h file
*/ */
class AX_DLL Profiler : public Ref class AX_DLL Profiler
{ {
public: public:
/** /**

View File

@ -0,0 +1,38 @@
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
https://axmolengine.github.io/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "ApplicationBase.h"
#include "base/Director.h"
NS_AX_BEGIN
ApplicationBase::~ApplicationBase()
{
Director::destroyInstance();
}
NS_AX_END

View File

@ -2,6 +2,7 @@
Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
https://axmolengine.github.io/ https://axmolengine.github.io/
@ -24,8 +25,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
****************************************************************************/ ****************************************************************************/
#ifndef __AX_APPLICATION_PROTOCOL_H__ #ifndef __AX_APPLICATION_BASE_H__
#define __AX_APPLICATION_PROTOCOL_H__ #define __AX_APPLICATION_BASE_H__
#include "platform/PlatformMacros.h" #include "platform/PlatformMacros.h"
#include "base/AutoreleasePool.h" #include "base/AutoreleasePool.h"
@ -38,7 +39,7 @@ NS_AX_BEGIN
* @{ * @{
*/ */
class AX_DLL ApplicationProtocol class AX_DLL ApplicationBase
{ {
public: public:
/** Since WINDOWS and ANDROID are defined as macros, we could not just use these keywords in enumeration(Platform). /** Since WINDOWS and ANDROID are defined as macros, we could not just use these keywords in enumeration(Platform).
@ -65,11 +66,7 @@ public:
* @js NA * @js NA
* @lua NA * @lua NA
*/ */
virtual ~ApplicationProtocol() virtual ~ApplicationBase();
{
/** clean auto release pool. */
PoolManager::destroyInstance();
}
/** /**
* @brief Implement Director and Scene init code here. * @brief Implement Director and Scene init code here.
@ -152,6 +149,8 @@ public:
virtual bool openURL(std::string_view url) = 0; virtual bool openURL(std::string_view url) = 0;
}; };
using ApplicationProtocol = ApplicationBase;
// end of platform group // end of platform group
/** @} */ /** @} */

View File

@ -171,7 +171,7 @@ endif()
set(_AX_PLATFORM_HEADER set(_AX_PLATFORM_HEADER
${_AX_PLATFORM_SPECIFIC_HEADER} ${_AX_PLATFORM_SPECIFIC_HEADER}
platform/Application.h platform/Application.h
platform/ApplicationProtocol.h platform/ApplicationBase.h
platform/Common.h platform/Common.h
platform/Device.h platform/Device.h
platform/FileUtils.h platform/FileUtils.h
@ -194,4 +194,5 @@ set(_AX_PLATFORM_SRC
platform/FileUtils.cpp platform/FileUtils.cpp
platform/Image.cpp platform/Image.cpp
platform/FileStream.cpp platform/FileStream.cpp
platform/ApplicationBase.cpp
) )

View File

@ -2,6 +2,7 @@
Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
https://axmolengine.github.io/ https://axmolengine.github.io/
@ -26,11 +27,11 @@ THE SOFTWARE.
#pragma once #pragma once
#include "platform/Common.h" #include "platform/Common.h"
#include "platform/ApplicationProtocol.h" #include "platform/ApplicationBase.h"
NS_AX_BEGIN NS_AX_BEGIN
class AX_DLL Application : public ApplicationProtocol class AX_DLL Application : public ApplicationBase
{ {
public: public:
/** /**

View File

@ -3,8 +3,9 @@
* Developed by Game Engine part * Developed by Game Engine part
* *
* Copyright 2015 by Mobile Solution Lab, MSG, SRC-NJ. * Copyright 2015 by Mobile Solution Lab, MSG, SRC-NJ.
* Wang Ying * Wang Ying, All rights reserved.
* All rights reserved. * Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
*
* *
* This software is the confidential and proprietary information of * This software is the confidential and proprietary information of
* Samsung Electronics, Inc. ("Confidential Information"). You * Samsung Electronics, Inc. ("Confidential Information"). You
@ -15,7 +16,7 @@
#pragma once #pragma once
#include "platform/Common.h" #include "platform/Common.h"
#include "platform/ApplicationProtocol.h" #include "platform/ApplicationBase.h"
NS_AX_BEGIN NS_AX_BEGIN

View File

@ -2,6 +2,7 @@
Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
https://axmolengine.github.io/ https://axmolengine.github.io/
@ -26,11 +27,11 @@ THE SOFTWARE.
#pragma once #pragma once
#include "platform/Common.h" #include "platform/Common.h"
#include "platform/ApplicationProtocol.h" #include "platform/ApplicationBase.h"
NS_AX_BEGIN NS_AX_BEGIN
class AX_DLL Application : public ApplicationProtocol class AX_DLL Application : public ApplicationBase
{ {
public: public:
/** /**

View File

@ -2,6 +2,7 @@
Copyright (c) 2011 Laschweinski Copyright (c) 2011 Laschweinski
Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
https://axmolengine.github.io/ https://axmolengine.github.io/
@ -26,14 +27,14 @@ THE SOFTWARE.
#pragma once #pragma once
#include "platform/Common.h" #include "platform/Common.h"
#include "platform/ApplicationProtocol.h" #include "platform/ApplicationBase.h"
#include <string> #include <string>
#include <chrono> #include <chrono>
NS_AX_BEGIN NS_AX_BEGIN
class Rect; class Rect;
class Application : public ApplicationProtocol class Application : public ApplicationBase
{ {
public: public:
/** /**

View File

@ -2,6 +2,7 @@
Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
https://axmolengine.github.io/ https://axmolengine.github.io/
@ -26,13 +27,13 @@ THE SOFTWARE.
#pragma once #pragma once
#include "platform/Common.h" #include "platform/Common.h"
#include "platform/ApplicationProtocol.h" #include "platform/ApplicationBase.h"
#include <string> #include <string>
#include <chrono> #include <chrono>
NS_AX_BEGIN NS_AX_BEGIN
class AX_DLL Application : public ApplicationProtocol class AX_DLL Application : public ApplicationBase
{ {
public: public:
/** /**

View File

@ -2,6 +2,7 @@
Copyright (c) 2011 Laschweinski Copyright (c) 2011 Laschweinski
Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
http://www.cocos2d-x.org http://www.cocos2d-x.org
@ -31,13 +32,13 @@ THE SOFTWARE.
#if AX_TARGET_PLATFORM == AX_PLATFORM_WASM #if AX_TARGET_PLATFORM == AX_PLATFORM_WASM
#include "platform/Common.h" #include "platform/Common.h"
#include "platform/ApplicationProtocol.h" #include "platform/ApplicationBase.h"
#include <string> #include <string>
NS_AX_BEGIN NS_AX_BEGIN
class Rect; class Rect;
class Application : public ApplicationProtocol class Application : public ApplicationBase
{ {
public: public:
/** /**

View File

@ -128,6 +128,7 @@ int Application::run()
} }
glView->release(); glView->release();
return 0; return 0;
} }

View File

@ -2,6 +2,7 @@
Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
https://axmolengine.github.io/ https://axmolengine.github.io/
@ -27,12 +28,12 @@ THE SOFTWARE.
#include "platform/StdC.h" #include "platform/StdC.h"
#include "platform/Common.h" #include "platform/Common.h"
#include "platform/ApplicationProtocol.h" #include "platform/ApplicationBase.h"
#include <string> #include <string>
NS_AX_BEGIN NS_AX_BEGIN
class AX_DLL Application : public ApplicationProtocol class AX_DLL Application : public ApplicationBase
{ {
public: public:
/** /**

View File

@ -2,6 +2,7 @@
Copyright (c) 2010-2013 cocos2d-x.org Copyright (c) 2010-2013 cocos2d-x.org
Copyright (c) Microsoft Open Technologies, Inc. Copyright (c) Microsoft Open Technologies, Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
https://axmolengine.github.io/ https://axmolengine.github.io/

View File

@ -2,6 +2,7 @@
Copyright (c) 2010-2013 cocos2d-x.org Copyright (c) 2010-2013 cocos2d-x.org
Copyright (c) Microsoft Open Technologies, Inc. Copyright (c) Microsoft Open Technologies, Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
https://axmolengine.github.io/ https://axmolengine.github.io/
@ -31,14 +32,14 @@ THE SOFTWARE.
# include "platform/StdC.h" # include "platform/StdC.h"
# include "platform/Common.h" # include "platform/Common.h"
# include "platform/ApplicationProtocol.h" # include "platform/ApplicationBase.h"
# include "platform/winrt/InputEvent.h" # include "platform/winrt/InputEvent.h"
# include <string> # include <string>
# include <functional> # include <functional>
NS_AX_BEGIN NS_AX_BEGIN
class AX_DLL Application : public ApplicationProtocol class AX_DLL Application : public ApplicationBase
{ {
public: public:
Application(); Application();

View File

@ -1,6 +1,7 @@
/**************************************************************************** /****************************************************************************
Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
https://axmolengine.github.io/ https://axmolengine.github.io/
@ -37,6 +38,12 @@ NS_AX_BEGIN
int QuadCommand::__indexCapacity = -1; int QuadCommand::__indexCapacity = -1;
uint16_t* QuadCommand::__indices = nullptr; uint16_t* QuadCommand::__indices = nullptr;
void QuadCommand::destroyIsolatedIndices()
{
AX_SAFE_DELETE_ARRAY(__indices);
__indexCapacity = -1;
}
QuadCommand::QuadCommand() : _indexSize(-1), _ownedIndices() {} QuadCommand::QuadCommand() : _indexSize(-1), _ownedIndices() {}
QuadCommand::~QuadCommand() QuadCommand::~QuadCommand()

View File

@ -1,6 +1,7 @@
/**************************************************************************** /****************************************************************************
Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
https://axmolengine.github.io/ https://axmolengine.github.io/
@ -67,6 +68,8 @@ public:
const Mat4& mv, const Mat4& mv,
uint32_t flags); uint32_t flags);
static void destroyIsolatedIndices();
protected: protected:
void reIndex(int indices); void reIndex(int indices);

View File

@ -72,7 +72,7 @@ enum class FeatureType : uint32_t
/** /**
* New or create resources from DriverBase. * New or create resources from DriverBase.
*/ */
class AX_DLL DriverBase : public ax::Ref class AX_DLL DriverBase
{ {
public: public:
friend class ProgramManager; friend class ProgramManager;
@ -82,6 +82,7 @@ public:
* Returns a shared instance of the DriverBase. * Returns a shared instance of the DriverBase.
*/ */
static DriverBase* getInstance(); static DriverBase* getInstance();
static void destroyInstance();
virtual ~DriverBase() = default; virtual ~DriverBase() = default;

View File

@ -52,7 +52,7 @@ ProgramManager* ProgramManager::getInstance()
void ProgramManager::destroyInstance() void ProgramManager::destroyInstance()
{ {
AX_SAFE_RELEASE_NULL(_sharedProgramManager); AX_SAFE_DELETE(_sharedProgramManager);
} }
ProgramManager::ProgramManager() ProgramManager::ProgramManager()
@ -69,7 +69,7 @@ ProgramManager::~ProgramManager()
AX_SAFE_RELEASE(program.second); AX_SAFE_RELEASE(program.second);
} }
AXLOGINFO("deallocing ProgramManager: %p", this); AXLOGINFO("deallocing ProgramManager: %p", this);
backend::ShaderCache::getInstance()->purge(); backend::ShaderCache::destroyInstance();
} }
// ### end of vertex layout setup functions // ### end of vertex layout setup functions

View File

@ -46,7 +46,7 @@ NS_AX_BACKEND_BEGIN
/** /**
* Cache and reuse program object. * Cache and reuse program object.
*/ */
class AX_DLL ProgramManager : public Ref class AX_DLL ProgramManager
{ {
public: public:
/** returns the shared instance */ /** returns the shared instance */

View File

@ -21,7 +21,7 @@ ProgramStateRegistry* ProgramStateRegistry::getInstance()
/** purges the cache. It releases the retained instance. */ /** purges the cache. It releases the retained instance. */
void ProgramStateRegistry::destroyInstance() void ProgramStateRegistry::destroyInstance()
{ {
AX_SAFE_RELEASE_NULL(_sharedStateRegistry); AX_SAFE_DELETE(_sharedStateRegistry);
} }
bool ProgramStateRegistry::init() bool ProgramStateRegistry::init()

View File

@ -15,7 +15,7 @@ NS_AX_BACKEND_BEGIN
* @{ * @{
* #todo: Rename to ProgramStateRegistry * #todo: Rename to ProgramStateRegistry
*/ */
class AX_DLL ProgramStateRegistry : public Ref class AX_DLL ProgramStateRegistry
{ {
public: public:
/** returns the shared instance */ /** returns the shared instance */

View File

@ -1,5 +1,6 @@
/**************************************************************************** /****************************************************************************
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
https://axmolengine.github.io/ https://axmolengine.github.io/
@ -27,10 +28,23 @@
NS_AX_BACKEND_BEGIN NS_AX_BACKEND_BEGIN
static ShaderCache* s_instance;
ShaderCache* ShaderCache::getInstance() ShaderCache* ShaderCache::getInstance()
{ {
static ShaderCache instance; if (s_instance)
return &instance; return s_instance;
return (s_instance = new ShaderCache());
}
void ShaderCache::destroyInstance()
{
AX_SAFE_DELETE(s_instance);
}
ShaderCache::~ShaderCache()
{
purge();
} }
void ShaderCache::purge() void ShaderCache::purge()
@ -55,7 +69,7 @@ backend::ShaderModule* ShaderCache::newFragmentShaderModule(std::string_view sha
backend::ShaderModule* ShaderCache::newShaderModule(backend::ShaderStage stage, std::string_view shaderSource) backend::ShaderModule* ShaderCache::newShaderModule(backend::ShaderStage stage, std::string_view shaderSource)
{ {
const std::size_t key = std::hash<std::string_view>{}(shaderSource); const std::size_t key = std::hash<std::string_view>{}(shaderSource);
const auto iter = _cachedShaders.find(key); const auto iter = _cachedShaders.find(key);
if (_cachedShaders.end() != iter) if (_cachedShaders.end() != iter)
return iter->second; return iter->second;

View File

@ -1,5 +1,6 @@
/**************************************************************************** /****************************************************************************
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
https://axmolengine.github.io/ https://axmolengine.github.io/
@ -40,10 +41,13 @@ NS_AX_BACKEND_BEGIN
/** /**
* Create and reuse shader module. * Create and reuse shader module.
*/ */
class AX_DLL ShaderCache : public Ref class AX_DLL ShaderCache
{ {
public: public:
static ShaderCache* getInstance(); static ShaderCache* getInstance();
static void destroyInstance();
~ShaderCache();
/** purges the cache. It releases the retained instance. */ /** purges the cache. It releases the retained instance. */
void purge(); void purge();

View File

@ -391,10 +391,15 @@ id<CAMetalDrawable> DriverMTL::_currentDrawable = nil;
DriverBase* DriverBase::getInstance() DriverBase* DriverBase::getInstance()
{ {
if (!DriverBase::_instance) if (!_instance)
DriverBase::_instance = new DriverMTL(); _instance = new DriverMTL();
return DriverBase::_instance; return _instance;
}
void DriverBase::destroyInstance()
{
AX_SAFE_DELETE(_instance);
} }
void DriverMTL::setCAMetalLayer(CAMetalLayer* metalLayer) void DriverMTL::setCAMetalLayer(CAMetalLayer* metalLayer)

View File

@ -94,6 +94,10 @@ DriverBase* DriverBase::getInstance()
return _instance; return _instance;
} }
void DriverBase::destroyInstance() {
AX_SAFE_DELETE(_instance);
}
DriverGL::DriverGL() DriverGL::DriverGL()
{ {
/// driver info /// driver info

View File

@ -190,7 +190,7 @@ cc.UNIFORM_SAMPLER_S = 'AX_Texture0'
cc.UNIFORM_SIN_TIME_S = 'AX_SinTime' cc.UNIFORM_SIN_TIME_S = 'AX_SinTime'
cc.UNIFORM_TIME_S = 'AX_Time' cc.UNIFORM_TIME_S = 'AX_Time'
-- refer to: ApplicationProtocol.h: enum class Platform -- refer to: ApplicationBase.h: enum class Platform
cc.PLATFORM_UNKNOWN = 0 cc.PLATFORM_UNKNOWN = 0
cc.PLATFORM_WIN32 = 1 cc.PLATFORM_WIN32 = 1
cc.PLATFORM_WINUWP = 2 cc.PLATFORM_WINUWP = 2