update panic handler with system information
This commit is contained in:
parent
e2f47f1327
commit
6d71e907a4
4 changed files with 47 additions and 78 deletions
|
@ -8,7 +8,6 @@ use std::sync::Arc;
|
|||
use ctx::{Renderer, Vertex};
|
||||
use image::ImageDecoder;
|
||||
use image::ImageFormat;
|
||||
use tobj::Mesh;
|
||||
use tobj::{LoadOptions, Model};
|
||||
use tracing::{debug, error, info, trace, warn};
|
||||
use wgpu::rwh::HasWindowHandle;
|
||||
|
@ -17,7 +16,6 @@ use winit::dpi::LogicalSize;
|
|||
use winit::dpi::Size;
|
||||
use winit::event::{KeyEvent, WindowEvent};
|
||||
use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop};
|
||||
use winit::monitor::MonitorHandle;
|
||||
use winit::platform::windows::WindowAttributesExtWindows;
|
||||
use winit::window::Fullscreen;
|
||||
use winit::window::Icon;
|
||||
|
@ -94,15 +92,18 @@ f 6/11/6 5/10/6 1/1/6 2/13/6
|
|||
";
|
||||
|
||||
impl App<'_> {
|
||||
const ICON: &'static [u8] =
|
||||
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../assets/Badge.png"));
|
||||
|
||||
fn create_main_window(&mut self, event_loop: &ActiveEventLoop) {
|
||||
let icon = self.load_icon_from_bytes(Self::ICON).unwrap();
|
||||
|
||||
let win_attr = Window::default_attributes()
|
||||
.with_title("Zenyx")
|
||||
.with_min_inner_size(Size::Logical(LogicalSize::new(100.0, 100.0)))
|
||||
.with_window_icon(icon.clone())
|
||||
.with_taskbar_icon(icon);
|
||||
|
||||
.with_title("Zenyx")
|
||||
.with_min_inner_size(Size::Logical(LogicalSize::new(100.0, 100.0)))
|
||||
.with_window_icon(icon.clone())
|
||||
.with_taskbar_icon(icon);
|
||||
|
||||
match event_loop.create_window(win_attr) {
|
||||
Ok(window) => {
|
||||
let window = Arc::new(window);
|
||||
|
@ -229,14 +230,17 @@ impl App<'_> {
|
|||
warn!("No window found for fullscreen toggle: {:?}", window_id);
|
||||
}
|
||||
}
|
||||
|
||||
fn load_icon_from_bytes(&self, bytes: &[u8]) -> Result<Option<Icon>, String> {
|
||||
const IMAGE_DIR: &str = env!("CARGO_MANIFEST_DIR");
|
||||
let cursor = Cursor::new(bytes);
|
||||
let format = image::guess_format(bytes).map_err(|_| "Failed to guess image format")?;
|
||||
let decoder = match format {
|
||||
ImageFormat::Png => image::codecs::png::PngDecoder::new(cursor).map_err(|e| format!("Failed to decode PNG: {}", e))?,
|
||||
ImageFormat::Png => image::codecs::png::PngDecoder::new(cursor)
|
||||
.map_err(|e| format!("Failed to decode PNG: {}", e))?,
|
||||
_ => {
|
||||
let img = image::load_from_memory(bytes).map_err(|e| format!("Failed to load image: {}", e))?.into_rgba8();
|
||||
let img = image::load_from_memory(bytes)
|
||||
.map_err(|e| format!("Failed to load image: {}", e))?
|
||||
.into_rgba8();
|
||||
let (width, height) = img.dimensions();
|
||||
return Icon::from_rgba(img.into_raw(), width, height)
|
||||
.map(Some)
|
||||
|
@ -246,14 +250,15 @@ impl App<'_> {
|
|||
|
||||
let (width, height) = decoder.dimensions();
|
||||
let mut image_data = vec![0; decoder.total_bytes() as usize];
|
||||
decoder.read_image(&mut image_data).map_err(|e| format!("Failed to read image data: {}", e))?;
|
||||
decoder
|
||||
.read_image(&mut image_data)
|
||||
.map_err(|e| format!("Failed to read image data: {}", e))?;
|
||||
|
||||
Icon::from_rgba(image_data, width, height)
|
||||
.map(Some)
|
||||
.map_err(|e| format!("Failed to create icon from bytes: {}", e))
|
||||
}
|
||||
|
||||
const ICON: &'static [u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../assets/Badge.png"));
|
||||
fn spawn_child_window(&mut self, event_loop: &ActiveEventLoop) {
|
||||
if let Some(main_ctx) = self.windows.values().find(|ctx| ctx.is_main_window()) {
|
||||
let title = format!("Zenyx - New Window {}", self.windows.len());
|
||||
|
@ -265,7 +270,7 @@ impl App<'_> {
|
|||
.with_min_inner_size(Size::Logical(LogicalSize::new(100.0, 100.0)))
|
||||
.with_window_icon(icon.clone())
|
||||
.with_taskbar_icon(icon);
|
||||
|
||||
|
||||
match main_ctx.window_handle() {
|
||||
Ok(handle) => {
|
||||
if !cfg!(target_os = "windows") {
|
||||
|
@ -345,6 +350,11 @@ impl App<'_> {
|
|||
|
||||
fn handle_resize(&mut self, window_id: WindowId, new_size: winit::dpi::PhysicalSize<u32>) {
|
||||
if let Some(window_context) = self.windows.get_mut(&window_id) {
|
||||
// if we dont ignore size 0 this WILL cause a crash. DO NOT REMOVE
|
||||
if new_size.height == 0 || new_size.width == 0 {
|
||||
error!("Attempted to resize a window to 0x0!");
|
||||
return;
|
||||
}
|
||||
window_context.ctx.resize(new_size.into());
|
||||
window_context.window.request_redraw();
|
||||
debug!(
|
||||
|
@ -435,7 +445,7 @@ impl ApplicationHandler for App<'_> {
|
|||
}
|
||||
|
||||
pub fn init_renderer(event_loop: EventLoop<()>) {
|
||||
event_loop.set_control_flow(ControlFlow::Wait);
|
||||
event_loop.set_control_flow(ControlFlow::Poll);
|
||||
let mut app = App::default();
|
||||
if let Err(e) = event_loop.run_app(&mut app) {
|
||||
error!("Failed to run application: {}", e);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue