From 6eed14ae75e9fae8611fc7967ddf6e0e56e1de17 Mon Sep 17 00:00:00 2001 From: gabest11 Date: Sat, 4 Jul 2009 17:37:06 +0000 Subject: [PATCH] GSdx: fixing the (texture) memory leak git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1464 96395faa-99c1-11dd-bbfe-3dabce05a288 --- plugins/GSdx/GSDevice.cpp | 12 ++++++++---- plugins/GSdx/GSFunctionMap.h | 10 ++-------- plugins/GSdx/GSRasterizer.cpp | 5 +---- plugins/GSdx/GSState.cpp | 2 -- plugins/GSdx/GSTextureCache.cpp | 10 ++-------- plugins/GSdx/GSTextureCacheSW.cpp | 5 +---- plugins/GSdx/stdafx.h | 5 +++++ 7 files changed, 19 insertions(+), 30 deletions(-) diff --git a/plugins/GSdx/GSDevice.cpp b/plugins/GSdx/GSDevice.cpp index db34523630..88565ed6b5 100644 --- a/plugins/GSdx/GSDevice.cpp +++ b/plugins/GSdx/GSDevice.cpp @@ -34,6 +34,13 @@ GSDevice::GSDevice() GSDevice::~GSDevice() { + for_each(m_pool.begin(), m_pool.end(), delete_object()); + + delete m_backbuffer; + delete m_merge; + delete m_weavebob; + delete m_blend; + delete m_1x1; } bool GSDevice::Create(GSWnd* wnd, bool vsync) @@ -46,10 +53,7 @@ bool GSDevice::Create(GSWnd* wnd, bool vsync) bool GSDevice::Reset(int w, int h, int mode) { - for(list::iterator i = m_pool.begin(); i != m_pool.end(); i++) - { - delete *i; - } + for_each(m_pool.begin(), m_pool.end(), delete_object()); m_pool.clear(); diff --git a/plugins/GSdx/GSFunctionMap.h b/plugins/GSdx/GSFunctionMap.h index 050e49a92a..909b664ea8 100644 --- a/plugins/GSdx/GSFunctionMap.h +++ b/plugins/GSdx/GSFunctionMap.h @@ -66,10 +66,7 @@ public: virtual ~GSFunctionMap() { - for(hash_map::iterator i = m_map_active.begin(); i != m_map_active.end(); i++) - { - delete i->second; - } + for_each(m_map_active.begin(), m_map_active.end(), delete_second()); } VALUE operator [] (KEY key) @@ -177,10 +174,7 @@ public: virtual ~GSCodeGeneratorFunctionMap() { - for(hash_map::iterator i = m_cgmap.begin(); i != m_cgmap.end(); i++) - { - delete i->second; - } + for_each(m_cgmap.begin(), m_cgmap.end(), delete_second()); } VALUE GetDefaultFunction(KEY key) diff --git a/plugins/GSdx/GSRasterizer.cpp b/plugins/GSdx/GSRasterizer.cpp index de1d0e5e10..258b913834 100644 --- a/plugins/GSdx/GSRasterizer.cpp +++ b/plugins/GSdx/GSRasterizer.cpp @@ -883,10 +883,7 @@ GSRasterizerList::~GSRasterizerList() void GSRasterizerList::FreeRasterizers() { - for(list::iterator i = begin(); i != end(); i++) - { - delete *i; - } + for_each(begin(), end(), delete_object()); clear(); } diff --git a/plugins/GSdx/GSState.cpp b/plugins/GSdx/GSState.cpp index 1c77edd590..62b51bd95e 100644 --- a/plugins/GSdx/GSState.cpp +++ b/plugins/GSdx/GSState.cpp @@ -87,8 +87,6 @@ GSState::GSState(uint8* base, bool mt, void (*irq)()) m_regs = (GSPrivRegSet*)(base + 0x12000000); - memset(m_regs, 0, sizeof(GSPrivRegSet)); - PRIM = &m_env.PRIM; // CSR->rREV = 0x20; m_env.PRMODECONT.AC = 1; diff --git a/plugins/GSdx/GSTextureCache.cpp b/plugins/GSdx/GSTextureCache.cpp index d1893e0eba..03dd2281d4 100644 --- a/plugins/GSdx/GSTextureCache.cpp +++ b/plugins/GSdx/GSTextureCache.cpp @@ -38,10 +38,7 @@ void GSTextureCache::RemoveAll() for(int type = 0; type < 2; type++) { - for(list::iterator i = m_dst[type].begin(); i != m_dst[type].end(); i++) - { - delete *i; - } + for_each(m_dst[type].begin(), m_dst[type].end(), delete_object()); m_dst[type].clear(); } @@ -842,10 +839,7 @@ void GSTextureCache::SourceMap::Add(Source* s, const GIFRegTEX0& TEX0, GSLocalMe void GSTextureCache::SourceMap::RemoveAll() { - for(hash_map::iterator i = m_surfaces.begin(); i != m_surfaces.end(); i++) - { - delete i->first; - } + for_each(m_surfaces.begin(), m_surfaces.end(), delete_first()); m_surfaces.clear(); diff --git a/plugins/GSdx/GSTextureCacheSW.cpp b/plugins/GSdx/GSTextureCacheSW.cpp index 7b31f877c2..4921f6dd07 100644 --- a/plugins/GSdx/GSTextureCacheSW.cpp +++ b/plugins/GSdx/GSTextureCacheSW.cpp @@ -130,10 +130,7 @@ const GSTextureCacheSW::GSTexture* GSTextureCacheSW::Lookup(const GIFRegTEX0& TE void GSTextureCacheSW::RemoveAll() { - for(hash_map::iterator i = m_textures.begin(); i != m_textures.end(); i++) - { - delete i->first; - } + for_each(m_textures.begin(), m_textures.end(), delete_first()); m_textures.clear(); diff --git a/plugins/GSdx/stdafx.h b/plugins/GSdx/stdafx.h index 7d1c48d988..fd3a16579b 100644 --- a/plugins/GSdx/stdafx.h +++ b/plugins/GSdx/stdafx.h @@ -53,12 +53,17 @@ #include #include #include +#include using namespace std; using namespace stdext; extern string format(const char* fmt, ...); +struct delete_object {template void operator()(T& p) {delete p;}}; +struct delete_first {template void operator()(T& p) {delete p.first;}}; +struct delete_second {template void operator()(T& p) {delete p.second;}}; + // syntactic sugar // put these into vc9/common7/ide/usertype.dat to have them highlighted