Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit b3f120b

Browse files
committed
Fixed SoundOverlapMode and SoundSelectionCycleMode reading, hopefully properly this time
1 parent b5c8418 commit b3f120b

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

Entities/SoundContainer.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ namespace RTE {
7070
std::string soundOverlapModeString = reader.ReadPropValue();
7171
if (c_SoundOverlapModeMap.find(soundOverlapModeString) != c_SoundOverlapModeMap.end()) {
7272
m_SoundOverlapMode = c_SoundOverlapModeMap.find(soundOverlapModeString)->second;
73-
} else if (std::stoi(soundOverlapModeString)) {
74-
m_SoundOverlapMode = static_cast<SoundOverlapMode>(std::stoi(soundOverlapModeString));
7573
} else {
76-
reader.ReportError("Cycle mode " + soundOverlapModeString + " is invalid.");
74+
try {
75+
m_SoundOverlapMode = static_cast<SoundOverlapMode>(std::stoi(soundOverlapModeString));
76+
} catch (const std::exception &) {
77+
reader.ReportError("Cycle mode " + soundOverlapModeString + " is invalid.");
78+
}
7779
}
7880
} else if (propName == "Immobile") {
7981
reader >> m_Immobile;

Entities/SoundSet.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,21 @@ namespace RTE {
101101
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
102102

103103
SoundSet::SoundSelectionCycleMode SoundSet::ReadSoundSelectionCycleMode(Reader &reader) {
104+
SoundSelectionCycleMode soundSelectionCycleModeToReturn;
104105
std::string soundSelectionCycleModeString = reader.ReadPropValue();
105106

106107
std::unordered_map<std::string, SoundSelectionCycleMode>::const_iterator soundSelectionCycleMode = c_SoundSelectionCycleModeMap.find(soundSelectionCycleModeString);
107108
if (soundSelectionCycleMode != c_SoundSelectionCycleModeMap.end()) {
108-
return soundSelectionCycleMode->second;
109-
} else if (std::stoi(soundSelectionCycleModeString)) {
110-
return static_cast<SoundSelectionCycleMode>(std::stoi(soundSelectionCycleModeString));
109+
soundSelectionCycleModeToReturn = soundSelectionCycleMode->second;
110+
} else {
111+
try {
112+
soundSelectionCycleModeToReturn = static_cast<SoundSelectionCycleMode>(std::stoi(soundSelectionCycleModeString));
113+
} catch (const std::exception &) {
114+
reader.ReportError("Sound selection cycle mode " + soundSelectionCycleModeString + " is invalid.");
115+
}
111116
}
112-
113-
reader.ReportError("Sound selection cycle mode " + soundSelectionCycleModeString + " is invalid.");
114-
return SoundSelectionCycleMode::RANDOM;
117+
118+
return soundSelectionCycleModeToReturn;
115119
}
116120

117121
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)