Skip to content

Commit

Permalink
Work around assimp-rs bug that causes panic
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Feb 2, 2024
1 parent 39aeae6 commit 62f21ed
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/assimp_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::cell::RefCell;
use std::ffi::CStr;
use std::os::raw::{c_float, c_uint};
use std::rc::Rc;
use std::str;
use tracing::*;

const ASSIMP_DIFFUSE: &CStr = match CStr::from_bytes_with_nul(b"$clr.diffuse\0") {
Expand Down Expand Up @@ -52,7 +53,14 @@ fn assimp_material_texture(material: &assimp::Material<'_>) -> Option<String> {
&mut map_mode,
&mut flags,
) {
assimp_sys::AiReturn::Success => Some(path.as_ref().to_owned()),
assimp_sys::AiReturn::Success => Some(
// assimp-rs's impl AsRef<str> for AiString does a similar, but it
// might panic because assimp-rs doesn't handle the case where assimp
// returns an out-of-range length (which probably means an error).
str::from_utf8(path.data.get(0..path.length)?)
.ok()?
.to_owned(),
),
_ => None,
}
}
Expand Down

0 comments on commit 62f21ed

Please sign in to comment.