Skip to content

Commit

Permalink
fix one potential crash bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Arisotura committed Jun 15, 2024
1 parent 8fc403c commit ccc5c95
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
12 changes: 1 addition & 11 deletions src/frontend/qt_sdl/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,19 +723,9 @@ bool Load()
void Save()
{
auto cfgpath = Platform::GetLocalFilePath(kConfigFile);
printf("save\n");
if (!Platform::CheckFileWritable(cfgpath))
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;
file.open(cfgpath, std::ofstream::out | std::ofstream::trunc);
file << RootTable;
Expand Down
36 changes: 26 additions & 10 deletions src/frontend/qt_sdl/EmuInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ EmuInstance::EmuInstance(int inst) : instanceID(inst),
globalCfg(Config::GetGlobalTable()),
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;
cheatsOn = localCfg.GetBool("EnableCheats");

Expand Down Expand Up @@ -506,7 +520,7 @@ std::string EmuInstance::getEffectiveFirmwareSavePath()
{
return kWifiSettingsPath;
}
if (nds->ConsoleType == 1)
if (consoleType == 1)
{
return globalCfg.GetString("DSi.FirmwarePath");
}
Expand Down Expand Up @@ -1016,7 +1030,7 @@ ARCodeFile* EmuInstance::getCheatFile()

void EmuInstance::setBatteryLevels()
{
if (nds->ConsoleType == 1)
if (consoleType == 1)
{
auto dsi = static_cast<DSi*>(nds);
dsi->I2C.GetBPTWL()->SetBatteryLevel(localCfg.GetInt("DSi.Battery.Level"));
Expand Down Expand Up @@ -1158,7 +1172,7 @@ bool EmuInstance::updateConsole(UpdateConsoleNDSArgs&& _ndsargs, UpdateConsoleGB
}


if ((!nds) || (consoletype != nds->ConsoleType))
if ((!nds) || (consoletype != consoleType))
{
NDS::Current = nullptr;
if (nds) delete nds;
Expand Down Expand Up @@ -1204,9 +1218,11 @@ bool EmuInstance::updateConsole(UpdateConsoleNDSArgs&& _ndsargs, UpdateConsoleGB

void EmuInstance::reset()
{
consoleType = globalCfg.GetInt("Emu.ConsoleType");

updateConsole(Keep {}, Keep {});

if (nds->ConsoleType == 1) ejectGBACart();
if (consoleType == 1) ejectGBACart();

nds->Reset();
setBatteryLevels();
Expand Down Expand Up @@ -1237,7 +1253,7 @@ void EmuInstance::reset()
string newsave;
if (globalCfg.GetBool("Emu.ExternalBIOSEnable"))
{
if (nds->ConsoleType == 1)
if (consoleType == 1)
newsave = globalCfg.GetString("DSi.FirmwarePath") + instanceFileSuffix();
else
newsave = globalCfg.GetString("DS.FirmwarePath") + instanceFileSuffix();
Expand Down Expand Up @@ -1381,7 +1397,7 @@ pair<unique_ptr<Firmware>, string> EmuInstance::generateDefaultFirmware()
{
// Construct the default firmware...
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);

// Try to open the instanced Wi-fi settings, falling back to the regular Wi-fi settings if they don't exist.
Expand Down Expand Up @@ -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());

firmware->GetAccessPoints() = {
Firmware::WifiAccessPoint(nds->ConsoleType),
Firmware::WifiAccessPoint(consoleType),
Firmware::WifiAccessPoint(),
Firmware::WifiAccessPoint(),
};
Expand Down Expand Up @@ -1789,7 +1805,7 @@ QString EmuInstance::cartLabel()

bool EmuInstance::loadGBAROM(QStringList filepath)
{
if (nds->ConsoleType == 1)
if (consoleType == 1)
{
QMessageBox::critical(mainWindow, "melonDS", "The DSi doesn't have a GBA slot.");
return false;
Expand Down Expand Up @@ -1864,7 +1880,7 @@ bool EmuInstance::loadGBAROM(QStringList filepath)

void EmuInstance::loadGBAAddon(int type)
{
if (nds->ConsoleType == 1) return;
if (consoleType == 1) return;

gbaSave = nullptr;

Expand Down Expand Up @@ -1895,7 +1911,7 @@ bool EmuInstance::gbaCartInserted()

QString EmuInstance::gbaCartLabel()
{
if (nds->ConsoleType == 1) return "none (DSi)";
if (consoleType == 1) return "none (DSi)";

switch (gbaCartType)
{
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/qt_sdl/EmuInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class EmuInstance
~EmuInstance();

int getInstanceID() { return instanceID; }
int getConsoleType() { return consoleType; }
EmuThread* getEmuThread() { return emuThread; }
melonDS::NDS* getNDS() { return nds; }

Expand Down Expand Up @@ -225,6 +226,7 @@ class EmuInstance
Config::Table globalCfg;
Config::Table localCfg;

int consoleType;
melonDS::NDS* nds;

int cartType;
Expand Down

0 comments on commit ccc5c95

Please sign in to comment.