Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unwrap in lib code panic on single-player #1

Open
harryhaaren opened this issue Feb 4, 2023 · 0 comments
Open

Unwrap in lib code panic on single-player #1

harryhaaren opened this issue Feb 4, 2023 · 0 comments

Comments

@harryhaaren
Copy link

harryhaaren commented Feb 4, 2023

Thanks for sharing your code - it was a good way to get some data from the F1 game quickly. I've bumped into some issues when using/testing the library, described below. Regards (or Groetjes? : ) -Harry

The ? operator here causes issues when driving in single-player, as there may not be 22 participants available? This is reproducible in F2 single-player time-trial mode:

let num_active_cars = reader.read_u8()?;
let mut participants = Vec::new();
for _ in 0..22 {
participants.push(ParticipantData::new(reader)?);
}

Refactoring to a if let Some() and vec::push() of the result might be a nice solution?

let mut participants = Vec::new();
for _ in 0..22 {
    if let Some(participant) = ParticipantData::new(reader) {
         participants.push(participant);
    };
}

I've had other occurances of .unwrap or ? behaviour causing issues in data-parsing when not as expected, for example in FinalClassification TyreCompounds (in F1 race, Barcelona with default race setup iirc):

for _ in 0..8 {
v.push(ActualTyreCompound::from_u8(reader.read_u8()?).unwrap());
}

Similar code refactors to avoid ? here (and in other places in the library) would make it more "error resistant".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant