use std::ffi::{c_void, CStr};
use physx_sys::{create_assert_handler, PxAssertHandler};
pub trait AssertHandler: Sized {
fn on_assert(&self, expr: &str, file: &str, line: u32, should_ignore: &mut bool);
unsafe fn into_px(self) -> *mut PxAssertHandler {
unsafe extern "C" fn on_message_shim<L: AssertHandler>(
expr: *const i8,
file: *const i8,
line: u32,
should_ignore: *mut bool,
this: *const c_void,
) {
unsafe {
let this = &*this.cast::<L>();
let expr = CStr::from_ptr(expr.cast());
let expr = expr.to_string_lossy();
let file = CStr::from_ptr(file.cast());
let file = file.to_string_lossy();
this.on_assert(&expr, &file, line, &mut *should_ignore);
}
}
unsafe {
create_assert_handler(
on_message_shim::<Self>,
Box::into_raw(Box::new(self)) as *mut c_void,
)
}
}
}