Fixed crash if mouse functions are used after video quit

This commit is contained in:
Sam Lantinga
2025-08-25 08:54:43 -07:00
parent 270737584e
commit aab95894a6
2 changed files with 9 additions and 10 deletions

View File

@@ -1168,6 +1168,12 @@ void SDL_QuitMouse(void)
}
SDL_free(SDL_mice);
SDL_mice = NULL;
if (mouse->internal) {
SDL_free(mouse->internal);
mouse->internal = NULL;
}
SDL_zerop(mouse);
}
bool SDL_SetRelativeMouseTransform(SDL_MouseMotionTransformCallback transform, void *userdata)

View File

@@ -373,12 +373,12 @@ bool Cocoa_InitMouse(SDL_VideoDevice *_this)
{
NSPoint location;
SDL_Mouse *mouse = SDL_GetMouse();
SDL_MouseData *internal = (SDL_MouseData *)SDL_calloc(1, sizeof(SDL_MouseData));
if (internal == NULL) {
SDL_MouseData *data = (SDL_MouseData *)SDL_calloc(1, sizeof(SDL_MouseData));
if (data == NULL) {
return false;
}
mouse->internal = internal;
mouse->internal = data;
mouse->CreateCursor = Cocoa_CreateCursor;
mouse->CreateSystemCursor = Cocoa_CreateSystemCursor;
mouse->ShowCursor = Cocoa_ShowCursor;
@@ -585,13 +585,6 @@ void Cocoa_HandleMouseWarp(CGFloat x, CGFloat y)
void Cocoa_QuitMouse(SDL_VideoDevice *_this)
{
SDL_Mouse *mouse = SDL_GetMouse();
if (mouse) {
if (mouse->internal) {
SDL_free(mouse->internal);
mouse->internal = NULL;
}
}
}
#endif // SDL_VIDEO_DRIVER_COCOA