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

Fix out of bound error if material name is missing #49

Merged
merged 2 commits into from
Mar 2, 2022

Conversation

Dyedbyte
Copy link
Contributor

When reading material names specified by the usemtl tag, the program may panic due to an out of bound bug if the material name is missing. This PR should fix this error by splitting the line at the first whitespace so that everything after the tag (including whitespace) belongs to the material name.

Minimal reproduction

use tobj::{LoadOptions, load_obj_buf, load_mtl_buf};

fn main() {
    let mut data = "usemtl".as_bytes();
    load_obj_buf(&mut data, &LoadOptions::default(), |_| load_mtl_buf(&mut "".as_bytes()));
}

@Twinklebear
Copy link
Owner

Thanks @Dyedbyte , this looks good! It looks like the last thing to do before merging this is to run cargo fmt to fix the job: https://github.com/Twinklebear/tobj/runs/5370142090?check_suite_focus=true . The nightly failure will take some other fixes since it looks like some functionality has changed there so that's ok to be failing.

@Dyedbyte
Copy link
Contributor Author

Dyedbyte commented Mar 1, 2022

@Twinklebear I have now run cargo fmt, I hope the formatting looks now as expected.

@Twinklebear
Copy link
Owner

Looks great, thanks @Dyedbyte !

@Twinklebear Twinklebear merged commit 9372984 into Twinklebear:master Mar 2, 2022
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

Successfully merging this pull request may close these issues.

2 participants