From 855d28e97aff349474ddba02d1d6a7a98a17bb1b Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 17 Jul 2025 08:47:12 -0700
Subject: [PATCH] Fixed crash if a clipboard event was sent with video
uninitialized
This can happen if you're using SDL on Android without using the video subsystem.
---
src/video/SDL_clipboard.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/src/video/SDL_clipboard.c b/src/video/SDL_clipboard.c
index 105c2889e3d91..9d8c27d451867 100644
--- a/src/video/SDL_clipboard.c
+++ b/src/video/SDL_clipboard.c
@@ -42,6 +42,10 @@ void SDL_CancelClipboardData(Uint32 sequence)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
+ if (!_this) {
+ return;
+ }
+
if (sequence && sequence != _this->clipboard_sequence) {
// This clipboard data was already canceled
return;
@@ -62,6 +66,10 @@ bool SDL_SaveClipboardMimeTypes(const char **mime_types, size_t num_mime_types)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
+ if (!_this) {
+ return SDL_UninitializedVideo();
+ }
+
SDL_FreeClipboardMimeTypes(_this);
if (mime_types && num_mime_types > 0) {
@@ -234,13 +242,11 @@ bool SDL_HasClipboardData(const char *mime_type)
SDL_VideoDevice *_this = SDL_GetVideoDevice();
if (!_this) {
- SDL_UninitializedVideo();
- return false;
+ return SDL_UninitializedVideo();
}
if (!mime_type) {
- SDL_InvalidParamError("mime_type");
- return false;
+ return SDL_InvalidParamError("mime_type");
}
if (_this->HasClipboardData) {