Application getting stuck after calling SDL_DestroyWindow()

I have an application in SDL2 to share your screen using the airplay protocol. So to share I have created a class in which I created a SDL_Texture, SDL_Renderer and SDL_Window to show the rendered frames. But when I disconnect my iPhone/iPad and the SDL_DestroyWindow is called, the application is getting stuck. If I debug it, the texture and renderer destroy functions are called but as soon as the SDL_DestroyWindow function is called, the app gets stuck.

The app gets stuck on the last frame.


Any help is appreciated. Thanks.

I had a similar weird bug on Mac OS 13.0.1 with
cocoa video driver which prevents SDL windows to close in some situations.
Workaround: for some reason the window will close if I initialize a
subsystem that was not already initialized (I used joystick). (That is, calling Sdl_Init (SDL_INIT_JOYSTICK) before calling SDL_DestroyWindow)