Repository: bevyengine/bevy
File: examples/app/render_recovery.rs (Rust)

Code before:

#[derive(Resource, ExtractResource, Clone, Default)]
enum RenderError {
    #[default]
    None,
    OutOfMemory,
    Validation,
    DeviceLost,
    Loop,
}

fn input(keyboard_input: Res<ButtonInput<KeyCode>>, mut error: ResMut<RenderError>) {
    *error = RenderError::None;
    if keyboard_input.just_pressed(KeyCode::KeyO) {
        *error = RenderError::OutOfMemory;
    }
    if keyboard_input.just_pressed(KeyCode::KeyV) {
        *error = RenderError::Validation;
    }
    if keyboard_input.just_pressed(KeyCode::KeyD) {
        *error = RenderError::DeviceLost;
    }
    if keyboard_input.just_pressed(KeyCode::KeyL) {
        *error = RenderError::Loop;
    }
}

fn cause_error(error: Res<RenderError>, device: Res<RenderDevice>, queue: Res<RenderQueue>) {
    match *error {
        RenderError::None => {}
        RenderError::OutOfMemory => {
            let mut textures = Vec::new();
            for _ in 0..64 {
                textures.push(device.create_texture(&TextureDescriptor {
                    label: None,
                    size: Extent3d {
                        width: 8192,
                        height: 8192,
                        depth_or_array_layers: 1,
                    },
                    mip_level_count: 1,
                    sample_count: 1,
                    dimension: TextureDimension::D2,
                    format: TextureFormat::Rgba16Float,
                    usage: TextureUsages::RENDER_ATTACHMENT,
                    view_formats: &[],
                }));
            }
        }
        RenderError::Validation => {
            device.create_buffer(&BufferDescriptor {

Review comment (suggestion):
Not a blocker but I'd suggest either using numbers or using something like `input.just_pressed(Key::Character("o".into()))` so it works for people with non qwerty layout.

Code after:
}

#[derive(Resource, ExtractResource, Clone, Default)]
enum RenderError {
    #[default]
    None,
    OutOfMemory,
    Validation,
    DeviceLost,
    Loop,
}

fn input(input: Res<ButtonInput<Key>>, mut error: ResMut<RenderError>) {
    *error = RenderError::None;
    if input.just_pressed(Key::Character("o".into())) {
        *error = RenderError::OutOfMemory;
    }
    if input.just_pressed(Key::Character("v".into())) {
        *error = RenderError::Validation;
    }
    if input.just_pressed(Key::Character("d".into())) {
        *error = RenderError::DeviceLost;
    }
    if input.just_pressed(Key::Character("l".into())) {
        *error = RenderError::Loop;
    }
}

fn cause_error(error: If<Res<RenderError>>, device: Res<RenderDevice>, queue: Res<RenderQueue>) {
    match **error {
        RenderError::None => {}
        RenderError::OutOfMemory => {
            let mut textures = Vec::new();
            for _ in 0..64 {
                textures.push(device.create_texture(&TextureDescriptor {
                    label: None,
                    size: Extent3d {
                        width: 8192,
                        height: 8192,
                        depth_or_array_layers: 1,
                    },
                    mip_level_count: 1,
                    sample_count: 1,
                    dimension: TextureDimension::D2,
                    format: TextureFormat::Rgba16Float,
                    usage: TextureUsages::RENDER_ATTACHMENT,
                    view_formats: &[],
                }));
            }
        }
        RenderError::Validation => {