Skip to content

Commit

Permalink
Merge pull request #72 from SomeoneToIgnore/fix-error-messages
Browse files Browse the repository at this point in the history
Show proper error in `load_font` call
  • Loading branch information
boozook authored Oct 16, 2023
2 parents 5b289e5 + 6984a4e commit fa05318
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,20 @@ impl Graphics {

pub fn load_font(&self, path: &str) -> Result<Font, Error> {
let c_path = CString::new(path).map_err(Error::msg)?;
let font = pd_func_caller!((*self.0).loadFont, c_path.as_ptr(), ptr::null_mut())?;
Font::new(font)
let mut out_err: *const crankstart_sys::ctypes::c_char = ptr::null_mut();
let font = pd_func_caller!((*self.0).loadFont, c_path.as_ptr(), &mut out_err)?;
if font == ptr::null_mut() {
if out_err != ptr::null_mut() {
let err_msg = unsafe { CStr::from_ptr(out_err).to_string_lossy().into_owned() };
Err(anyhow!(err_msg))
} else {
Err(anyhow!(
"load_font failed without providing an error message"
))
}
} else {
Font::new(font)
}
}

pub fn set_font(&self, font: &Font) -> Result<(), Error> {
Expand Down

0 comments on commit fa05318

Please sign in to comment.