Merge pull request #7687 from german77/tas_handle

input_common: Handle errors on TAS scripts
This commit is contained in:
Morph 2022-01-09 16:43:06 -08:00 committed by GitHub
commit 18adea343e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 7 deletions

View File

@ -105,10 +105,16 @@ void Tas::LoadTasFile(size_t player_index, size_t file_index) {
continue; continue;
} }
const auto num_frames = std::stoi(seg_list[0]); try {
while (frame_no < num_frames) { const auto num_frames = std::stoi(seg_list[0]);
commands[player_index].emplace_back(); while (frame_no < num_frames) {
frame_no++; commands[player_index].emplace_back();
frame_no++;
}
} catch (const std::invalid_argument&) {
LOG_ERROR(Input, "Invalid argument: '{}' at command {}", seg_list[0], frame_no);
} catch (const std::out_of_range&) {
LOG_ERROR(Input, "Out of range: '{}' at command {}", seg_list[0], frame_no);
} }
TASCommand command = { TASCommand command = {
@ -233,10 +239,21 @@ TasAnalog Tas::ReadCommandAxis(const std::string& line) const {
} }
} }
const float x = std::stof(seg_list.at(0)) / 32767.0f; if (seg_list.size() < 2) {
const float y = std::stof(seg_list.at(1)) / 32767.0f; LOG_ERROR(Input, "Invalid axis data: '{}'", line);
return {};
}
return {x, y}; try {
const float x = std::stof(seg_list.at(0)) / 32767.0f;
const float y = std::stof(seg_list.at(1)) / 32767.0f;
return {x, y};
} catch (const std::invalid_argument&) {
LOG_ERROR(Input, "Invalid argument: '{}'", line);
} catch (const std::out_of_range&) {
LOG_ERROR(Input, "Out of range: '{}'", line);
}
return {};
} }
u64 Tas::ReadCommandButtons(const std::string& line) const { u64 Tas::ReadCommandButtons(const std::string& line) const {