add: tracing object leaks
This commit is contained in:
parent
2b411989cf
commit
ff8b647d9d
|
|
@ -29,7 +29,7 @@ namespace easy2d
|
|||
class ActionManager;
|
||||
|
||||
class Action
|
||||
: public RefCounter
|
||||
: public ObjectBase
|
||||
, protected intrusive::ListItem<spAction>
|
||||
{
|
||||
friend class ActionManager;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace easy2d
|
|||
{
|
||||
// 帧动画
|
||||
class Animation
|
||||
: public RefCounter
|
||||
: public ObjectBase
|
||||
{
|
||||
using Images = std::vector< spImage >;
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,9 @@ namespace easy2d
|
|||
style.wrap = false;
|
||||
style.line_spacing = 18.f;
|
||||
debug_text_->SetStyle(style);
|
||||
|
||||
ObjectBase::__RemoveObjectFromTracingList(this);
|
||||
ObjectBase::__RemoveObjectFromTracingList(debug_text_.Get());
|
||||
}
|
||||
|
||||
DebugerNode::~DebugerNode()
|
||||
|
|
@ -84,6 +87,12 @@ namespace easy2d
|
|||
std::wstringstream ss;
|
||||
ss << "fps=" << frame_time_.size() << std::endl;
|
||||
|
||||
#ifdef E2D_DEBUG
|
||||
|
||||
ss << "objects=" << ObjectBase::__GetTracingObjects().size() << std::endl;
|
||||
|
||||
#endif
|
||||
|
||||
PROCESS_MEMORY_COUNTERS_EX pmc;
|
||||
GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc));
|
||||
if (pmc.PrivateUsage > 1024 * 1024)
|
||||
|
|
@ -92,7 +101,7 @@ namespace easy2d
|
|||
ss << "memory=" << pmc.PrivateUsage / 1024 << "Kb";
|
||||
|
||||
for (const auto& text : texts_)
|
||||
ss << text << std::endl;
|
||||
ss << std::endl << text;
|
||||
|
||||
debug_text_->SetText(ss.str());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ namespace easy2d
|
|||
{
|
||||
// ͼƬ
|
||||
class Image
|
||||
: public RefCounter
|
||||
: public ObjectBase
|
||||
{
|
||||
public:
|
||||
Image();
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace easy2d
|
|||
{
|
||||
// 稜있
|
||||
class Music
|
||||
: public RefCounter
|
||||
: public ObjectBase
|
||||
{
|
||||
public:
|
||||
Music();
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace easy2d
|
|||
|
||||
// 节点
|
||||
class Node
|
||||
: public RefCounter
|
||||
: public ObjectBase
|
||||
, public ActionManager
|
||||
, public TaskManager
|
||||
, protected intrusive::ListItem<spNode>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,96 @@
|
|||
// Copyright (c) 2016-2018 Easy2D - Nomango
|
||||
//
|
||||
// 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 "ObjectBase.h"
|
||||
|
||||
namespace easy2d
|
||||
{
|
||||
namespace
|
||||
{
|
||||
bool tracing_leaks = true;
|
||||
std::vector<ObjectBase*> tracing_objects;
|
||||
}
|
||||
|
||||
ObjectBase::ObjectBase()
|
||||
: tracing_leak_(false)
|
||||
{
|
||||
#ifdef E2D_DEBUG
|
||||
|
||||
ObjectBase::__AddObjectToTracingList(this);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
ObjectBase::~ObjectBase()
|
||||
{
|
||||
#ifdef E2D_DEBUG
|
||||
|
||||
ObjectBase::__RemoveObjectFromTracingList(this);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void ObjectBase::StartTracingLeaks()
|
||||
{
|
||||
tracing_leaks = true;
|
||||
}
|
||||
|
||||
void ObjectBase::StopTracingLeaks()
|
||||
{
|
||||
tracing_leaks = false;
|
||||
}
|
||||
|
||||
std::vector<ObjectBase*> const& easy2d::ObjectBase::__GetTracingObjects()
|
||||
{
|
||||
return tracing_objects;
|
||||
}
|
||||
|
||||
void ObjectBase::__AddObjectToTracingList(ObjectBase * obj)
|
||||
{
|
||||
#ifdef E2D_DEBUG
|
||||
|
||||
if (tracing_leaks && !obj->tracing_leak_)
|
||||
{
|
||||
obj->tracing_leak_ = true;
|
||||
tracing_objects.push_back(obj);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void ObjectBase::__RemoveObjectFromTracingList(ObjectBase * obj)
|
||||
{
|
||||
#ifdef E2D_DEBUG
|
||||
|
||||
if (tracing_leaks && obj->tracing_leak_)
|
||||
{
|
||||
obj->tracing_leak_ = false;
|
||||
|
||||
auto iter = std::find(tracing_objects.begin(), tracing_objects.end(), obj);
|
||||
if (iter != tracing_objects.end())
|
||||
{
|
||||
tracing_objects.erase(iter);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
// Copyright (c) 2016-2018 Easy2D - Nomango
|
||||
//
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
#include "RefCounter.hpp"
|
||||
|
||||
namespace easy2d
|
||||
{
|
||||
class ObjectBase
|
||||
: public RefCounter
|
||||
{
|
||||
public:
|
||||
ObjectBase();
|
||||
|
||||
virtual ~ObjectBase();
|
||||
|
||||
static void StartTracingLeaks();
|
||||
|
||||
static void StopTracingLeaks();
|
||||
|
||||
static std::vector<ObjectBase*> const& __GetTracingObjects();
|
||||
|
||||
protected:
|
||||
static void __AddObjectToTracingList(ObjectBase*);
|
||||
|
||||
static void __RemoveObjectFromTracingList(ObjectBase*);
|
||||
|
||||
private:
|
||||
bool tracing_leak_;
|
||||
};
|
||||
}
|
||||
|
|
@ -30,7 +30,7 @@ namespace easy2d
|
|||
|
||||
// 定时任务
|
||||
class Task
|
||||
: public RefCounter
|
||||
: public ObjectBase
|
||||
, protected intrusive::ListItem<spTask>
|
||||
{
|
||||
friend class TaskManager;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ namespace easy2d
|
|||
|
||||
// 场景过渡
|
||||
class Transition
|
||||
: public RefCounter
|
||||
: public ObjectBase
|
||||
{
|
||||
friend class Game;
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#pragma once
|
||||
#include "BaseTypes.hpp"
|
||||
#include "RefCounter.hpp"
|
||||
#include "ObjectBase.h"
|
||||
#include "intrusive/SmartPointer.hpp"
|
||||
#include "d2dres.hpp"
|
||||
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@
|
|||
#include "base/intrusive/List.hpp"
|
||||
|
||||
#include "base/RefCounter.hpp"
|
||||
#include "base/ObjectBase.h"
|
||||
#include "base/Image.h"
|
||||
#include "base/Node.h"
|
||||
#include "base/Scene.h"
|
||||
|
|
@ -68,6 +69,7 @@
|
|||
#include "base/Animation.h"
|
||||
#include "base/CallFunc.h"
|
||||
#include "base/Transition.h"
|
||||
#include "base/Debuger.h"
|
||||
|
||||
#include "base/KeyEvent.h"
|
||||
#include "base/MouseEvent.h"
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@
|
|||
<ClInclude Include="..\..\core\base\Music.h" />
|
||||
<ClInclude Include="..\..\core\base\Node.h" />
|
||||
<ClInclude Include="..\..\core\base\noncopyable.hpp" />
|
||||
<ClInclude Include="..\..\core\base\ObjectBase.h" />
|
||||
<ClInclude Include="..\..\core\base\Point.hpp" />
|
||||
<ClInclude Include="..\..\core\base\Rect.hpp" />
|
||||
<ClInclude Include="..\..\core\base\RefCounter.hpp" />
|
||||
|
|
@ -97,6 +98,7 @@
|
|||
<ClCompile Include="..\..\core\base\MouseEvent.cpp" />
|
||||
<ClCompile Include="..\..\core\base\Music.cpp" />
|
||||
<ClCompile Include="..\..\core\base\Node.cpp" />
|
||||
<ClCompile Include="..\..\core\base\ObjectBase.cpp" />
|
||||
<ClCompile Include="..\..\core\base\render.cpp" />
|
||||
<ClCompile Include="..\..\core\base\Resource.cpp" />
|
||||
<ClCompile Include="..\..\core\base\Scene.cpp" />
|
||||
|
|
|
|||
|
|
@ -173,6 +173,9 @@
|
|||
<ClInclude Include="..\..\core\utils\string.h">
|
||||
<Filter>utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\core\base\ObjectBase.h">
|
||||
<Filter>base</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="base">
|
||||
|
|
@ -306,5 +309,8 @@
|
|||
<ClCompile Include="..\..\core\utils\string.cpp">
|
||||
<Filter>utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\core\base\ObjectBase.cpp">
|
||||
<Filter>base</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -46,6 +46,7 @@
|
|||
<ClInclude Include="..\..\core\base\Music.h" />
|
||||
<ClInclude Include="..\..\core\base\Node.h" />
|
||||
<ClInclude Include="..\..\core\base\noncopyable.hpp" />
|
||||
<ClInclude Include="..\..\core\base\ObjectBase.h" />
|
||||
<ClInclude Include="..\..\core\base\Point.hpp" />
|
||||
<ClInclude Include="..\..\core\base\Rect.hpp" />
|
||||
<ClInclude Include="..\..\core\base\RefCounter.hpp" />
|
||||
|
|
@ -97,6 +98,7 @@
|
|||
<ClCompile Include="..\..\core\base\MouseEvent.cpp" />
|
||||
<ClCompile Include="..\..\core\base\Music.cpp" />
|
||||
<ClCompile Include="..\..\core\base\Node.cpp" />
|
||||
<ClCompile Include="..\..\core\base\ObjectBase.cpp" />
|
||||
<ClCompile Include="..\..\core\base\render.cpp" />
|
||||
<ClCompile Include="..\..\core\base\Resource.cpp" />
|
||||
<ClCompile Include="..\..\core\base\Scene.cpp" />
|
||||
|
|
|
|||
|
|
@ -173,6 +173,9 @@
|
|||
<ClInclude Include="..\..\core\utils\string.h">
|
||||
<Filter>utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\core\base\ObjectBase.h">
|
||||
<Filter>base</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="base">
|
||||
|
|
@ -306,5 +309,8 @@
|
|||
<ClCompile Include="..\..\core\utils\string.cpp">
|
||||
<Filter>utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\core\base\ObjectBase.cpp">
|
||||
<Filter>base</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -46,6 +46,7 @@
|
|||
<ClInclude Include="..\..\core\base\Music.h" />
|
||||
<ClInclude Include="..\..\core\base\Node.h" />
|
||||
<ClInclude Include="..\..\core\base\noncopyable.hpp" />
|
||||
<ClInclude Include="..\..\core\base\ObjectBase.h" />
|
||||
<ClInclude Include="..\..\core\base\Point.hpp" />
|
||||
<ClInclude Include="..\..\core\base\Rect.hpp" />
|
||||
<ClInclude Include="..\..\core\base\RefCounter.hpp" />
|
||||
|
|
@ -97,6 +98,7 @@
|
|||
<ClCompile Include="..\..\core\base\MouseEvent.cpp" />
|
||||
<ClCompile Include="..\..\core\base\Music.cpp" />
|
||||
<ClCompile Include="..\..\core\base\Node.cpp" />
|
||||
<ClCompile Include="..\..\core\base\ObjectBase.cpp" />
|
||||
<ClCompile Include="..\..\core\base\render.cpp" />
|
||||
<ClCompile Include="..\..\core\base\Resource.cpp" />
|
||||
<ClCompile Include="..\..\core\base\Scene.cpp" />
|
||||
|
|
|
|||
|
|
@ -173,6 +173,9 @@
|
|||
<ClInclude Include="..\..\core\utils\string.h">
|
||||
<Filter>utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\core\base\ObjectBase.h">
|
||||
<Filter>base</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="base">
|
||||
|
|
@ -306,5 +309,8 @@
|
|||
<ClCompile Include="..\..\core\utils\string.cpp">
|
||||
<Filter>utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\core\base\ObjectBase.cpp">
|
||||
<Filter>base</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Loading…
Reference in New Issue