Skip to content

Commit

Permalink
Handle invalid texture id
Browse files Browse the repository at this point in the history
  • Loading branch information
Speykious committed Jul 13, 2023
1 parent 97d2dcd commit 921b71d
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/formats/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,26 @@ fn deserialize_part(obj: &JsonObject) -> InoxParseResult<Part> {
};

let tex_emissive = match textures.get(1).and_then(JsonValue::as_number) {
Some(val) => val.try_into().map_err(|_| {
InoxParseError::JsonError(
JsonError::ParseIntError("1".to_owned()).nested("textures"),
)
})?,
Some(val) => val.try_into()
// Map u32::MAX to nothing
.map(|val| if val == u32::MAX as usize { 0 } else { val })
.map_err(|_| {
InoxParseError::JsonError(
JsonError::ParseIntError("1".to_owned()).nested("textures"),
)
})?,
None => 0,
};

let tex_bumpmap = match textures.get(2).and_then(JsonValue::as_number) {
Some(val) => val.try_into().map_err(|_| {
InoxParseError::JsonError(
JsonError::ParseIntError("2".to_owned()).nested("textures"),
)
})?,
Some(val) => val.try_into()
// Map u32::MAX to nothing
.map(|val| if val == u32::MAX as usize { 0 } else { val })
.map_err(|_| {
InoxParseError::JsonError(
JsonError::ParseIntError("2".to_owned()).nested("textures"),
)
})?,
None => 0,
};

Expand Down

0 comments on commit 921b71d

Please sign in to comment.