Core: Fix crashes if core directories aren't set

This commit is contained in:
Vicki Pfau 2019-06-01 11:08:28 -07:00
parent 3cce95b287
commit 5436d2576f
2 changed files with 10 additions and 0 deletions

View File

@ -26,6 +26,7 @@ Other fixes:
- Core: Improved lockstep driver reliability (Le Hoang Quyen)
- Switch: Fix threading-related crash on second launch
- Qt: Fix FPS target maxing out at 59.727 (fixes mgba.io/i/1421)
- Core: Fix crashes if core directories aren't set
Misc:
- GBA Savedata: EEPROM performance fixes
- GBA Savedata: Automatically map 1Mbit Flash files as 1Mbit Flash

View File

@ -157,10 +157,16 @@ bool mCorePreloadFile(struct mCore* core, const char* path) {
}
bool mCoreAutoloadSave(struct mCore* core) {
if (!core->dirs.save) {
return false;
}
return core->loadSave(core, mDirectorySetOpenSuffix(&core->dirs, core->dirs.save, ".sav", O_CREAT | O_RDWR));
}
bool mCoreAutoloadPatch(struct mCore* core) {
if (!core->dirs.patch) {
return false;
}
return core->loadPatch(core, mDirectorySetOpenSuffix(&core->dirs, core->dirs.patch, ".ups", O_RDONLY)) ||
core->loadPatch(core, mDirectorySetOpenSuffix(&core->dirs, core->dirs.patch, ".ips", O_RDONLY)) ||
core->loadPatch(core, mDirectorySetOpenSuffix(&core->dirs, core->dirs.patch, ".bps", O_RDONLY));
@ -217,6 +223,9 @@ bool mCoreLoadState(struct mCore* core, int slot, int flags) {
}
struct VFile* mCoreGetState(struct mCore* core, int slot, bool write) {
if (!core->dirs.state) {
return NULL;
}
char name[PATH_MAX + 14]; // Quash warning
snprintf(name, sizeof(name), "%s.ss%i", core->dirs.baseName, slot);
return core->dirs.state->openFile(core->dirs.state, name, write ? (O_CREAT | O_TRUNC | O_RDWR) : O_RDONLY);