Fixed crash if using clipboard functions without having initialized video.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
diff --git a/src/video/SDL_clipboard.c b/src/video/SDL_clipboard.c
index a3b38e0..f2b4501 100644
--- a/src/video/SDL_clipboard.c
+++ b/src/video/SDL_clipboard.c
@@ -29,6 +29,10 @@ SDL_SetClipboardText(const char *text)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
+ if (!_this) {
+ return SDL_SetError("Video subsystem must be initialized to set clipboard text");
+ }
+
if (!text) {
text = "";
}
@@ -46,6 +50,11 @@ SDL_GetClipboardText(void)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
+ if (!_this) {
+ SDL_SetError("Video subsystem must be initialized to get clipboard text");
+ return SDL_strdup("");
+ }
+
if (_this->GetClipboardText) {
return _this->GetClipboardText(_this);
} else {
@@ -62,6 +71,11 @@ SDL_HasClipboardText(void)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
+ if (!_this) {
+ SDL_SetError("Video subsystem must be initialized to check clipboard text");
+ return SDL_FALSE;
+ }
+
if (_this->HasClipboardText) {
return _this->HasClipboardText(_this);
} else {