summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Morph2022-01-09 16:43:06 -0800
committerGravatar GitHub2022-01-09 16:43:06 -0800
commit18adea343ebd77dce1180942fc773ec891153ff8 (patch)
treeb3a224c730c7201f2bcc8b8c309cbc0be2cfd2f9
parentMerge pull request #7682 from german77/udp_fix (diff)
parentinput_common: Handle errors on TAS scripts (diff)
downloadyuzu-18adea343ebd77dce1180942fc773ec891153ff8.tar.gz
yuzu-18adea343ebd77dce1180942fc773ec891153ff8.tar.xz
yuzu-18adea343ebd77dce1180942fc773ec891153ff8.zip
Merge pull request #7687 from german77/tas_handle
input_common: Handle errors on TAS scripts
Diffstat (limited to '')
-rw-r--r--src/input_common/drivers/tas_input.cpp31
1 files changed, 24 insertions, 7 deletions
diff --git a/src/input_common/drivers/tas_input.cpp b/src/input_common/drivers/tas_input.cpp
index 5bdd5dac3..d78228b50 100644
--- a/src/input_common/drivers/tas_input.cpp
+++ b/src/input_common/drivers/tas_input.cpp
@@ -105,10 +105,16 @@ void Tas::LoadTasFile(size_t player_index, size_t file_index) {
105 continue; 105 continue;
106 } 106 }
107 107
108 const auto num_frames = std::stoi(seg_list[0]); 108 try {
109 while (frame_no < num_frames) { 109 const auto num_frames = std::stoi(seg_list[0]);
110 commands[player_index].emplace_back(); 110 while (frame_no < num_frames) {
111 frame_no++; 111 commands[player_index].emplace_back();
112 frame_no++;
113 }
114 } catch (const std::invalid_argument&) {
115 LOG_ERROR(Input, "Invalid argument: '{}' at command {}", seg_list[0], frame_no);
116 } catch (const std::out_of_range&) {
117 LOG_ERROR(Input, "Out of range: '{}' at command {}", seg_list[0], frame_no);
112 } 118 }
113 119
114 TASCommand command = { 120 TASCommand command = {
@@ -233,10 +239,21 @@ TasAnalog Tas::ReadCommandAxis(const std::string& line) const {
233 } 239 }
234 } 240 }
235 241
236 const float x = std::stof(seg_list.at(0)) / 32767.0f; 242 if (seg_list.size() < 2) {
237 const float y = std::stof(seg_list.at(1)) / 32767.0f; 243 LOG_ERROR(Input, "Invalid axis data: '{}'", line);
244 return {};
245 }
238 246
239 return {x, y}; 247 try {
248 const float x = std::stof(seg_list.at(0)) / 32767.0f;
249 const float y = std::stof(seg_list.at(1)) / 32767.0f;
250 return {x, y};
251 } catch (const std::invalid_argument&) {
252 LOG_ERROR(Input, "Invalid argument: '{}'", line);
253 } catch (const std::out_of_range&) {
254 LOG_ERROR(Input, "Out of range: '{}'", line);
255 }
256 return {};
240} 257}
241 258
242u64 Tas::ReadCommandButtons(const std::string& line) const { 259u64 Tas::ReadCommandButtons(const std::string& line) const {