修复了对象重复释放的bug

This commit is contained in:
Nomango 2017-10-21 19:53:38 +08:00
parent 9fa60891a4
commit 3abc386793
6 changed files with 10 additions and 33 deletions

View File

@ -271,8 +271,6 @@ void e2d::EApp::run()
// 关闭控制台
EApp::showConsole(false);
// 释放所有内存资源
this->_free();
}
void e2d::EApp::setFPS(UINT32 fps)
@ -581,14 +579,6 @@ void e2d::EApp::showWindow()
ShowWindow(GetHWnd(), SW_SHOWNORMAL);
}
void e2d::EApp::_free()
{
// 删除图片缓存
ETexture::clearCache();
// 删除所有对象(包括所有场景、定时器、监听器、动画)
EObjectManager::clearAllObjects();
}
void e2d::EApp::quit()
{
get()->m_bEnd = true;

View File

@ -101,7 +101,7 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<DebugInformationFormat>None</DebugInformationFormat>
<MinimalRebuild>false</MinimalRebuild>
</ClCompile>
<Link>
@ -146,7 +146,6 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>false</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
@ -172,7 +171,6 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>

View File

@ -1,11 +1,11 @@
#include "..\etools.h"
// EObjectManager 释放池的实现机制:
/// EObject 类中的引用计数m_nRefCount保证了指针的使用安全
/// 它记录了对象被使用的次数,当计数为 0 时EObjectManager 会自动释放这个对象
/// 所有的 EObject 对象都应在被使用时(例如 Text 添加到了场景中)
/// 调用 retain 函数保证该对象不被删除,并在不再使用时调用 release 函数
/// 让其自动释放
// EObject 类中的引用计数m_nRefCount保证了指针的使用安全
// 它记录了对象被使用的次数,当计数为 0 时EObjectManager 会自动释放这个对象
// 所有的 EObject 对象都应在被使用时(例如 Text 添加到了场景中)
// 调用 retain 函数保证该对象不被删除,并在不再使用时调用 release 函数
// 让其自动释放
// 释放池容器
static e2d::EVector<e2d::EObject*> s_vPool;
@ -45,15 +45,6 @@ void e2d::EObjectManager::add(e2d::EObject * nptr)
}
}
void e2d::EObjectManager::clearAllObjects()
{
for (const auto &obj : s_vPool)
{
delete obj;
}
s_vPool.clear();
}
void e2d::EObjectManager::notifyFlush()
{
s_bNotifyed = true;

View File

@ -39,6 +39,10 @@ e2d::ENode::~ENode()
EMsgManager::_clearAllMouseListenersBindedWith(this);
EMsgManager::_clearAllKeyboardListenersBindedWith(this);
EActionManager::_clearAllActionsBindedWith(this);
for (auto child : m_vChildren)
{
SafeReleaseAndClear(&child);
}
}
void e2d::ENode::onEnter()

View File

@ -184,9 +184,6 @@ protected:
UINT32 height
);
// 释放所有内存资源
void _free();
// ´°¿Ú³ÌÐò
static LRESULT CALLBACK WndProc(
HWND hWnd,

View File

@ -20,9 +20,6 @@ public:
e2d::EObject * nptr
);
// 删除所有节点
static void clearAllObjects();
// 通知内存池刷新
static void notifyFlush();