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 145 - Crash if SDL_SetVideoMode larger than current Xrandr resolution.
Summary: Crash if SDL_SetVideoMode larger than current Xrandr resolution.
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: HG 1.2
Hardware: All Linux
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on: 109
Blocks:
  Show dependency treegraph
 
Reported: 2006-02-21 05:56 UTC by Ryan C. Gordon
Modified: 2006-03-22 06:15 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ryan C. Gordon 2006-02-21 05:56:08 UTC
Date: Tue, 21 Feb 2006 01:05:53 +0100
To: "A list for developers using the SDL library." <sdl@libsdl.org>(includes\
	SDL-announce)
From: "Gerry JJ" <trick@icculus.org>
Subject: [SDL] BUG: Linux/X: Crash when setting video mode for higher XRandR
	modes than current (X BadValue)

As the subject says, SDL fails setting the full screen video mode to  
resolutions higher than current XRandR resolution setting (I'm using Linux  
on an amd64 system, with Xorg 6.8.2 and the nvidia 1.0.8178 driver, if  
that matters), in stead choosing to crash with a BadValue error from X.

For example, my system supports up to 1280x1024 and 1400x1050 resolutions,  
but I usually use X with a 1024x768 xrandr setting (because of an old  
monitor).  For me this means that SDL crashes if setting fullscreen  
resolutions higher than 1024x768.  This is 100% reproducable.  Also, SDL  
does claim to support these higher modes when queried with SDL_ListModes().

Here's a small test program:

--- 8< ---
#include <SDL.h>
#include <stdio.h>

int main (int argc, char *argv[])
{
	SDL_Rect **modes;
	unsigned int i;

	SDL_Init(SDL_INIT_VIDEO);

	modes = SDL_ListModes(NULL, SDL_FULLSCREEN);
	if (!modes)
		printf("All modes supported\n");
	else if (modes == (SDL_Rect**)-1)
		fprintf(stderr, "No supported modes!\n");
	else for (i = 0; modes[i]; ++i)
		printf("Supported mode: %ux%u\n", modes[i]->w, modes[i]->h);

	if (!SDL_SetVideoMode(1024, 768, 0, SDL_FULLSCREEN))
		fprintf(stderr, "Couldn't set video mode");
	else
		SDL_Delay(5000);

	SDL_Quit();
}
--- 8< ---

Also, here's the output from xrandr on my system:

--- 8< ---
$ xrandr
  SZ:    Pixels          Physical       Refresh
  0   1400 x 1050   ( 474mm x 356mm )   60
  1   1280 x 1024   ( 474mm x 356mm )   60
  2   1280 x 960    ( 474mm x 356mm )   60
  3   1152 x 864    ( 474mm x 356mm )   75
*4   1024 x 768    ( 474mm x 356mm )  *85   75   70   60
  5    832 x 624    ( 474mm x 356mm )   75
  6    800 x 600    ( 474mm x 356mm )   85   75   72   60   56
  7    700 x 525    ( 474mm x 356mm )   60
  8    640 x 512    ( 474mm x 356mm )   60
  9    640 x 480    ( 474mm x 356mm )   85   75   73   60
  10   720 x 400    ( 474mm x 356mm )   85
  11   640 x 400    ( 474mm x 356mm )   85
  12   576 x 432    ( 474mm x 356mm )   75
  13   640 x 350    ( 474mm x 356mm )   85
  14   512 x 384    ( 474mm x 356mm )   85   75   70   60
  15   416 x 312    ( 474mm x 356mm )   75
  16   400 x 300    ( 474mm x 356mm )   85   75   72   60   56
  17   320 x 240    ( 474mm x 356mm )   85   75   73   60
  18   320 x 200    ( 474mm x 356mm )   85
  19   320 x 175    ( 474mm x 356mm )   85
Current rotation - normal
Current reflection - none
Rotations possible - normal
Reflections possible - none
--- 8< ---

When I run the test program on my system, it lists all of the modes listed  
by xrandr above, ie the xrandr setting doesn't influence SDLs supported  
modes list at all.  (Also, modes available in several refresh rates is  
listed more than once, once for each refresh rate, so that on my system  
1024x768 is listed four times, 800x600 is listed five times, etc -- is  
this a bug ?).

When run with xrandr set to 1024x768 (the resolution the test program  
attempts to set) or higher, the test program works fine.  The fullscreen  
video mode is set correctly, and the program exits normally.  In other  
words, everything is just peachy.

When run with xrandr set to a mode lower than the resolution we attempt to  
set, however (eg mode 6, 800x600), the test program aborts with the  
following error (again, after listing all the modes, including 1024x768):

--- 8< ---
[...]
X Error of failed request:  BadValue (integer parameter out of range for  
operation)
   Major opcode of failed request:  134 (XFree86-VidModeExtension)
   Minor opcode of failed request:  10 (XF86VidModeSwitchToMode)
   Value in failed request:  0x131
   Serial number of failed request:  97
   Current serial number in output stream:  99
--- 8< ---

Now, based on these results it doesn't look like SDL supports switching  
video mode with XRandR.  It'd be great if this could be added, but if  
noone volunteers to do that (I'd do it myself, but I don't know how, and  
don't have time to look into it at the moment -- maybe later though), the  
list returned by SDL_ListModes etc should at least be fixed to take this  
into account, so that programs don't try switching to higher modes and  
crash like this.

- Gerry
Comment 1 Ryan C. Gordon 2006-03-22 06:15:56 UTC
Latest CVS uses Xrandr when available and thus fixes this crash.

--ryan.