From d9018e2d2ee25c9bf9f4cf467505dbff56726af6 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sat, 1 Sep 2018 20:45:46 -0700 Subject: [PATCH] Fix NameDB and Voice related crashes --- lib/AudioGroup.cpp | 2 +- lib/AudioGroupProject.cpp | 15 ++++++++++----- lib/AudioGroupSampleDirectory.cpp | 3 ++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/AudioGroup.cpp b/lib/AudioGroup.cpp index 3b67ba3..bce8544 100644 --- a/lib/AudioGroup.cpp +++ b/lib/AudioGroup.cpp @@ -63,7 +63,7 @@ std::pair, const unsigned char*> const_cast(sample)->loadLooseData(basePath); return {sample->m_data, sample->m_data->m_looseData.get()}; } - return std::make_pair(ObjToken(), m_samp + sample->m_data->m_sampleOff); + return {sample->m_data, m_samp + sample->m_data->m_sampleOff}; } SampleFileState AudioGroup::getSampleFileState(SampleId sfxId, const SampleEntry* sample, SystemString* pathOut) const diff --git a/lib/AudioGroupProject.cpp b/lib/AudioGroupProject.cpp index aaea340..1b1d6cf 100644 --- a/lib/AudioGroupProject.cpp +++ b/lib/AudioGroupProject.cpp @@ -46,7 +46,8 @@ static void ReadRangedObjectIds(NameDB* db, athena::io::IStreamReader& r, NameDB useId.id |= 0x8000; else if (tp == NameDB::Type::Keymap) useId.id |= 0x4000; - db->registerPair(NameDB::generateName(useId, tp), useId); + if (db) + db->registerPair(NameDB::generateName(useId, tp), useId); } } else @@ -55,7 +56,8 @@ static void ReadRangedObjectIds(NameDB* db, athena::io::IStreamReader& r, NameDB id |= 0x8000; else if (tp == NameDB::Type::Keymap) id |= 0x4000; - db->registerPair(NameDB::generateName(id, tp), id); + if (db) + db->registerPair(NameDB::generateName(id, tp), id); } } @@ -97,7 +99,8 @@ AudioGroupProject::AudioGroupProject(athena::io::IStreamReader& r, GCNDataTag) GroupHeader header; header.read(r); - GroupId::CurNameDB->registerPair(NameDB::generateName(header.groupId, NameDB::Type::Group), header.groupId); + if (GroupId::CurNameDB) + GroupId::CurNameDB->registerPair(NameDB::generateName(header.groupId, NameDB::Type::Group), header.groupId); /* Sound Macros */ r.seek(header.soundMacroIdsOff, athena::Begin); @@ -156,7 +159,8 @@ AudioGroupProject::AudioGroupProject(athena::io::IStreamReader& r, GCNDataTag) std::array& setup = idx->m_midiSetups[songId]; for (int i = 0; i < 16 ; ++i) setup[i].read(r); - SongId::CurNameDB->registerPair(NameDB::generateName(songId, NameDB::Type::Song), songId); + if (SongId::CurNameDB) + SongId::CurNameDB->registerPair(NameDB::generateName(songId, NameDB::Type::Song), songId); } } else if (header.type == GroupType::SFX) @@ -174,7 +178,8 @@ AudioGroupProject::AudioGroupProject(athena::io::IStreamReader& r, GCNDataTag) SFXGroupIndex::SFXEntryDNA entry; entry.read(r); idx->m_sfxEntries[entry.sfxId.id] = entry; - SFXId::CurNameDB->registerPair( + if (SFXId::CurNameDB) + SFXId::CurNameDB->registerPair( NameDB::generateName(entry.sfxId.id, NameDB::Type::SFX), entry.sfxId.id); } } diff --git a/lib/AudioGroupSampleDirectory.cpp b/lib/AudioGroupSampleDirectory.cpp index a251ae0..42badb1 100644 --- a/lib/AudioGroupSampleDirectory.cpp +++ b/lib/AudioGroupSampleDirectory.cpp @@ -51,7 +51,8 @@ AudioGroupSampleDirectory::AudioGroupSampleDirectory(athena::io::IStreamReader& EntryDNA ent; ent.read(r); m_entries[ent.m_sfxId] = MakeObj(ent); - SampleId::CurNameDB->registerPair(NameDB::generateName(ent.m_sfxId, NameDB::Type::Sample), ent.m_sfxId); + if (SampleId::CurNameDB) + SampleId::CurNameDB->registerPair(NameDB::generateName(ent.m_sfxId, NameDB::Type::Sample), ent.m_sfxId); } for (auto& p : m_entries)