fix one potential crash bug

This commit is contained in:
Arisotura 2024-06-15 17:42:26 +02:00
parent 8fc403cdad
commit ccc5c955e9
3 changed files with 28 additions and 20 deletions

View File

@ -723,19 +723,9 @@ bool Load()
void Save() void Save()
{ {
auto cfgpath = Platform::GetLocalFilePath(kConfigFile); auto cfgpath = Platform::GetLocalFilePath(kConfigFile);
printf("save\n");
if (!Platform::CheckFileWritable(cfgpath)) if (!Platform::CheckFileWritable(cfgpath))
return; return;
printf("zirz\n");
/*RootTable["test"] = 4444;
RootTable["teste.derp"] = 5555;
RootTable["testa"]["fazil"] = 6666;*/
//std::string derp = "sfsdf";
//toml::serializer<std::string> vorp(RootTable);
//toml::serializer<toml::string> zarp;
//std::cout << RootTable;
printf("blarg\n");
std::ofstream file; std::ofstream file;
file.open(cfgpath, std::ofstream::out | std::ofstream::trunc); file.open(cfgpath, std::ofstream::out | std::ofstream::trunc);
file << RootTable; file << RootTable;

View File

@ -68,6 +68,20 @@ EmuInstance::EmuInstance(int inst) : instanceID(inst),
globalCfg(Config::GetGlobalTable()), globalCfg(Config::GetGlobalTable()),
localCfg(Config::GetLocalTable(inst)) localCfg(Config::GetLocalTable(inst))
{ {
consoleType = globalCfg.GetInt("Emu.ConsoleType");
ndsSave = nullptr;
cartType = -1;
baseROMDir = "";
baseROMName = "";
baseAssetName = "";
gbaSave = nullptr;
gbaCartType = -1;
baseGBAROMDir = "";
baseGBAROMName = "";
baseGBAAssetName = "";
cheatFile = nullptr; cheatFile = nullptr;
cheatsOn = localCfg.GetBool("EnableCheats"); cheatsOn = localCfg.GetBool("EnableCheats");
@ -506,7 +520,7 @@ std::string EmuInstance::getEffectiveFirmwareSavePath()
{ {
return kWifiSettingsPath; return kWifiSettingsPath;
} }
if (nds->ConsoleType == 1) if (consoleType == 1)
{ {
return globalCfg.GetString("DSi.FirmwarePath"); return globalCfg.GetString("DSi.FirmwarePath");
} }
@ -1016,7 +1030,7 @@ ARCodeFile* EmuInstance::getCheatFile()
void EmuInstance::setBatteryLevels() void EmuInstance::setBatteryLevels()
{ {
if (nds->ConsoleType == 1) if (consoleType == 1)
{ {
auto dsi = static_cast<DSi*>(nds); auto dsi = static_cast<DSi*>(nds);
dsi->I2C.GetBPTWL()->SetBatteryLevel(localCfg.GetInt("DSi.Battery.Level")); dsi->I2C.GetBPTWL()->SetBatteryLevel(localCfg.GetInt("DSi.Battery.Level"));
@ -1158,7 +1172,7 @@ bool EmuInstance::updateConsole(UpdateConsoleNDSArgs&& _ndsargs, UpdateConsoleGB
} }
if ((!nds) || (consoletype != nds->ConsoleType)) if ((!nds) || (consoletype != consoleType))
{ {
NDS::Current = nullptr; NDS::Current = nullptr;
if (nds) delete nds; if (nds) delete nds;
@ -1204,9 +1218,11 @@ bool EmuInstance::updateConsole(UpdateConsoleNDSArgs&& _ndsargs, UpdateConsoleGB
void EmuInstance::reset() void EmuInstance::reset()
{ {
consoleType = globalCfg.GetInt("Emu.ConsoleType");
updateConsole(Keep {}, Keep {}); updateConsole(Keep {}, Keep {});
if (nds->ConsoleType == 1) ejectGBACart(); if (consoleType == 1) ejectGBACart();
nds->Reset(); nds->Reset();
setBatteryLevels(); setBatteryLevels();
@ -1237,7 +1253,7 @@ void EmuInstance::reset()
string newsave; string newsave;
if (globalCfg.GetBool("Emu.ExternalBIOSEnable")) if (globalCfg.GetBool("Emu.ExternalBIOSEnable"))
{ {
if (nds->ConsoleType == 1) if (consoleType == 1)
newsave = globalCfg.GetString("DSi.FirmwarePath") + instanceFileSuffix(); newsave = globalCfg.GetString("DSi.FirmwarePath") + instanceFileSuffix();
else else
newsave = globalCfg.GetString("DS.FirmwarePath") + instanceFileSuffix(); newsave = globalCfg.GetString("DS.FirmwarePath") + instanceFileSuffix();
@ -1381,7 +1397,7 @@ pair<unique_ptr<Firmware>, string> EmuInstance::generateDefaultFirmware()
{ {
// Construct the default firmware... // Construct the default firmware...
string settingspath; string settingspath;
std::unique_ptr<Firmware> firmware = std::make_unique<Firmware>(nds->ConsoleType); std::unique_ptr<Firmware> firmware = std::make_unique<Firmware>(consoleType);
assert(firmware->Buffer() != nullptr); assert(firmware->Buffer() != nullptr);
// Try to open the instanced Wi-fi settings, falling back to the regular Wi-fi settings if they don't exist. // Try to open the instanced Wi-fi settings, falling back to the regular Wi-fi settings if they don't exist.
@ -1412,7 +1428,7 @@ pair<unique_ptr<Firmware>, string> EmuInstance::generateDefaultFirmware()
Platform::Log(Platform::LogLevel::Warn, "Failed to read Wi-fi settings from \"%s\"; using defaults instead\n", wfcsettingspath.c_str()); Platform::Log(Platform::LogLevel::Warn, "Failed to read Wi-fi settings from \"%s\"; using defaults instead\n", wfcsettingspath.c_str());
firmware->GetAccessPoints() = { firmware->GetAccessPoints() = {
Firmware::WifiAccessPoint(nds->ConsoleType), Firmware::WifiAccessPoint(consoleType),
Firmware::WifiAccessPoint(), Firmware::WifiAccessPoint(),
Firmware::WifiAccessPoint(), Firmware::WifiAccessPoint(),
}; };
@ -1789,7 +1805,7 @@ QString EmuInstance::cartLabel()
bool EmuInstance::loadGBAROM(QStringList filepath) bool EmuInstance::loadGBAROM(QStringList filepath)
{ {
if (nds->ConsoleType == 1) if (consoleType == 1)
{ {
QMessageBox::critical(mainWindow, "melonDS", "The DSi doesn't have a GBA slot."); QMessageBox::critical(mainWindow, "melonDS", "The DSi doesn't have a GBA slot.");
return false; return false;
@ -1864,7 +1880,7 @@ bool EmuInstance::loadGBAROM(QStringList filepath)
void EmuInstance::loadGBAAddon(int type) void EmuInstance::loadGBAAddon(int type)
{ {
if (nds->ConsoleType == 1) return; if (consoleType == 1) return;
gbaSave = nullptr; gbaSave = nullptr;
@ -1895,7 +1911,7 @@ bool EmuInstance::gbaCartInserted()
QString EmuInstance::gbaCartLabel() QString EmuInstance::gbaCartLabel()
{ {
if (nds->ConsoleType == 1) return "none (DSi)"; if (consoleType == 1) return "none (DSi)";
switch (gbaCartType) switch (gbaCartType)
{ {

View File

@ -78,6 +78,7 @@ public:
~EmuInstance(); ~EmuInstance();
int getInstanceID() { return instanceID; } int getInstanceID() { return instanceID; }
int getConsoleType() { return consoleType; }
EmuThread* getEmuThread() { return emuThread; } EmuThread* getEmuThread() { return emuThread; }
melonDS::NDS* getNDS() { return nds; } melonDS::NDS* getNDS() { return nds; }
@ -225,6 +226,7 @@ private:
Config::Table globalCfg; Config::Table globalCfg;
Config::Table localCfg; Config::Table localCfg;
int consoleType;
melonDS::NDS* nds; melonDS::NDS* nds;
int cartType; int cartType;