cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.22k stars 7.06k forks source link

crtdbg " Detected memory leaks!" fix patch #17412

Open ka7713 opened 7 years ago

ka7713 commented 7 years ago

Steps to Reproduce:

  1. cpp-empty-test, cpp-tests
int WINAPI _tWinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPTSTR    lpCmdLine,
                       int       nCmdShow)
{
    _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);

    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    AppDelegate app;
    Application::getInstance()->run();

    return 0;
}
Detected memory leaks!
Dumping objects ->
{211136} normal block at 0x12F2E9D8, 4 bytes long.
 Data: <    > 00 00 00 00 
.....................
9613 lines
.....................
{89196} normal block at 0x048E94C0, 44 bytes long.
 Data: <       ?p   X   > E4 EE BF 05 00 00 80 3F 70 EB 8D 08 58 9E 8E 04 
Object dump complete.
  1. patch
    
    diff -x ''\''*.h'\''' -x ''\''*.cpp'\''' -ur D:\download\cocos2d-x-3.14.1\cocos2d-x-3.14.1/cocos/base/CCDirector.cpp D:\work\cocos2d-x-3.14.1/cocos/base/CCDirector.cpp
    --- D:\download\cocos2d-x-3.14.1\cocos2d-x-3.14.1/cocos/base/CCDirector.cpp 2017-01-18 10:57:42.000000000 +0900
    +++ D:\work\cocos2d-x-3.14.1/cocos/base/CCDirector.cpp  2017-02-26 15:14:29.666814100 +0900
    @@ -62,6 +62,12 @@
    #include "base/CCAsyncTaskPool.h"
    #include "platform/CCApplication.h"

+#include "cocostudio/CCTransformHelp.h" +#include "base/ObjectFactory.h" +#include "3d/CCSprite3DMaterial.h" +#include "3d/CCSprite3D.h" +#include "extensions/Particle3D/PU/CCPUMaterialManager.h" +

if CC_ENABLE_SCRIPT_BINDING

include "base/CCScriptSupport.h"

endif

@@ -210,6 +216,13 @@

 Configuration::destroyInstance();

@@ -1081,13 +1094,17 @@

elif _MSC_VER >= 1400 //vs 2005 or higher

pragma warning (pop)

endif

+ AnimationCache::destroyInstance();

diff -x ''\''.h'\''' -x ''\''.cpp'\''' -ur D:\download\cocos2d-x-3.14.1\cocos2d-x-3.14.1/cocos/editor-support/cocostudio/CCTransformHelp.cpp D:\work\cocos2d-x-3.14.1/cocos/editor-support/cocostudio/CCTransformHelp.cpp --- D:\download\cocos2d-x-3.14.1\cocos2d-x-3.14.1/cocos/editor-support/cocostudio/CCTransformHelp.cpp 2017-01-18 10:57:42.000000000 +0900 +++ D:\work\cocos2d-x-3.14.1/cocos/editor-support/cocostudio/CCTransformHelp.cpp 2017-02-26 04:18:53.384811600 +0900 @@ -35,12 +35,17 @@ Vec2 TransformHelp::helpPoint1; Vec2 TransformHelp::helpPoint2;

-BaseData helpParentNode; +BaseData *helpParentNode = nullptr;

TransformHelp::TransformHelp() { }

+void TransformHelp::release() +{

diff -x ''\''.h'\''' -x ''\''.cpp'\''' -ur D:\download\cocos2d-x-3.14.1\cocos2d-x-3.14.1/cocos/editor-support/cocostudio/CCTransformHelp.h D:\work\cocos2d-x-3.14.1/cocos/editor-support/cocostudio/CCTransformHelp.h --- D:\download\cocos2d-x-3.14.1\cocos2d-x-3.14.1/cocos/editor-support/cocostudio/CCTransformHelp.h 2017-01-18 10:57:42.000000000 +0900 +++ D:\work\cocos2d-x-3.14.1/cocos/editor-support/cocostudio/CCTransformHelp.h 2017-02-26 04:25:58.553020600 +0900 @@ -41,6 +41,8 @@ public: TransformHelp();

diff -x ''\''.h'\''' -x ''\''.cpp'\''' -ur D:\download\cocos2d-x-3.14.1\cocos2d-x-3.14.1/cocos/platform/desktop/CCGLViewImpl-desktop.cpp D:\work\cocos2d-x-3.14.1/cocos/platform/desktop/CCGLViewImpl-desktop.cpp --- D:\download\cocos2d-x-3.14.1\cocos2d-x-3.14.1/cocos/platform/desktop/CCGLViewImpl-desktop.cpp 2017-01-18 10:57:42.000000000 +0900 +++ D:\work\cocos2d-x-3.14.1/cocos/platform/desktop/CCGLViewImpl-desktop.cpp 2017-02-26 05:02:32.676988900 +0900 @@ -487,6 +487,17 @@ { if(_mainWindow) {

diff -x ''\''.h'\''' -x ''\''.cpp'\''' -ur D:\download\cocos2d-x-3.14.1\cocos2d-x-3.14.1/cocos/renderer/CCQuadCommand.cpp D:\work\cocos2d-x-3.14.1/cocos/renderer/CCQuadCommand.cpp --- D:\download\cocos2d-x-3.14.1\cocos2d-x-3.14.1/cocos/renderer/CCQuadCommand.cpp 2017-01-18 10:57:42.000000000 +0900 +++ D:\work\cocos2d-x-3.14.1/cocos/renderer/CCQuadCommand.cpp 2017-02-26 04:58:24.233604600 +0900 @@ -85,8 +85,9 @@

     CCLOG("cocos2d: QuadCommand: resizing index size from [%d] to [%d]", __indexCapacity, indicesCount);

diff -x ''\''.h'\''' -x ''\''.cpp'\''' -ur D:\download\cocos2d-x-3.14.1\cocos2d-x-3.14.1/extensions/Particle3D/PU/CCPUMaterialManager.cpp D:\work\cocos2d-x-3.14.1/extensions/Particle3D/PU/CCPUMaterialManager.cpp --- D:\download\cocos2d-x-3.14.1\cocos2d-x-3.14.1/extensions/Particle3D/PU/CCPUMaterialManager.cpp 2017-01-18 10:57:44.000000000 +0900 +++ D:\work\cocos2d-x-3.14.1/extensions/Particle3D/PU/CCPUMaterialManager.cpp 2017-02-26 15:17:59.310606900 +0900 @@ -44,6 +44,8 @@ NS_CC_BEGIN

+PUMaterialCache* PUMaterialCache::s_instance = nullptr; + PUMaterial::PUMaterial() : isEnabledLight(true) , ambientColor(Vec4::ONE) @@ -74,8 +76,14 @@

PUMaterialCache* PUMaterialCache::Instance() {

minggo commented 7 years ago

why not send a PR? It is hard to read the patch