-fixed possible bug in memory allocation (thanks megazig for

hints how to debug better)
-made the global cleanup less unstable
-fixed IOS Reload on game loading codedump
-fixed bug in network init
This commit is contained in:
fix94.1 2012-07-08 13:35:59 +00:00
parent fd30f2aa74
commit 1ad14ce248
8 changed files with 80 additions and 98 deletions

View File

@ -129,8 +129,8 @@ int main(int argc, char **argv)
ret = mainMenu->main(); ret = mainMenu->main();
} }
} }
delete mainMenu;
ISFS_Deinitialize();
Sys_Exit(); Sys_Exit();
exit(1); exit(1);
return 0; return 0;

View File

@ -70,7 +70,7 @@ void *CMEM2Alloc::allocate(unsigned int s)
} }
// Search for a free block // Search for a free block
SBlock *i; SBlock *i;
SBlock *j; SBlock *j = m_first;
for (i = m_first; i != 0; i = i->next) for (i = m_first; i != 0; i = i->next)
{ {
if (i->f && i->s >= s) if (i->f && i->s >= s)

View File

@ -481,45 +481,40 @@ void CMenu::init(void)
bool cleaned_up = false; bool cleaned_up = false;
void CMenu::cleanup(bool ios_reload) void CMenu::cleanup()
{ {
if(cleaned_up) if(cleaned_up)
return; return;
m_cf.stopCoverLoader(); m_cf.stopCoverLoader();
_cleanupDefaultFont();
m_cf.clear(); m_cf.clear();
ClearGameSoundThreadStack();
m_banner->DeleteBanner(); m_banner->DeleteBanner();
m_plugin.Cleanup(); m_plugin.Cleanup();
_stopSounds(); _stopSounds();
delete m_music;
if (!ios_reload)
m_cameraSound.release(); m_cameraSound.release();
ClearGameSoundThreadStack();
m_music->cleanup();
SoundHandler::DestroyInstance(); SoundHandler::DestroyInstance();
soundDeinit(); soundDeinit();
if(!m_reload) if(!m_reload)
{ {
ISFS_Deinitialize();
DeviceHandler::DestroyInstance(); DeviceHandler::DestroyInstance();
m_vid.CheckWaitThread(true);
m_vid.cleanup(); m_vid.cleanup();
wiiLightOff();
} }
wiiLightOff();
_deinitNetwork();
if (!ios_reload)
{
LWP_MutexDestroy(m_mutex); LWP_MutexDestroy(m_mutex);
m_mutex = 0; m_mutex = 0;
}
if (!ios_reload)
_cleanupDefaultFont();
if (!ios_reload || (!m_use_wifi_gecko && ios_reload))
_deinitNetwork();
ClearLogBuffer(); ClearLogBuffer();
Close_Inputs();
cleaned_up = true; cleaned_up = true;
gprintf(" \nMemory cleaned up\n"); gprintf(" \nMemory cleaned up\n");
@ -527,11 +522,11 @@ void CMenu::cleanup(bool ios_reload)
void CMenu::_reload_wifi_gecko(void) void CMenu::_reload_wifi_gecko(void)
{ {
if (m_use_wifi_gecko) if(m_use_wifi_gecko)
{ {
_initAsyncNetwork(); _initAsyncNetwork();
while(net_get_status() == -EBUSY); while(net_get_status() == -EBUSY)
usleep(1000); usleep(100);
} }
} }

View File

@ -47,7 +47,7 @@ public:
void terror(const char *key, const wchar_t *msg) { error(_fmt(key, msg)); } void terror(const char *key, const wchar_t *msg) { error(_fmt(key, msg)); }
void exitHandler(int ExitTo); void exitHandler(int ExitTo);
int main(void); int main(void);
void cleanup(bool ios_reload = false); void cleanup();
u8 m_current_view; u8 m_current_view;
private: private:
struct SZone struct SZone

View File

@ -451,6 +451,8 @@ int CMenu::_initNetwork()
void CMenu::_deinitNetwork() void CMenu::_deinitNetwork()
{ {
while(net_get_status() == -EBUSY)
usleep(100);
net_wc24cleanup(); net_wc24cleanup();
net_deinit(); net_deinit();
m_networkInit = false; m_networkInit = false;

View File

@ -17,6 +17,7 @@
#include "wip.h" #include "wip.h"
#include "channel_launcher.h" #include "channel_launcher.h"
#include "devicemounter/sdhc.h" #include "devicemounter/sdhc.h"
#include "devicemounter/usbstorage.h"
#include "BannerWindow.hpp" #include "BannerWindow.hpp"
#include <network.h> #include <network.h>
@ -772,11 +773,13 @@ void CMenu::_launch(dir_discHdr *hdr)
} }
} }
extern "C" {extern void USBStorage_Deinit(void);}
void CMenu::_launchGC(dir_discHdr *hdr, bool DML) void CMenu::_launchGC(dir_discHdr *hdr, bool DML)
{ {
char* id = (char *)hdr->id; char id[7];
strncpy(id, hdr->id, sizeof(id));
char path[256];
strncpy(path, hdr->path, sizeof(path));
Nand::Instance()->Disable_Emu(); Nand::Instance()->Disable_Emu();
@ -812,23 +815,21 @@ void CMenu::_launchGC(dir_discHdr *hdr, bool DML)
if(cheats) if(cheats)
{ {
snprintf(CheatPath, sizeof(CheatPath), "%s/%s", m_cheatDir.c_str(), fmt("%s.gct", id)); snprintf(CheatPath, sizeof(CheatPath), "%s/%s", m_cheatDir.c_str(), fmt("%s.gct", id));
snprintf(NewCheatPath, sizeof(NewCheatPath), "%s/%s/%s", fmt(DML_DIR, "sd"), hdr->path, fmt("%s.gct", id)); snprintf(NewCheatPath, sizeof(NewCheatPath), "%s/%s/%s", fmt(DML_DIR, "sd"), path, fmt("%s.gct", id));
} }
string newPath;
if(strcasestr(path, "boot.bin") != NULL)
{
newPath = &path[string(path).find_first_of(":/")+1];
newPath.erase(newPath.end() - 12, newPath.end());
}
else
newPath = &path[string(path).find_first_of(":/")+1];
if(m_new_dml) if(m_new_dml)
{ DML_New_SetOptions(newPath.c_str(), CheatPath, NewCheatPath, cheats, DML_debug, NMM, nodisc, DMLvideoMode);
string path;
if(strcasestr(hdr->path, "boot.bin") != NULL)
{
path = &hdr->path[string(hdr->path).find_first_of(":/")+1];
path.erase(path.end() - 12, path.end());
}
else else
path = &hdr->path[string(hdr->path).find_first_of(":/")+1]; DML_Old_SetOptions(path, CheatPath, NewCheatPath, cheats);
DML_New_SetOptions(path.c_str(), CheatPath, NewCheatPath, cheats, DML_debug, NMM, nodisc, DMLvideoMode);
}
else
DML_Old_SetOptions(hdr->path, CheatPath, NewCheatPath, cheats);
if(!nodisc || !m_new_dml) if(!nodisc || !m_new_dml)
{ {
@ -844,9 +845,8 @@ void CMenu::_launchGC(dir_discHdr *hdr, bool DML)
m_gcfg2.save(true); m_gcfg2.save(true);
m_cat.save(true); m_cat.save(true);
m_cfg.save(true); m_cfg.save(true);
cleanup(); cleanup();
Close_Inputs();
USBStorage_Deinit(); USBStorage_Deinit();
SDHC_Init(); SDHC_Init();
@ -876,19 +876,10 @@ void CMenu::_launchHomebrew(const char *filepath, vector<string> arguments)
m_cat.save(true); m_cat.save(true);
m_cfg.save(true); m_cfg.save(true);
while(net_get_status() == -EBUSY)
usleep(100);
m_vid.CheckWaitThread(true);
Playlog_Delete(); Playlog_Delete();
cleanup(); cleanup(); // wifi and sd gecko doesnt work anymore after cleanup
// wifi and sd gecko doesnt work anymore after cleanup
Close_Inputs();
m_vid.cleanup();
wiiLightOff();
LoadHomebrew(filepath); LoadHomebrew(filepath);
DeviceHandler::DestroyInstance();
USBStorage_Deinit(); USBStorage_Deinit();
AddBootArgument(filepath); AddBootArgument(filepath);
for(u32 i = 0; i < arguments.size(); ++i) for(u32 i = 0; i < arguments.size(); ++i)
@ -978,7 +969,7 @@ void CMenu::_launchChannel(dir_discHdr *hdr)
u32 entry = 0; u32 entry = 0;
Nand::Instance()->Disable_Emu(); Nand::Instance()->Disable_Emu();
string id = string((const char *)hdr->id); string id = string(hdr->id);
bool forwarder = true; bool forwarder = true;
for (u8 num = 0; num < ARRAY_SIZE(systems); num++) for (u8 num = 0; num < ARRAY_SIZE(systems); num++)
@ -1032,17 +1023,13 @@ void CMenu::_launchChannel(dir_discHdr *hdr)
int emulate_mode = min(max(0, m_cfg.getInt("NAND", "emulation", 1)), (int)ARRAY_SIZE(CMenu::_NandEmu) - 1); int emulate_mode = min(max(0, m_cfg.getInt("NAND", "emulation", 1)), (int)ARRAY_SIZE(CMenu::_NandEmu) - 1);
int userIOS = m_gcfg2.getInt(id, "ios", 0); int userIOS = m_gcfg2.getInt(id, "ios", 0);
u64 gameTitle = TITLE_ID(hdr->settings[0],hdr->settings[1]);
m_gcfg1.save(true); m_gcfg1.save(true);
m_gcfg2.save(true); m_gcfg2.save(true);
m_cat.save(true); m_cat.save(true);
m_cfg.save(true); m_cfg.save(true);
CheckGameSoundThread();
m_vid.CheckWaitThread(true);
cleanup(); cleanup();
USBStorage_Deinit();
Close_Inputs();
if(!emu_disabled) if(!emu_disabled)
{ {
@ -1065,13 +1052,13 @@ void CMenu::_launchChannel(dir_discHdr *hdr)
if(!forwarder) if(!forwarder)
{ {
entry = channel.Load(TITLE_ID(hdr->settings[0],hdr->settings[1]), &ios); entry = channel.Load(gameTitle, &ios);
setLanguage(language); setLanguage(language);
SmartBuf cheatFile; SmartBuf cheatFile;
u32 cheatSize = 0; u32 cheatSize = 0;
if (cheat) if (cheat)
_loadFile(cheatFile, cheatSize, m_cheatDir.c_str(), fmt("%s.gct", hdr->id)); _loadFile(cheatFile, cheatSize, m_cheatDir.c_str(), fmt("%s.gct", id.c_str()));
ocarina_load_code(cheatFile.get(), cheatSize); ocarina_load_code(cheatFile.get(), cheatSize);
@ -1157,17 +1144,22 @@ void CMenu::_launchChannel(dir_discHdr *hdr)
if(forwarder) if(forwarder)
{ {
WII_Initialize(); WII_Initialize();
if(WII_LaunchTitle(TITLE_ID(hdr->settings[0],hdr->settings[1])) < 0) if(WII_LaunchTitle(gameTitle) < 0)
Sys_LoadMenu(); Sys_LoadMenu();
} }
if(!BootChannel(entry, TITLE_ID(hdr->settings[0],hdr->settings[1]), ios, videoMode, vipatch, countryPatch, patchVidMode, aspectRatio)) if(!BootChannel(entry, gameTitle, ios, videoMode, vipatch, countryPatch, patchVidMode, aspectRatio))
Sys_LoadMenu(); Sys_LoadMenu();
} }
void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
{ {
string id = string((const char *) hdr->id); char id[7];
strncpy(id, hdr->id, sizeof(id));
char path[256];
strncpy(path, hdr->path, sizeof(path));
Nand::Instance()->Disable_Emu(); Nand::Instance()->Disable_Emu();
if (dvd) if (dvd)
@ -1208,7 +1200,7 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
/* Read GC disc header */ /* Read GC disc header */
struct gc_discHdr *gcHeader = (struct gc_discHdr *)MEM2_alloc(sizeof(struct gc_discHdr)); struct gc_discHdr *gcHeader = (struct gc_discHdr *)MEM2_alloc(sizeof(struct gc_discHdr));
Disc_ReadGCHeader(gcHeader); Disc_ReadGCHeader(gcHeader);
memcpy(hdr->id, gcHeader->id, 6); memcpy(id, gcHeader->id, 6);
MEM2_free(gcHeader); MEM2_free(gcHeader);
/* Launching GC Game */ /* Launching GC Game */
_launchGC(hdr, false); _launchGC(hdr, false);
@ -1300,7 +1292,7 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
} }
} }
if (!dvd && get_frag_list((u8 *)hdr->id, (char *) hdr->path, currentPartition == 0 ? 0x200 : sector_size) < 0) if(!dvd && get_frag_list((u8 *)id, path, currentPartition == 0 ? 0x200 : sector_size) < 0)
return; return;
u8 patchVidMode = min((u32)m_gcfg2.getInt(id, "patch_video_modes", 0), ARRAY_SIZE(CMenu::_vidModePatch) - 1u); u8 patchVidMode = min((u32)m_gcfg2.getInt(id, "patch_video_modes", 0), ARRAY_SIZE(CMenu::_vidModePatch) - 1u);
@ -1310,7 +1302,7 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
if ((debuggerselect || cheat) && hooktype == 0) hooktype = 1; if ((debuggerselect || cheat) && hooktype == 0) hooktype = 1;
if (!debuggerselect && !cheat) hooktype = 0; if (!debuggerselect && !cheat) hooktype = 0;
if (id == "RPWE41" || id == "RPWZ41" || id == "SPXP41") // Prince of Persia, Rival Swords if(strstr(id, "RPWE41") || strstr(id, "RPWZ41") || strstr(id, "SPXP41")) // Prince of Persia, Rival Swords
debuggerselect = false; debuggerselect = false;
SmartBuf cheatFile, gameconfig; SmartBuf cheatFile, gameconfig;
@ -1322,38 +1314,36 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
m_gcfg1.setUInt("LASTPLAYED", id, time(NULL)); m_gcfg1.setUInt("LASTPLAYED", id, time(NULL));
if(has_enabled_providers() && _initNetwork() == 0) if(has_enabled_providers() && _initNetwork() == 0)
add_game_to_card(id.c_str()); add_game_to_card(id);
int userIOS = 0; int userIOS = 0;
m_gcfg2.getInt(id, "ios", &userIOS); m_gcfg2.getInt(id, "ios", &userIOS);
setLanguage(language);
if(cheat)
_loadFile(cheatFile, cheatSize, m_cheatDir.c_str(), fmt("%s.gct", id));
_loadFile(gameconfig, gameconfigSize, m_txtCheatDir.c_str(), "gameconfig.txt");
load_wip_patches((u8 *)m_wipDir.c_str(), (u8 *) &id);
app_gameconfig_load((u8 *) &id, gameconfig.get(), gameconfigSize);
ocarina_load_code(cheatFile.get(), cheatSize);
u8 gameIOS = GetRequestedGameIOS(hdr);
m_gcfg1.save(true); m_gcfg1.save(true);
m_gcfg2.save(true); m_gcfg2.save(true);
m_cat.save(true); m_cat.save(true);
m_cfg.save(true); m_cfg.save(true);
cleanup(); // wifi and sd gecko doesnt work anymore after cleanup
setLanguage(language);
if(cheat)
_loadFile(cheatFile, cheatSize, m_cheatDir.c_str(), fmt("%s.gct", hdr->id));
_loadFile(gameconfig, gameconfigSize, m_txtCheatDir.c_str(), "gameconfig.txt");
load_wip_patches((u8 *)m_wipDir.c_str(), (u8 *) &hdr->id);
app_gameconfig_load((u8 *) &hdr->id, gameconfig.get(), gameconfigSize);
ocarina_load_code(cheatFile.get(), cheatSize);
if (!m_use_wifi_gecko)
net_wc24cleanup();
bool iosLoaded = false; bool iosLoaded = false;
if (!dvd) if(!dvd)
{ {
int result = _loadIOS(GetRequestedGameIOS(hdr), userIOS, id); int result = _loadIOS(gameIOS, userIOS, id);
if (result == LOAD_IOS_FAILED) if(result == LOAD_IOS_FAILED)
return; return;
if (result == LOAD_IOS_SUCCEEDED) if(result == LOAD_IOS_SUCCEEDED)
iosLoaded = true; iosLoaded = true;
} }
@ -1373,7 +1363,7 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
{ {
Nand::Instance()->Disable_Emu(); Nand::Instance()->Disable_Emu();
error(_t("errgame6", L"Enabling emu after reload failed!")); error(_t("errgame6", L"Enabling emu after reload failed!"));
if (iosLoaded) Sys_LoadMenu(); Sys_LoadMenu();
return; return;
} }
if(!DeviceHandler::Instance()->IsInserted(currentPartition)) if(!DeviceHandler::Instance()->IsInserted(currentPartition))
@ -1402,7 +1392,7 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
if (!dvd) if (!dvd)
{ {
s32 ret = Disc_SetUSB((u8 *)hdr->id); s32 ret = Disc_SetUSB((u8 *)id);
if (ret < 0) if (ret < 0)
{ {
gprintf("Set USB failed: %d\n", ret); gprintf("Set USB failed: %d\n", ret);
@ -1420,13 +1410,6 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
} }
IOSReloadBlock(IOS_GetVersion(), true); IOSReloadBlock(IOS_GetVersion(), true);
while(net_get_status() == -EBUSY)
usleep(100);
m_vid.CheckWaitThread(true);
cleanup();
// wifi and sd gecko doesnt work anymore after cleanup
Close_Inputs();
USBStorage_Deinit(); USBStorage_Deinit();
if(currentPartition == 0) if(currentPartition == 0)
SDHC_Init(); SDHC_Init();

View File

@ -836,8 +836,10 @@ int CMenu::main(void)
coverStatus = LWP_THREAD_NULL; coverStatus = LWP_THREAD_NULL;
if(coverstatus_stack.get()) if(coverstatus_stack.get())
coverstatus_stack.release(); coverstatus_stack.release();
if(!m_reload)
return 0;
cleanup(); cleanup();
return m_reload ? 1 : 0; return 1;
} }
void CMenu::_initMainMenu(CMenu::SThemeData &theme) void CMenu::_initMainMenu(CMenu::SThemeData &theme)

View File

@ -19,6 +19,8 @@ class MusicPlayer
{ {
public: public:
MusicPlayer(); MusicPlayer();
~MusicPlayer();
void cleanup(); void cleanup();
void Init(Config &cfg, std::string musicDir, std::string themeMusicDir); void Init(Config &cfg, std::string musicDir, std::string themeMusicDir);
void Tick(bool attenuate); void Tick(bool attenuate);
@ -36,8 +38,6 @@ public:
bool IsStopped() { return m_stopped; }; bool IsStopped() { return m_stopped; };
private: private:
~MusicPlayer();
void LoadCurrentFile(); void LoadCurrentFile();
CachedList<std::string> m_music_files; CachedList<std::string> m_music_files;