# SDL: Fixed crash when the current mouse capture window is destroyed (403f8)

**URL:** <https://discourse.libsdl.org/t/sdl-fixed-crash-when-the-current-mouse-capture-window-is-destroyed-403f8/53450>\
**Category:** SDL Commits\
**Created:** [August 7, 2024, 7:38pm UTC](https://discourse.libsdl.org/t/sdl-fixed-crash-when-the-current-mouse-capture-window-is-destroyed-403f8/53450 "2024-08-07T19:38:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDLPushPostBot](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sdlpushpostbot/32/4370_2.png) [@SDLPushPostBot](https://discourse.libsdl.org/u/SDLPushPostBot)\
**Post date:** [August 7, 2024, 7:38pm UTC](https://discourse.libsdl.org/t/sdl-fixed-crash-when-the-current-mouse-capture-window-is-destroyed-403f8/53450/1 "2024-08-07T19:38:08Z")

</div>

> <https://github.com/libsdl-org/SDL/commit/403f87340fe4464ff7d194e641bc36de02b627b8>
>
> Fixes https://github.com/libsdl-org/SDL/issues/10494
> 
> (cherry picked from commit… 91d97a367e9e15bb2067ed0594798dc54c862bb1)
> (cherry picked from commit 5ca0639a42c25f3c282b9704da4bf28028ea0ae7)

```diff
From 403f87340fe4464ff7d194e641bc36de02b627b8 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 7 Aug 2024 12:15:00 -0700
Subject: [PATCH] Fixed crash when the current mouse capture window is
 destroyed

Fixes https://github.com/libsdl-org/SDL/issues/10494

(cherry picked from commit 91d97a367e9e15bb2067ed0594798dc54c862bb1)
(cherry picked from commit 5ca0639a42c25f3c282b9704da4bf28028ea0ae7)
---
 src/video/SDL_video.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 1df2359ea7feb..04a1fdf652456 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -3303,6 +3303,9 @@ void SDL_DestroyWindow(SDL_Window *window)
     if (SDL_GetKeyboardFocus() == window) {
         SDL_SetKeyboardFocus(NULL);
     }
+ if ((window->flags & SDL_WINDOW_MOUSE_CAPTURE)) {
+ SDL_UpdateMouseCapture(SDL_TRUE);
+ }
     if (SDL_GetMouseFocus() == window) {
         SDL_SetMouseFocus(NULL);
     }

```
