1

I get a window ID from the command line, and create an SDL window with it:

Window window_id = from_cli();    // e.g. 0x34000c8
w = SDL_CreateWindowFrom((void*) (Window) window_id);

When my program finishes I try to clean up:

SDL_DestroyWindow(w);

And that is when I got an X11 error:

X Error of failed request:  BadWindow (invalid Window parameter)
  Major opcode of failed request:  3 (X_GetWindowAttributes)
  Resource id in failed request:  0x34000c8
  Serial number of failed request:  255
  Current serial number in output stream:  256

Obviously, the caller of my program - which I cannot change - has already destroyed the X window I was using.


How should I handle this situation?

  1. SDL_DestroyWindow() can be omitted if the SDL window was created with SDL_CreateWindowFrom()

  2. go for SDL_SysWMinfo, pick up x11.display, create my own X11 error handler, and filter errors for window_id?


Looking at the SDL2-2.0.9 source code, it seems that SDL already sets an error handler, which calls the previous error handler, which is the default one that terminates the program on error. (src/video/x11/SDL_x11video.c::X11_SafetyNetErrHandler())

Internally SDL will override this error handler temporarily, when doing its own stuff. (src/video/x11/SDL_x11video.c::X11_CheckWindowManager())

Thus, I guess 2) is the correct way to go.

EDIT:

When omitting SDL_DestroyWindow(), SDL_Quit() will fail with the same X error.

I also realized that SDL may not anticipate a failed X call, so ignoring the error may not be a good idea, after all.

EDIT2:

I just realized that SetErrorHandler() does not require a display.

Adding an X error handler that ignores X errors regarding this particular X window seems to work, not sure if it creates new problems unseen.


Is there preferred way to handle this problem?


Version: SDL2-2.0.9

Zoltan K.
  • 1,036
  • 9
  • 19

0 Answers0