SDL: Use a consistent error message when video isn't initialized

From d666c2d1899d686adad50c1459de83c5ec165475 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 31 Dec 2024 12:23:58 -0800
Subject: [PATCH] Use a consistent error message when video isn't initialized

---
 src/video/SDL_clipboard.c | 22 ++++++++++------------
 src/video/SDL_sysvideo.h  |  1 +
 src/video/SDL_video.c     |  2 +-
 3 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/src/video/SDL_clipboard.c b/src/video/SDL_clipboard.c
index c5f06974795d6..e669f0de5eea9 100644
--- a/src/video/SDL_clipboard.c
+++ b/src/video/SDL_clipboard.c
@@ -64,7 +64,7 @@ bool SDL_SetClipboardData(SDL_ClipboardDataCallback callback, SDL_ClipboardClean
     size_t i;
 
     if (!_this) {
-        return SDL_SetError("Video subsystem must be initialized to set clipboard text");
+        return SDL_UninitializedVideo();
     }
 
     // Parameter validation
@@ -176,7 +176,7 @@ void *SDL_GetClipboardData(const char *mime_type, size_t *size)
     SDL_VideoDevice *_this = SDL_GetVideoDevice();
 
     if (!_this) {
-        SDL_SetError("Video subsystem must be initialized to get clipboard data");
+        SDL_UninitializedVideo();
         return NULL;
     }
 
@@ -227,7 +227,7 @@ bool SDL_HasClipboardData(const char *mime_type)
     SDL_VideoDevice *_this = SDL_GetVideoDevice();
 
     if (!_this) {
-        SDL_SetError("Video subsystem must be initialized to check clipboard data");
+        SDL_UninitializedVideo();
         return false;
     }
 
@@ -289,7 +289,7 @@ char **SDL_GetClipboardMimeTypes(size_t *num_mime_types)
     }
 
     if (!_this) {
-        SDL_SetError("Video subsystem has not been initialized");
+        SDL_UninitializedVideo();
         return NULL;
     }
 
@@ -338,7 +338,7 @@ bool SDL_SetClipboardText(const char *text)
     const char **text_mime_types;
 
     if (!_this) {
-        return SDL_SetError("Video subsystem must be initialized to set clipboard text");
+        return SDL_UninitializedVideo();
     }
 
     if (text && *text) {
@@ -358,7 +358,7 @@ char *SDL_GetClipboardText(void)
     char *text = NULL;
 
     if (!_this) {
-        SDL_SetError("Video subsystem must be initialized to get clipboard text");
+        SDL_UninitializedVideo();
         return SDL_strdup("");
     }
 
@@ -384,8 +384,7 @@ bool SDL_HasClipboardText(void)
     const char **text_mime_types;
 
     if (!_this) {
-        SDL_SetError("Video subsystem must be initialized to check clipboard text");
-        return false;
+        return SDL_UninitializedVideo();
     }
 
     text_mime_types = SDL_GetTextMimeTypes(_this, &num_mime_types);
@@ -404,7 +403,7 @@ bool SDL_SetPrimarySelectionText(const char *text)
     SDL_VideoDevice *_this = SDL_GetVideoDevice();
 
     if (!_this) {
-        return SDL_SetError("Video subsystem must be initialized to set primary selection text");
+        return SDL_UninitializedVideo();
     }
 
     if (!text) {
@@ -432,7 +431,7 @@ char *SDL_GetPrimarySelectionText(void)
     SDL_VideoDevice *_this = SDL_GetVideoDevice();
 
     if (!_this) {
-        SDL_SetError("Video subsystem must be initialized to get primary selection text");
+        SDL_UninitializedVideo();
         return SDL_strdup("");
     }
 
@@ -452,8 +451,7 @@ bool SDL_HasPrimarySelectionText(void)
     SDL_VideoDevice *_this = SDL_GetVideoDevice();
 
     if (!_this) {
-        SDL_SetError("Video subsystem must be initialized to check primary selection text");
-        return false;
+        return SDL_UninitializedVideo();
     }
 
     if (_this->HasPrimarySelectionText) {
diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h
index 2633f5e067965..7887a5ade1481 100644
--- a/src/video/SDL_sysvideo.h
+++ b/src/video/SDL_sysvideo.h
@@ -528,6 +528,7 @@ extern VideoBootStrap OFFSCREEN_bootstrap;
 extern VideoBootStrap QNX_bootstrap;
 extern VideoBootStrap OPENVR_bootstrap;
 
+extern bool SDL_UninitializedVideo(void);
 // Use SDL_OnVideoThread() sparingly, to avoid regressions in use cases that currently happen to work
 extern bool SDL_OnVideoThread(void);
 extern SDL_VideoDevice *SDL_GetVideoDevice(void);
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index dc04b1405da25..57fdf689f92f8 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -520,7 +520,7 @@ static int SDLCALL cmpmodes(const void *A, const void *B)
     return 0;
 }
 
-static bool SDL_UninitializedVideo(void)
+bool SDL_UninitializedVideo(void)
 {
     return SDL_SetError("Video subsystem has not been initialized");
 }