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 5341 - X11: crash if window size too large, SW rend
Summary: X11: crash if window size too large, SW rend
Status: ASSIGNED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.12
Hardware: x86_64 Linux
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords: target-2.0.14
Depends on:
Blocks:
 
Reported: 2020-11-08 00:58 UTC by Stas Sergeev
Modified: 2020-12-27 23:05 UTC (History)
1 user (show)

See Also:


Attachments
the fix (969 bytes, patch)
2020-12-27 22:37 UTC, Stas Sergeev
Details | Diff
alternative (1.56 KB, patch)
2020-12-27 23:05 UTC, Stas Sergeev
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Stas Sergeev 2020-11-08 00:58:38 UTC
I am getting this crash:
---
X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  130 (MIT-SHM)
  Minor opcode of failed request:  3 (X_ShmPutImage)
  Value in failed request:  0x500
  Serial number of failed request:  579
  Current serial number in output stream:  580
---

It is specific to software renderer.
All you need to do is to set the window
size to your desktop size (but not making
it full-screen!), then do
  SDL_RenderClear(renderer);
  SDL_RenderPresent(renderer);

After some debugging, I've found that somehow
the window decorations are taken into account,
so if I have the desktop res 1280x1024 and do
SDL_SetWindowSize(window, 1280, 1024);
then subsequent SDL_GetWindowSize() will only
return 1280x960. This is a bug by itself: other
apps have no problems setting window size larger
than the desktop res, in which case the part of
the window is invisible (but you can drag it with
the mouse). But SDL seems to be limited to the
visible area size only.

Now, it seems that the window is in an inconsistent
state after such operation. I think it still has
the surface of the size 1280x1024, so the rendering
attempt crashes. So the work-around it to do
SDL_SetWindowSize() the second time, now with the
values obtained from SDL_GetWindowSize(). This seems
to bring the internals back in sync, and I can render
after that. So the work-around looks like this:

    SDL_SetWindowSize(window, w_x_res, w_y_res);
    SDL_GetWindowSize(window, &w_x_res, &w_y_res);
    SDL_SetWindowSize(window, w_x_res, w_y_res);

Please fix 2 bugs:

- Make it possible to create windows larger than
the desktop itself (in my case - only by the size
of the decorators, as I am trying to set the same
res as my desktop has)

- in SDL_x11window.c:970 you have:
        if ((attrs.width != orig_w) || (attrs.height != orig_h)) {
            window->w = attrs.width;
            window->h = attrs.height;
which is obviously not enough and leaves
the window in an inconsistent state. Please
make the new size to propagate properly, so
that the user doesn't have to call SDL_SetWindowSize()
twice.
Comment 1 Sylvain 2020-12-27 20:38:00 UTC
No sure if this is related to the issue, but I noticed:

https://hg.libsdl.org/SDL/file/02f670c66eed/src/video/x11/SDL_x11window.c#l545

If your window is created with flags SDL_WINDOW_RESIZABLE, X11 clips the user w/h with screen size. So the window size ends up not being the requested w/h.
Comment 2 Stas Sergeev 2020-12-27 22:37:22 UTC
Created attachment 4613 [details]
the fix

This fixes the crash part.
The most important thing is to call
SDL_OnWindowResized(window);
The remaining part:
            window->windowed.w = w;
            window->windowed.h = h;
may not be needed, at least it doesn't
make any obvious difference.
Comment 3 Stas Sergeev 2020-12-27 23:05:03 UTC
Created attachment 4614 [details]
alternative

Alternatively (or additionally, at your
opinion) you can do this.
It would just ignore the fact that the
WM have resized the window.
Please consider what fix would you prefer.