We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3222 - X11: Clipboard API needs a window
Summary: X11: Clipboard API needs a window
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.4
Hardware: x86_64 Linux
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
: 3718 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-01-04 18:48 UTC by Imants
Modified: 2017-08-02 14:21 UTC (History)
2 users (show)

See Also:


Attachments
Test program (470 bytes, text/plain)
2016-01-06 06:45 UTC, Ryan C. Gordon
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Imants 2016-01-04 18:48:35 UTC
I am using libSDL2-2.0.so.0.4.0 witch I have compiled myself. When I try to get clipboard text or try to check if there is clipboard text my application gangs and stop responding indefinitely.   

code example: 

SDL_SetClipboardText('Test');
AssertTrue('SDL_HasClipboardText', SDL_HasClipboardText() = SDL_TRUE);
AssertEquals('Test', SDL_GetClipboardText());
Comment 1 Imants 2016-01-04 19:35:41 UTC
I tried same in CodeBlocks result was little different but failure still

   SDL_SetClipboardText("SDL Tutorial");
   int rez = SDL_HasClipboardText(); //rez was 0
   if (rez)
   {
     title = SDL_GetClipboardText();
   }
   else
   {
     title = "fail"; //got this value
   }
Comment 2 Imants 2016-01-05 18:01:51 UTC
I was idiot and forgot to call SDL_Init(SDL_INIT_EVERYTHING) in code blocks. After that application crashed as in my pascal code.
Comment 3 Ryan C. Gordon 2016-01-06 06:45:37 UTC
Created attachment 2355 [details]
Test program


Can you try this test program and see if it still has problems? It'll create a window, print what's currently on the clipboard to stdout, and then put whatever you had on the command line on the clipboard (which you can see by pasting it somewhere). The otherwise-useless SDL window will hang around until you close it to end the program.

Just trying to narrow down the problem here.

--ryan.
Comment 4 Imants 2016-01-06 18:29:18 UTC
Ok now I understand. On Linux SDL_HasClipboardText and SDL_GetClipboardText crashes if I call them before I create SDL_window or do not create it at all. On Windows it works properly in bought cases. I do not see why should I create SDL_Window to use clipboard functionality but I do know that It should not crash system :). And there is no documentation that this should work together with SDL_Window :\
Comment 5 Ryan C. Gordon 2016-01-06 19:33:34 UTC
(In reply to Imants from comment #4)
> Ok now I understand. On Linux SDL_HasClipboardText and SDL_GetClipboardText
> crashes if I call them before I create SDL_window or do not create it at
> all. On Windows it works properly in bought cases. I do not see why should I
> create SDL_Window to use clipboard functionality but I do know that It
> should not crash system :). And there is no documentation that this should
> work together with SDL_Window :\

Yeah, X11 requires a window for this. But we could handle this better (maybe making a temporary window, or at least not crashing).

I'll leave this open for now while we figure out what to do.

--ryan.
Comment 6 Imants 2016-01-07 06:14:31 UTC
I would be contented if it would be mentioned in documentation, it would not crash and SDL_GetError() would return error message why it is not working.
Comment 7 Ryan C. Gordon 2017-07-31 03:24:00 UTC
*** Bug 3718 has been marked as a duplicate of this bug. ***
Comment 8 Ryan C. Gordon 2017-08-02 14:21:34 UTC
This bug is now fixed in https://hg.libsdl.org/SDL/rev/3767cdd2d64b ...we had already fixed the crashing if SDL_Init(SDL_INIT_VIDEO) wasn't called, but now you don't need to have created an SDL_Window to interact with the X11 clipboard.

--ryan.