Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/video/SDL_sysvideo.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@ struct SDL_VideoDevice
*/
bool (*VideoInit)(SDL_VideoDevice *_this);

/*
* Called when Video subsystem is beginning to terminate. This allows for
* special case code that need to happen before internal SDL bits
* clean up that must happen before VideoQuit(). An example is stopping
* a hotplug thread that might add mice/keyboards after SDL has cleaned
* up its internal list. Most work is meant to happen in VideoQuit, though.
*/
void (*VideoPreQuit)(SDL_VideoDevice *_this);

/*
* Reverse the effects VideoInit() -- called if VideoInit() fails or
* if the application is shutting down the video subsystem.
Expand Down
4 changes: 4 additions & 0 deletions src/video/SDL_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -4718,6 +4718,10 @@ void SDL_QuitVideo(void)

_this->is_quitting = true;

if (_this->VideoPreQuit) {
_this->VideoPreQuit(_this);
}

// Halt event processing before doing anything else
#if 0 // This was moved to the end to fix a memory leak
SDL_QuitPen();
Expand Down
10 changes: 9 additions & 1 deletion src/video/windows/SDL_windowsvideo.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ struct ITaskbarList3
// Initialization/Query functions
static bool WIN_VideoInit(SDL_VideoDevice *_this);
static void WIN_VideoQuit(SDL_VideoDevice *_this);
static void WIN_VideoPreQuit(SDL_VideoDevice *_this);

// Hints
bool g_WindowsEnableMessageLoop = true;
Expand Down Expand Up @@ -327,6 +328,7 @@ static SDL_VideoDevice *WIN_CreateDevice(void)

// Set the function pointers
device->VideoInit = WIN_VideoInit;
device->VideoPreQuit = WIN_VideoPreQuit;
device->VideoQuit = WIN_VideoQuit;
#if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
device->RefreshDisplays = WIN_RefreshDisplays;
Expand Down Expand Up @@ -669,6 +671,13 @@ static bool WIN_VideoInit(SDL_VideoDevice *_this)
return true;
}

void WIN_VideoPreQuit(SDL_VideoDevice *_this)
{
#if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
WIN_QuitDeviceNotification(); // stop hotplug thread before the rest of the video subsystem cleans up.
#endif
}

void WIN_VideoQuit(SDL_VideoDevice *_this)
{
SDL_VideoData *data = _this->internal;
Expand All @@ -685,7 +694,6 @@ void WIN_VideoQuit(SDL_VideoDevice *_this)

#if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
WIN_QuitModes(_this);
WIN_QuitDeviceNotification();
WIN_QuitKeyboard(_this);
WIN_QuitMouse(_this);

Expand Down
Loading