Skip to content

Commit

Permalink
Use a consistent error message when video isn't initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Dec 31, 2024
1 parent 36806d9 commit fea769e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
22 changes: 10 additions & 12 deletions src/video/SDL_clipboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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("");
}

Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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("");
}

Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/video/SDL_sysvideo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/video/SDL_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down

0 comments on commit fea769e

Please sign in to comment.