-fixed small stupid memory bug

-fixed codedump on exit in certain situations
This commit is contained in:
fix94.1 2012-11-07 22:27:41 +00:00
parent 48737c010a
commit fa570d7c43
9 changed files with 34 additions and 57 deletions

View File

@ -227,6 +227,10 @@ CCoverFlow::CCoverFlow(void)
m_normal_speed = 0.1f; m_normal_speed = 0.1f;
m_selected_speed = 0.07f; m_selected_speed = 0.07f;
// //
m_flipSound = NULL;
m_hoverSound = NULL;
m_selectSound = NULL;
m_cancelSound = NULL;
LWP_MutexInit(&m_mutex, 0); LWP_MutexInit(&m_mutex, 0);
} }
@ -262,13 +266,7 @@ void CCoverFlow::simulateOtherScreenFormat(bool s)
CCoverFlow::~CCoverFlow(void) CCoverFlow::~CCoverFlow(void)
{ {
clear(); shutdown();
if(m_flipSound != NULL)
delete m_flipSound;
m_flipSound = NULL;
if(m_cancelSound != NULL)
delete m_cancelSound;
m_cancelSound = NULL;
LWP_MutexDestroy(m_mutex); LWP_MutexDestroy(m_mutex);
} }
@ -670,16 +668,13 @@ void CCoverFlow::clear(void)
void CCoverFlow::shutdown(void) void CCoverFlow::shutdown(void)
{ {
gprintf("Cleanup Coverflow\n"); gprintf("Cleanup Coverflow\n");
clear();
m_dvdSkin.Cleanup(); m_dvdSkin.Cleanup();
m_dvdSkin_Red.Cleanup(); m_dvdSkin_Red.Cleanup();
m_dvdSkin_Black.Cleanup(); m_dvdSkin_Black.Cleanup();
m_dvdSkin_Yellow.Cleanup(); m_dvdSkin_Yellow.Cleanup();
m_dvdSkin_GreenOne.Cleanup(); m_dvdSkin_GreenOne.Cleanup();
m_dvdSkin_GreenTwo.Cleanup(); m_dvdSkin_GreenTwo.Cleanup();
m_loadingTexture.Cleanup(); clear();
m_noCoverTexture.Cleanup();
if(m_flipSound != NULL) if(m_flipSound != NULL)
delete m_flipSound; 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 (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 (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 (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; 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); _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) void CCoverFlow::_left(int repeatDelay, u32 step)
{ {
int prev, arrStep; int prev, arrStep;
@ -1968,7 +1950,7 @@ void CCoverFlow::_left(int repeatDelay, u32 step)
_updateAllTargets(); _updateAllTargets();
_instantTarget(0); _instantTarget(0);
} }
_playSound(); _playSound(m_flipSound);
m_covers[m_range / 2].angle -= _coverMovesA(); m_covers[m_range / 2].angle -= _coverMovesA();
m_covers[m_range / 2].pos -= _coverMovesP(); m_covers[m_range / 2].pos -= _coverMovesP();
} }
@ -2009,7 +1991,7 @@ void CCoverFlow::_right(int repeatDelay, u32 step)
_updateAllTargets(); _updateAllTargets();
_instantTarget(m_range - 1); _instantTarget(m_range - 1);
} }
_playSound(); _playSound(m_flipSound);
m_covers[m_range / 2].angle -= _coverMovesA(); m_covers[m_range / 2].angle -= _coverMovesA();
m_covers[m_range / 2].pos -= _coverMovesP(); m_covers[m_range / 2].pos -= _coverMovesP();
} }

View File

@ -330,7 +330,6 @@ private:
bool _invisibleCover(u32 x, u32 y); bool _invisibleCover(u32 x, u32 y);
void _instantTarget(int i); void _instantTarget(int i);
void _transposeCover(vector<CCover> &dst, u32 rows, u32 columns, int pos); void _transposeCover(vector<CCover> &dst, u32 rows, u32 columns, int pos);
void _playSound(void);
void _stopSound(GuiSound * &snd); void _stopSound(GuiSound * &snd);
void _playSound(GuiSound * &snd); void _playSound(GuiSound * &snd);

View File

@ -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 (STexture::TE_OK != m_texture.fromImageFile(png))
{ {
if (chan == 0) 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) 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) 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) 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) if (ok && shadow)
{ {

View File

@ -215,6 +215,7 @@ bool STexture::CopyTexture(const STexture &tex)
STexture::TexErr STexture::fromImageFile(const char *filename, u8 f, u32 minMipSize, u32 maxMipSize) STexture::TexErr STexture::fromImageFile(const char *filename, u8 f, u32 minMipSize, u32 maxMipSize)
{ {
Cleanup();
FILE *file = fopen(filename, "rb"); FILE *file = fopen(filename, "rb");
if(file == NULL) 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); dataSize = GX_GetTexBufferSize(width, height, format, GX_FALSE, 0);
data = (u8*)MEM2_alloc(dataSize); data = (u8*)MEM2_alloc(dataSize);
if(data == NULL) if(data == NULL)
{
Cleanup();
return TE_NOMEM; return TE_NOMEM;
}
for(u32 block = 0; block < height; block += 4) for(u32 block = 0; block < height; block += 4)
{ {
for(u32 i = 0; i < width; i += 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); tmpData2 = _genMipMaps(tmpData2, imgProp.imgWidth, imgProp.imgHeight, maxLODTmp, baseWidth, baseHeight);
if(tmpData2 == NULL) if(tmpData2 == NULL)
{
Cleanup();
return TE_NOMEM; return TE_NOMEM;
}
u32 nWidth = newWidth; u32 nWidth = newWidth;
u32 nHeight = newHeight; u32 nHeight = newHeight;
u8 *pSrc = tmpData2; 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); u32 bufSize = fixGX_GetTexBufferSize(lod0Width, lod0Height, GX_TF_RGBA8, GX_TRUE, maxLOD);
u8 *dst = (u8*)MEM2_alloc(bufSize); u8 *dst = (u8*)MEM2_alloc(bufSize);
if(dst == NULL) if(dst == NULL)
return src; {
Cleanup();
return NULL;
}
memset(dst, 0, bufSize); memset(dst, 0, bufSize);
_resize(dst, lod0Width, lod0Height, src, width, height); _resize(dst, lod0Width, lod0Height, src, width, height);
DCFlushRange(dst, lod0Width * lod0Height * 4); DCFlushRange(dst, lod0Width * lod0Height * 4);

View File

@ -80,7 +80,6 @@ const int CVideo::_stencilWidth = 128;
const int CVideo::_stencilHeight = 128; const int CVideo::_stencilHeight = 128;
static lwp_t waitThread = LWP_THREAD_NULL; static lwp_t waitThread = LWP_THREAD_NULL;
u8 *waitThreadStack;
CVideo m_vid; CVideo m_vid;
CVideo::CVideo(void) : CVideo::CVideo(void) :
@ -284,13 +283,16 @@ void CVideo::cleanup(void)
{ {
if(m_defaultWaitMessages[i].data != NULL) if(m_defaultWaitMessages[i].data != NULL)
free(m_defaultWaitMessages[i].data); free(m_defaultWaitMessages[i].data);
m_defaultWaitMessages[i].data = NULL;
} }
if(waitThreadStack != NULL)
free(waitThreadStack);
free(MEM_K1_TO_K0(m_frameBuf[0])); free(MEM_K1_TO_K0(m_frameBuf[0]));
m_frameBuf[0] = NULL;
free(MEM_K1_TO_K0(m_frameBuf[1])); free(MEM_K1_TO_K0(m_frameBuf[1]));
m_frameBuf[1] = NULL;
free(m_stencil); free(m_stencil);
m_stencil = NULL;
free(m_fifo); free(m_fifo);
m_fifo = NULL;
} }
void CVideo::prepareAAPass(int aaStep) void CVideo::prepareAAPass(int aaStep)
@ -558,7 +560,7 @@ void CVideo::hideWaitMessage()
if(LWP_ThreadIsSuspended(waitThread)) if(LWP_ThreadIsSuspended(waitThread))
LWP_ResumeThread(waitThread); LWP_ResumeThread(waitThread);
while(m_showingWaitMessages) while(m_showingWaitMessages)
usleep(100); usleep(50);
LWP_JoinThread(waitThread, NULL); LWP_JoinThread(waitThread, NULL);
} }
waitThread = LWP_THREAD_NULL; waitThread = LWP_THREAD_NULL;
@ -602,9 +604,7 @@ void CVideo::waitMessage(const vector<STexture> &tex, float delay)
else if(m_waitMessages.size() > 1) else if(m_waitMessages.size() > 1)
{ {
m_showWaitMessage = true; m_showWaitMessage = true;
if(waitThreadStack != NULL) LWP_CreateThread(&waitThread, (void *(*)(void *))_showWaitMessages, (void *)this, NULL, 0, LWP_PRIO_HIGHEST);
waitThreadStack = (u8*)MEM2_alloc(8192);
LWP_CreateThread(&waitThread, (void *(*)(void *))_showWaitMessages, (void *)this, waitThreadStack, 8192, LWP_PRIO_HIGHEST);
} }
} }

View File

@ -21,7 +21,6 @@
/* Variables */ /* Variables */
bool reset = false; bool reset = false;
bool shutdown = false; bool shutdown = false;
bool exiting = false;
u8 ExitOption = 0; u8 ExitOption = 0;
const char *NeekPath = NULL; const char *NeekPath = NULL;
@ -61,7 +60,7 @@ void Close_Inputs(void)
bool Sys_Exiting(void) bool Sys_Exiting(void)
{ {
return reset || shutdown || exiting; return reset || shutdown;
} }
void Sys_Shutdown(void) void Sys_Shutdown(void)

View File

@ -33,10 +33,4 @@ unsigned int MEM2_freesize();
} }
#endif #endif
enum Alloc
{
ALLOC_MALLOC,
ALLOC_MEM2,
};
#endif // !defined(__MEM2_HPP) #endif // !defined(__MEM2_HPP)

View File

@ -220,9 +220,6 @@ void CMenu::exitHandler(int ExitTo)
ExitTo = EXIT_TO_HBC; ExitTo = EXIT_TO_HBC;
} }
Sys_ExitTo(ExitTo); Sys_ExitTo(ExitTo);
// Mark exiting to prevent soundhandler from restarting
extern bool exiting;
exiting = true;
} }
int CMenu::main(void) int CMenu::main(void)

View File

@ -147,11 +147,8 @@ void GuiSound::Init()
void GuiSound::FreeMemory() void GuiSound::FreeMemory()
{ {
Stop(); Stop();
if(this->voice != -1)
// Prevent reinitialization of SoundHandler since we're exiting
if(!Sys_Exiting())
SoundHandle.RemoveDecoder(this->voice); SoundHandle.RemoveDecoder(this->voice);
if(allocated && sound != NULL) if(allocated && sound != NULL)
free(sound); free(sound);
allocated = false; allocated = false;