//! Demonstrates how to trigger various rendering errors, and how bevy can recover from them. use bevy::{ input::keyboard::Key, prelude::*, render::{ error_handler::{RenderErrorHandler, RenderErrorPolicy}, extract_resource::{ExtractResource, ExtractResourcePlugin}, render_resource::{ BufferDescriptor, BufferUsages, CommandEncoderDescriptor, ComputePassDescriptor, Extent3d, PipelineLayoutDescriptor, PollType, RawComputePipelineDescriptor, ShaderModuleDescriptor, ShaderSource, TextureDescriptor, TextureDimension, TextureFormat, TextureUsages, }, renderer::{RenderDevice, RenderQueue}, Render, RenderApp, }, }; fn main() { let mut app = App::new(); app.add_plugins(( DefaultPlugins, ExtractResourcePlugin::::default(), )) .add_systems(Startup, setup) .add_systems(Update, (update_camera, input)) .init_resource::() .sub_app_mut(RenderApp) .add_systems(Render, cause_error); app.run(); } fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { // circular base commands.spawn(( Mesh3d(meshes.add(Circle::new(4.0))), MeshMaterial3d(materials.add(Color::WHITE)), Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)), )); // cube commands.spawn(( Mesh3d(meshes.add(Cuboid::new(2.0, 2.0, 2.0))), MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))), Transform::from_xyz(0.0, 1.0, 0.0), )); // light commands.spawn(( PointLight { shadow_maps_enabled: true, ..default() }, Transform::from_xyz(4.0, 8.0, 4.0), )); // camera commands.spawn(( Camera3d::default(), Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y), )); // help text commands.spawn(( Text::new( "Test at your own risk: you may need to restart your computer to fully recover\n\ Press O to trigger an OutOfMemory error\n\ Press V to trigger a Validation error\n\ Press D to Destroy the render device (causes device lost error)\n\ Press L to Loop infinitely in a compute shader (causes device lost error)\n\ \n\ Press 1 to ignore errors, pretending nothing happened and continue rendering.\n\ Press 2 to panic on error.\n\ Press 3 to signals app exit on error.\n\ Press 4 to keeps the app alive, but stops rendering further on error.\n\ Press 5 to attempt renderer recovery.\n\ ", ), Node { position_type: PositionType::Absolute, top: px(12), left: px(12), ..default() }, )); } fn update_camera(mut camera: Query<&mut Transform, With>, time: Res