From fa570d7c43ee73151cd2cfc76d3b819cba916ba5 Mon Sep 17 00:00:00 2001 From: "fix94.1" Date: Wed, 7 Nov 2012 22:27:41 +0000 Subject: [PATCH] -fixed small stupid memory bug -fixed codedump on exit in certain situations --- source/gui/coverflow.cpp | 34 ++++++++-------------------------- source/gui/coverflow.hpp | 3 +-- source/gui/cursor.cpp | 8 ++++---- source/gui/texture.cpp | 13 +++++++++++-- source/gui/video.cpp | 14 +++++++------- source/loader/sys.c | 3 +-- source/memory/mem2.hpp | 6 ------ source/menu/menu_main.cpp | 3 --- source/music/gui_sound.cpp | 7 ++----- 9 files changed, 34 insertions(+), 57 deletions(-) diff --git a/source/gui/coverflow.cpp b/source/gui/coverflow.cpp index 55f153c0..48d5eab9 100644 --- a/source/gui/coverflow.cpp +++ b/source/gui/coverflow.cpp @@ -227,6 +227,10 @@ CCoverFlow::CCoverFlow(void) m_normal_speed = 0.1f; m_selected_speed = 0.07f; // + m_flipSound = NULL; + m_hoverSound = NULL; + m_selectSound = NULL; + m_cancelSound = NULL; LWP_MutexInit(&m_mutex, 0); } @@ -262,13 +266,7 @@ void CCoverFlow::simulateOtherScreenFormat(bool s) CCoverFlow::~CCoverFlow(void) { - clear(); - if(m_flipSound != NULL) - delete m_flipSound; - m_flipSound = NULL; - if(m_cancelSound != NULL) - delete m_cancelSound; - m_cancelSound = NULL; + shutdown(); LWP_MutexDestroy(m_mutex); } @@ -670,16 +668,13 @@ void CCoverFlow::clear(void) void CCoverFlow::shutdown(void) { gprintf("Cleanup Coverflow\n"); - clear(); - m_dvdSkin.Cleanup(); m_dvdSkin_Red.Cleanup(); m_dvdSkin_Black.Cleanup(); m_dvdSkin_Yellow.Cleanup(); m_dvdSkin_GreenOne.Cleanup(); m_dvdSkin_GreenTwo.Cleanup(); - m_loadingTexture.Cleanup(); - m_noCoverTexture.Cleanup(); + clear(); if(m_flipSound != NULL) delete m_flipSound; @@ -1868,7 +1863,6 @@ bool CCoverFlow::start(const char *id) { if (m_pngLoadCoverFlat.empty() || STexture::TE_OK != m_loadingTexture.fromImageFile(m_pngLoadCoverFlat.c_str(), GX_TF_CMPR, 32, 512)) if (STexture::TE_OK != m_loadingTexture.fromJPG(flatloading_jpg, flatloading_jpg_size, GX_TF_CMPR, 32, 512)) return false; - if (m_pngNoCoverFlat.empty() || STexture::TE_OK != m_noCoverTexture.fromImageFile(m_pngNoCoverFlat.c_str(), GX_TF_CMPR, 32, 512)) if (STexture::TE_OK != m_noCoverTexture.fromPNG(flatnopic_png, GX_TF_CMPR, 32, 512)) return false; } @@ -1920,18 +1914,6 @@ void CCoverFlow::right(void) _right(m_minDelay, m_rows >= 3 ? m_rows - 2 : 1); } -void CCoverFlow::_playSound(void) -{ - /*if (m_soundVolume > 0) - { - sndCopyNum++; - if(sndCopyNum == 4) sndCopyNum = 0; - _playSound(m_sound[sndCopyNum]); - //gprintf("\n\nPlaying flipsound copy # %u\n\n", sndCopyNum); - }*/ - _playSound(m_flipSound); -} - void CCoverFlow::_left(int repeatDelay, u32 step) { int prev, arrStep; @@ -1968,7 +1950,7 @@ void CCoverFlow::_left(int repeatDelay, u32 step) _updateAllTargets(); _instantTarget(0); } - _playSound(); + _playSound(m_flipSound); m_covers[m_range / 2].angle -= _coverMovesA(); m_covers[m_range / 2].pos -= _coverMovesP(); } @@ -2009,7 +1991,7 @@ void CCoverFlow::_right(int repeatDelay, u32 step) _updateAllTargets(); _instantTarget(m_range - 1); } - _playSound(); + _playSound(m_flipSound); m_covers[m_range / 2].angle -= _coverMovesA(); m_covers[m_range / 2].pos -= _coverMovesP(); } diff --git a/source/gui/coverflow.hpp b/source/gui/coverflow.hpp index b3761b80..cea8af3b 100644 --- a/source/gui/coverflow.hpp +++ b/source/gui/coverflow.hpp @@ -330,8 +330,7 @@ private: bool _invisibleCover(u32 x, u32 y); void _instantTarget(int i); void _transposeCover(vector &dst, u32 rows, u32 columns, int pos); - void _playSound(void); - + void _stopSound(GuiSound * &snd); void _playSound(GuiSound * &snd); diff --git a/source/gui/cursor.cpp b/source/gui/cursor.cpp index 03785087..a930a8d2 100644 --- a/source/gui/cursor.cpp +++ b/source/gui/cursor.cpp @@ -32,13 +32,13 @@ bool CCursor::init(const char *png, bool wideFix, CColor shadowColor, float shad if (STexture::TE_OK != m_texture.fromImageFile(png)) { if (chan == 0) - ok = STexture::TE_OK == m_texture.fromPNG(player1_point_png, GX_TF_RGBA8); + ok = STexture::TE_OK == m_texture.fromPNG(player1_point_png); else if (chan == 1) - ok = STexture::TE_OK == m_texture.fromPNG(player2_point_png, GX_TF_RGBA8); + ok = STexture::TE_OK == m_texture.fromPNG(player2_point_png); else if (chan == 2) - ok = STexture::TE_OK == m_texture.fromPNG(player3_point_png, GX_TF_RGBA8); + ok = STexture::TE_OK == m_texture.fromPNG(player3_point_png); else if (chan == 3) - ok = STexture::TE_OK == m_texture.fromPNG(player4_point_png, GX_TF_RGBA8); + ok = STexture::TE_OK == m_texture.fromPNG(player4_point_png); } if (ok && shadow) { diff --git a/source/gui/texture.cpp b/source/gui/texture.cpp index e69d80ee..da515311 100644 --- a/source/gui/texture.cpp +++ b/source/gui/texture.cpp @@ -215,6 +215,7 @@ bool STexture::CopyTexture(const STexture &tex) STexture::TexErr STexture::fromImageFile(const char *filename, u8 f, u32 minMipSize, u32 maxMipSize) { + Cleanup(); FILE *file = fopen(filename, "rb"); if(file == NULL) { @@ -257,7 +258,10 @@ STexture::TexErr STexture::fromTHP(const u8 *src, u32 w, u32 h) dataSize = GX_GetTexBufferSize(width, height, format, GX_FALSE, 0); data = (u8*)MEM2_alloc(dataSize); if(data == NULL) + { + Cleanup(); return TE_NOMEM; + } for(u32 block = 0; block < height; block += 4) { for(u32 i = 0; i < width; i += 4) @@ -466,8 +470,10 @@ STexture::TexErr STexture::fromPNG(const u8 *buffer, u8 f, u32 minMipSize, u32 m tmpData2 = _genMipMaps(tmpData2, imgProp.imgWidth, imgProp.imgHeight, maxLODTmp, baseWidth, baseHeight); if(tmpData2 == NULL) + { + Cleanup(); return TE_NOMEM; - + } u32 nWidth = newWidth; u32 nHeight = newHeight; u8 *pSrc = tmpData2; @@ -659,7 +665,10 @@ u8 *STexture::_genMipMaps(u8 *src, u32 width, u32 height, u8 maxLOD, u32 lod0Wid u32 bufSize = fixGX_GetTexBufferSize(lod0Width, lod0Height, GX_TF_RGBA8, GX_TRUE, maxLOD); u8 *dst = (u8*)MEM2_alloc(bufSize); if(dst == NULL) - return src; + { + Cleanup(); + return NULL; + } memset(dst, 0, bufSize); _resize(dst, lod0Width, lod0Height, src, width, height); DCFlushRange(dst, lod0Width * lod0Height * 4); diff --git a/source/gui/video.cpp b/source/gui/video.cpp index d578c3f1..4145aafd 100644 --- a/source/gui/video.cpp +++ b/source/gui/video.cpp @@ -80,7 +80,6 @@ const int CVideo::_stencilWidth = 128; const int CVideo::_stencilHeight = 128; static lwp_t waitThread = LWP_THREAD_NULL; -u8 *waitThreadStack; CVideo m_vid; CVideo::CVideo(void) : @@ -284,13 +283,16 @@ void CVideo::cleanup(void) { if(m_defaultWaitMessages[i].data != NULL) free(m_defaultWaitMessages[i].data); + m_defaultWaitMessages[i].data = NULL; } - if(waitThreadStack != NULL) - free(waitThreadStack); free(MEM_K1_TO_K0(m_frameBuf[0])); + m_frameBuf[0] = NULL; free(MEM_K1_TO_K0(m_frameBuf[1])); + m_frameBuf[1] = NULL; free(m_stencil); + m_stencil = NULL; free(m_fifo); + m_fifo = NULL; } void CVideo::prepareAAPass(int aaStep) @@ -558,7 +560,7 @@ void CVideo::hideWaitMessage() if(LWP_ThreadIsSuspended(waitThread)) LWP_ResumeThread(waitThread); while(m_showingWaitMessages) - usleep(100); + usleep(50); LWP_JoinThread(waitThread, NULL); } waitThread = LWP_THREAD_NULL; @@ -602,9 +604,7 @@ void CVideo::waitMessage(const vector &tex, float delay) else if(m_waitMessages.size() > 1) { m_showWaitMessage = true; - if(waitThreadStack != NULL) - waitThreadStack = (u8*)MEM2_alloc(8192); - LWP_CreateThread(&waitThread, (void *(*)(void *))_showWaitMessages, (void *)this, waitThreadStack, 8192, LWP_PRIO_HIGHEST); + LWP_CreateThread(&waitThread, (void *(*)(void *))_showWaitMessages, (void *)this, NULL, 0, LWP_PRIO_HIGHEST); } } diff --git a/source/loader/sys.c b/source/loader/sys.c index 728f4e1b..860ff2aa 100644 --- a/source/loader/sys.c +++ b/source/loader/sys.c @@ -21,7 +21,6 @@ /* Variables */ bool reset = false; bool shutdown = false; -bool exiting = false; u8 ExitOption = 0; const char *NeekPath = NULL; @@ -61,7 +60,7 @@ void Close_Inputs(void) bool Sys_Exiting(void) { - return reset || shutdown || exiting; + return reset || shutdown; } void Sys_Shutdown(void) diff --git a/source/memory/mem2.hpp b/source/memory/mem2.hpp index 11c33937..6713112a 100644 --- a/source/memory/mem2.hpp +++ b/source/memory/mem2.hpp @@ -33,10 +33,4 @@ unsigned int MEM2_freesize(); } #endif -enum Alloc -{ - ALLOC_MALLOC, - ALLOC_MEM2, -}; - #endif // !defined(__MEM2_HPP) \ No newline at end of file diff --git a/source/menu/menu_main.cpp b/source/menu/menu_main.cpp index 973af851..a5ff3c68 100644 --- a/source/menu/menu_main.cpp +++ b/source/menu/menu_main.cpp @@ -220,9 +220,6 @@ void CMenu::exitHandler(int ExitTo) ExitTo = EXIT_TO_HBC; } Sys_ExitTo(ExitTo); - // Mark exiting to prevent soundhandler from restarting - extern bool exiting; - exiting = true; } int CMenu::main(void) diff --git a/source/music/gui_sound.cpp b/source/music/gui_sound.cpp index 5c98f1f8..949630e3 100644 --- a/source/music/gui_sound.cpp +++ b/source/music/gui_sound.cpp @@ -147,11 +147,8 @@ void GuiSound::Init() void GuiSound::FreeMemory() { Stop(); - - // Prevent reinitialization of SoundHandler since we're exiting - if(!Sys_Exiting()) - SoundHandle.RemoveDecoder(this->voice); - + if(this->voice != -1) + SoundHandle.RemoveDecoder(this->voice); if(allocated && sound != NULL) free(sound); allocated = false;