proper 3d projection
This commit is contained in:
parent
852d3f855d
commit
40792592b0
14 changed files with 3761 additions and 209 deletions
|
@ -7,13 +7,13 @@ use regex::Regex;
|
|||
|
||||
static INIT: parking_lot::Once = Once::new();
|
||||
|
||||
//#[cfg(not(debug_assertions))]
|
||||
pub fn set_panic_hook() {
|
||||
use std::io::Write;
|
||||
|
||||
use colored::Colorize;
|
||||
|
||||
use crate::workspace;
|
||||
|
||||
INIT.call_once(|| {
|
||||
let default_hook = std::panic::take_hook();
|
||||
std::panic::set_hook(Box::new(move |info| {
|
||||
|
@ -25,23 +25,26 @@ pub fn set_panic_hook() {
|
|||
std::fs::create_dir_all(&log_path).unwrap_or_else(|_| {
|
||||
default_hook(info);
|
||||
std::process::exit(0);
|
||||
})
|
||||
});
|
||||
}
|
||||
let log_path = log_path.join("panic.log");
|
||||
|
||||
// human_panic::print_msg::<PathBuf>(Some(log_path), &human_panic::Metadata::new("Zenyx", env!("CARGO_PKG_VERSION"))
|
||||
// .support("https://github.com/Zenyx-Engine/Zenyx/issues")
|
||||
// .authors("Zenyx community <https://github.com/Zenyx-Engine>")).unwrap();
|
||||
// // Call the default hook for any additional actions
|
||||
|
||||
let mut file = std::fs::File::create(&log_path).unwrap_or_else(|_| {
|
||||
default_hook(info);
|
||||
std::process::exit(0);
|
||||
});
|
||||
writeln!(file, "{}", info.payload_as_str().unwrap_or_else(|| {
|
||||
default_hook(info);
|
||||
std::process::exit(0);
|
||||
})).unwrap_or_else(|_| {
|
||||
|
||||
// Instead of using payload_as_str(), downcast the panic payload:
|
||||
let payload = info.payload();
|
||||
let payload_str = if let Some(s) = payload.downcast_ref::<&str>() {
|
||||
*s
|
||||
} else if let Some(s) = payload.downcast_ref::<String>() {
|
||||
s
|
||||
} else {
|
||||
"<non-string panic payload>"
|
||||
};
|
||||
|
||||
writeln!(file, "{}", payload_str).unwrap_or_else(|_| {
|
||||
default_hook(info);
|
||||
std::process::exit(0);
|
||||
});
|
||||
|
@ -49,6 +52,7 @@ pub fn set_panic_hook() {
|
|||
default_hook(info);
|
||||
std::process::exit(0);
|
||||
});
|
||||
|
||||
let panic_msg = format!(
|
||||
"Zenyx had a problem and crashed. To help us diagnose the problem you can send us a crash report.
|
||||
|
||||
|
@ -60,34 +64,20 @@ https://github.com/Zenyx-Engine/Zenyx/issues
|
|||
|
||||
We take privacy seriously, and do not perform any automated error collection. In order to improve the software, we rely on people to submit reports.
|
||||
|
||||
Thank you kindly!",log_path.display());
|
||||
println!("{}",panic_msg.red().bold());
|
||||
println!("\nFor future reference, the error summary is as follows:\n{}",info.payload_as_str().unwrap_or_else(||{
|
||||
default_hook(info);
|
||||
std::process::exit(0);
|
||||
}).red().bold());
|
||||
std::process::exit(0); // There is nothing to be done at this point, it looks cleaner to exit instead of doing a natural panic
|
||||
Thank you kindly!", log_path.display());
|
||||
|
||||
println!("{}", panic_msg.red().bold());
|
||||
println!("\nFor future reference, the error summary is as follows:\n{}", payload_str.red().bold());
|
||||
std::process::exit(0);
|
||||
}));
|
||||
});
|
||||
}
|
||||
// THIS SNIPPET IS LICENSED UNDER THE APACHE LICENSE, VERSION 2.0
|
||||
// https://github.com/rust-cli/human-panic
|
||||
// No changes were made to the original snippet
|
||||
|
||||
fn render_backtrace() -> String {
|
||||
//We take padding for address and extra two letters
|
||||
//to pad after index.
|
||||
#[allow(unused_qualifications)] // needed for pre-1.80 MSRV
|
||||
const HEX_WIDTH: usize = mem::size_of::<usize>() * 2 + 2;
|
||||
//Padding for next lines after frame's address
|
||||
const NEXT_SYMBOL_PADDING: usize = HEX_WIDTH + 6;
|
||||
|
||||
let mut backtrace = String::new();
|
||||
|
||||
//Here we iterate over backtrace frames
|
||||
//(each corresponds to function's stack)
|
||||
//We need to print its address
|
||||
//and symbol(e.g. function name),
|
||||
//if it is available
|
||||
let bt = Backtrace::new();
|
||||
let symbols = bt
|
||||
.frames()
|
||||
|
@ -121,7 +111,6 @@ fn render_backtrace() -> String {
|
|||
let ip = frame.ip();
|
||||
let _ = writeln!(backtrace, "{entry_idx:4}: {ip:HEX_WIDTH$?} - {name}");
|
||||
if let Some(symbol) = symbol {
|
||||
//See if there is debug information with file name and line
|
||||
if let (Some(file), Some(line)) = (symbol.filename(), symbol.lineno()) {
|
||||
let _ = writeln!(
|
||||
backtrace,
|
||||
|
@ -134,7 +123,6 @@ fn render_backtrace() -> String {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
backtrace
|
||||
}
|
||||
|
||||
|
@ -146,7 +134,6 @@ impl Sanitize for str {
|
|||
fn sanitize_path(&self) -> String {
|
||||
let username_pattern = r"(?i)(/home/|/Users/|\\Users\\)([^/\\]+)";
|
||||
let re = Regex::new(username_pattern).expect("Failed to sanitize path, aborting operation");
|
||||
|
||||
re.replace_all(self, "${1}<USER>").to_string()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue