Repository: alacritty/alacritty
File: alacritty/src/display/mod.rs (Rust)

Code before:
        let is_current = self.context.get().is_current();
        if is_current && !recover {
            return;
        }

        let mut was_context_reset = if is_current {
            false
        } else {
            match self.context.make_current(&self.surface) {
                Err(err) if err.error_kind() == ErrorKind::ContextLost => {
                    info!("Context lost for window {:?}", self.window.id());
                    true
                },
                _ => false,
            }
        };

        was_context_reset |= self.renderer.was_context_reset();

        if was_context_reset && recover {
            let gl_display = self.context.display();
            let gl_config = self.context.config();
            let raw_window_handle = Some(self.window.raw_window_handle());
            let context =
                renderer::platform::create_gl_context(&gl_display, &gl_config, raw_window_handle)
                    .expect("failed to recreate context.");

            // Drop the old context and renderer.
            unsafe {
                ManuallyDrop::drop(&mut self.renderer);
                ManuallyDrop::drop(&mut self.context);
            }

            // Activate new context.
            let context = context.treat_as_possibly_current();
            self.context = ManuallyDrop::new(Replaceable::new(context));
            self.context
                .make_current(&self.surface)
                .expect("failed to reativate context after reset.");

            // Recreate renderer.
            let renderer = Renderer::new(&self.context, self.renderer_preference)
                .expect("failed to recreate renderer after reset");
            self.renderer = ManuallyDrop::new(renderer);

            // Resize the renderer.
            self.renderer.resize(&self.size_info);

            self.reset_glyph_cache();
            self.damage_tracker.frame().mark_fully_damaged();


Review comment (bug):
```suggestion
                platform::create_gl_context(&gl_display, &gl_config, raw_window_handle)
                    .expect("failed to recreate context.");
```

Code after:
        let is_current = self.context.get().is_current();

        // Attempt to make the context current if it's not.
        let context_loss = if is_current {
            self.renderer.was_context_reset()
        } else {
            match self.context.make_current(&self.surface) {
                Err(err) if err.error_kind() == ErrorKind::ContextLost => {
                    info!("Context lost for window {:?}", self.window.id());
                    true
                },
                _ => false,
            }
        };

        if !context_loss {
            return;
        }

        let gl_display = self.context.display();
        let gl_config = self.context.config();
        let raw_window_handle = Some(self.window.raw_window_handle());
        let context = platform::create_gl_context(&gl_display, &gl_config, raw_window_handle)
            .expect("failed to recreate context.");

        // Drop the old context and renderer.
        unsafe {
            ManuallyDrop::drop(&mut self.renderer);
            ManuallyDrop::drop(&mut self.context);
        }

        // Activate new context.
        let context = context.treat_as_possibly_current();
        self.context = ManuallyDrop::new(Replaceable::new(context));
        self.context.make_current(&self.surface).expect("failed to reativate context after reset.");

        // Recreate renderer.
        let renderer = Renderer::new(&self.context, self.renderer_preference)
            .expect("failed to recreate renderer after reset");
        self.renderer = ManuallyDrop::new(renderer);

        // Resize the renderer.
        self.renderer.resize(&self.size_info);

        self.reset_glyph_cache();
        self.damage_tracker.frame().mark_fully_damaged();

        debug!("Recovered window {:?} from gpu reset", self.window.id());
    }

    fn swap_buffers(&self) {