[PATCH] SDL bug patch

Hi,

Let me introduce 2 fixes to SDL.

  1. Preventing great slowdown on fast machines while hardware
    flipping (it’s obviously bug).
  2. Setting up 85 Hz of monitor if supported. The reason is that
    Win98 by default sets lowest frequency 60 Hz.
    And we can’t set up maximum frequency because some users can have
    wrong monitor drivers.
    This is important for shareware and commercial programs.

Please look at it here:
http://activekitten.com/files/SDL_dx5video.diff

To apply use patch -R SDL_dx5video.c SDL_dx5video.diff

Hope it will be included in the next release–
With best regards,
Dmitry Yakimov,
+7 910 9429656
http://www.activekitten.com

  1. Setting up 85 Hz of monitor if supported. The reason is that
    Win98 by default sets lowest frequency 60 Hz.
    And we can’t set up maximum frequency because some users can have
    wrong monitor drivers.

You can’t set up 85Hz, either, for the same reason. If you go above
60Hz by default, it’ll cause monitor desyncs on some systems. (People
run things on very old systems; I even have a monitor next to me that
won’t go above 60Hz in 640x480.)

 This is important for shareware and commercial programs.

Please look at it here:
http://activekitten.com/files/SDL_dx5video.diff

To apply use patch -R SDL_dx5video.c SDL_dx5video.diff

Don’t forget to keep the DIB code in sync: if you change behavior like
this in the DX5 driver, be sure to do the same thing in the DIB driver
as well (wherever possible). Different behavior on the two drivers
causes lots of confusion.

(I strongly recommend making unified diffs, not old context diffs;
they’re actually readable.)On Tue, Jan 13, 2004 at 07:25:37PM +0300, Dmitry Yakimov wrote:


Glenn Maynard

At 19:25 2004-01-13 +0300, you wrote:

  1. Setting up 85 Hz of monitor if supported. The reason is that
    Win98 by default sets lowest frequency 60 Hz.
    And we can’t set up maximum frequency because some users can have
    wrong monitor drivers.
    This is important for shareware and commercial programs.

I was working on DX some time ago, and I’m sure it sets as a default
frequency rate equal to the frequency rate on desktop. I don’t understand
why this cannot be done that way?

Archibald

Hi,

Thank you for asnwer!

srlo> On Tue, Jan 13, 2004 at 07:25:37PM +0300, Dmitry Yakimov wrote:

  1. Setting up 85 Hz of monitor if supported. The reason is that
    Win98 by default sets lowest frequency 60 Hz.
    And we can’t set up maximum frequency because some users can have
    wrong monitor drivers.
    srlo>
    srlo> You can’t set up 85Hz, either, for the same reason. If you go above
    srlo> 60Hz by default, it’ll cause monitor desyncs on some systems. (People
    srlo> run things on very old systems; I even have a monitor next to me that
    srlo> won’t go above 60Hz in 640x480.)

It will automatically choose the maximal frequency supported by monitor.
So if the monitor supports only 60 Hz (as my TFT :slight_smile: it will not even
try to set up higher frequency. So it is safe enough.

srlo>

 This is important for shareware and commercial programs.

Please look at it here:
http://activekitten.com/files/SDL_dx5video.diff

To apply use patch -R SDL_dx5video.c SDL_dx5video.diff
srlo>
srlo> Don’t forget to keep the DIB code in sync: if you change behavior like
srlo> this in the DX5 driver, be sure to do the same thing in the DIB driver
srlo> as well (wherever possible). Different behavior on the two drivers
srlo> causes lots of confusion.

Yes, but
DIB driver does not need these changes I assume because
a) it uses default user monitor frequency, users usually set up
maximal supported frequency so we shall not change it.
b) bug fixed while hardware flipping is a DirectX related issue, not
the DIB one.

srlo>
srlo> (I strongly recommend making unified diffs, not old context diffs;
srlo> they’re actually readable.)

Thank you. I’ve uploaded unified diff version:
http://activekitten.com/files/SDL_dx5video.diff

I can’t commit these changes to CVS as I’m not a regular developer of
SDL, could anyone please do it if you found my changes useful.–
Best regards,
Dmitry Yakimov, ISDEF member
ActiveKitten.com

Dmitry Yakimov (2004-01-16 09:32):

Hi,

Thank you for asnwer!

srlo> On Tue, Jan 13, 2004 at 07:25:37PM +0300, Dmitry Yakimov wrote:

  1. Setting up 85 Hz of monitor if supported. The reason is that
    Win98 by default sets lowest frequency 60 Hz.
    And we can’t set up maximum frequency because some users can have
    wrong monitor drivers.

srlo>
srlo> You can’t set up 85Hz, either, for the same reason. If you go above
srlo> 60Hz by default, it’ll cause monitor desyncs on some systems. (People
srlo> run things on very old systems; I even have a monitor next to me that
srlo> won’t go above 60Hz in 640x480.)

just put a config dialog at the startup, there is an advanced settings
button, the upcoming dialog will have information about the current
system’s refreshrate and will have a dropdown field where you can select
the Hz and bits (16/32Bit) the gfx-adapter can supply.
there should also be a notice that you may break your monitor if you set
too high refresh rates.
A windowed mode checkbox should also be available imho.

good idea? bad idea?–
regards

ionas

just put a config dialog at the startup, there is an advanced settings
button, the upcoming dialog will have information about the current
system’s refreshrate and will have a dropdown field where you can select
[…]
good idea? bad idea?

SDL doesn’t have facilities for letting an application specify refresh
rate, so adding a user-defined setting to your app wouldn’t help.

I think the patch looks good…but it doesn’t apply to CVS at all:

[icculus at boxx ~/projects/SDL12/src/video/windx5]$ patch -p0 <
/home/icculus/SDL_dx5video.diff
patching file SDL_dx5video.c
Hunk #1 FAILED at 71.
Hunk #2 FAILED at 667.
Hunk #3 FAILED at 677.
Hunk #4 FAILED at 868.
Hunk #5 FAILED at 914.
Hunk #6 FAILED at 927.
Hunk #7 FAILED at 1001.
Hunk #8 FAILED at 1222.
Hunk #9 FAILED at 1992.
9 out of 9 hunks FAILED – saving rejects to file SDL_dx5video.c.rej

What version of SDL is this patch meant to be applied to, again?

–ryan.

I wrote the text below, and it was quoted “srlo”. I don’t know what
that means. I recommend using standard “>” quoting.

srlo> You can’t set up 85Hz, either, for the same reason. If you go above
srlo> 60Hz by default, it’ll cause monitor desyncs on some systems. (People
srlo> run things on very old systems; I even have a monitor next to me that
srlo> won’t go above 60Hz in 640x480.)

It will automatically choose the maximal frequency supported by monitor.
So if the monitor supports only 60 Hz (as my TFT :slight_smile: it will not even
try to set up higher frequency. So it is safe enough.

No, it’s not safe. It’s impossible to know the maximum frequency of the
monitor. A substantial number of monitor configurations are wrong, and
your program will think it can set a higher frequency than it really can.
This is a serious problem for SDL programs, which often are run on very
old, rickety systems.

Yes, but
DIB driver does not need these changes I assume because
a) it uses default user monitor frequency, users usually set up
maximal supported frequency so we shall not change it.

It doesn’t. The current DIB code gives me 60Hz video in 2k. I believe
the default refresh rate behavior is different across different versions
of Windows.On Fri, Jan 16, 2004 at 11:32:32AM +0300, Dmitry Yakimov wrote:


Glenn Maynard

I think the patch looks good…but it doesn’t apply to CVS at all:

It’s probably DOS newlines. I’ll look at the patch this weekend.

Thanks!
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Hi,

  1. Setting up 85 Hz of monitor if supported. The reason is that
    Win98 by default sets lowest frequency 60 Hz.
    And we can’t set up maximum frequency because some users can have
    wrong monitor drivers.
    This is important for shareware and commercial programs.
    srlo>
    srlo> I was working on DX some time ago, and I’m sure it sets as a default
    srlo> frequency rate equal to the frequency rate on desktop. I don’t understand
    srlo> why this cannot be done that way?

Default frequency for fullscreen in Win95/98 is 60 Hz all the time, poor user’s eyes :slight_smile:
It is unsuitable for shareware applications.

srlo> I think the patch looks good…but it doesn’t apply to CVS at all:
srlo>
srlo> [icculus at boxx ~/projects/SDL12/src/video/windx5]$ patch -p0 <
srlo> /home/icculus/SDL_dx5video.diff
srlo> patching file SDL_dx5video.c
srlo> Hunk #1 FAILED at 71.

previous version of the patch was reversed
patch, may be flag -R will help.

anyway please download again, I’ve uploaded old and new *.c
files (new from CVS) and diff, so you can make diff file by yourself.
http://activekitten.com/files/sdl_dx_patch.zip

Thank you for answer!–
Best regards,
Dmitry Yakimov, ISDEF member
ActiveKitten.com

Regardless, it’s not acceptable for SDL programs to stop working on these
misconfigured systems; they exist, and they must be dealt with. Remember,
computers that are misconfigured in this way are probably being used by
a non-technical user who doesn’t know better, and won’t be able to fix his
system. To the user, it’ll look like a bug in the application.On Sat, Jan 17, 2004 at 12:08:16PM +0300, Dmitry Yakimov wrote:

srlo> I was working on DX some time ago, and I’m sure it sets as a default
srlo> frequency rate equal to the frequency rate on desktop. I don’t understand
srlo> why this cannot be done that way?

Default frequency for fullscreen in Win95/98 is 60 Hz all the time, poor user’s eyes :slight_smile:
It is unsuitable for shareware applications.


Glenn Maynard

At 12:08 2004-01-17 +0300, you wrote:

  1. Setting up 85 Hz of monitor if supported. The reason is that
    Win98 by default sets lowest frequency 60 Hz.
    And we can’t set up maximum frequency because some users can have
    wrong monitor drivers.
    This is important for shareware and commercial programs.
    srlo>
    srlo> I was working on DX some time ago, and I’m sure it sets as a default
    srlo> frequency rate equal to the frequency rate on desktop. I don’t
    understand
    srlo> why this cannot be done that way?

Default frequency for fullscreen in Win95/98 is 60 Hz all the time, poor
user’s eyes :slight_smile:
It is unsuitable for shareware applications.

You can set desktop default refresh rate and this is done by most users (I
don’t know many win95/98 users which are working in 60Hz). After this, 99%
of applications automaticaly sets this refresh rate when opening a new
fullscreen. SDL is the 1% which isn’t doing it. Is it really so difficult
to do it the same way other applications are doing it?

Default frequency for fullscreen in Win95/98 is 60 Hz all the time, poor
user’s eyes :slight_smile:
It is unsuitable for shareware applications.

Shareware died a decade ago, thankfully. :slight_smile: Not reliably working on
poorly-configured systems is unsuitable for commercial applications and
Free Software alike.

You can set desktop default refresh rate and this is done by most users (I

Incorrect. Almost every machine I’ve seen that is being used by a typical
non-technically-competent, non-“gamer” user is at 60Hz. (The first thing I
do when I sit down at one of those is fix that.)

I’m speaking from the experience of having sat down at many such machines.

don’t know many win95/98 users which are working in 60Hz). After this, 99%
of applications automaticaly sets this refresh rate when opening a new
fullscreen. SDL is the 1% which isn’t doing it. Is it really so difficult
to do it the same way other applications are doing it?

Sorry, you’ve got it backwards.

Most modern games don’t touch the refresh; that’s why tools exist to hack
the refresh list. SDL is in the 99.9% that isn’t doing it, because doing
so makes programs not work on some systems.

Notice how Windows still asks, after changing the refresh rate in the
control panel, “click YES if can you see this, otherwise reverting in 15
seconds”? Same reason: the system can’t know for sure if a refresh works.

Doing this properly means exposing a list of available refresh rates for
a given configuration, and an interface for selecting one, so applications
can implement a similar mechanism.

Anyhow, I feel like I’m repeating myself, so I’ll just trust that Sam
will read this and understand why using non-60Hz refresh rates by default
is a bad idea.

The only potentially safe trick is to look at the desktop resolution, and if
the resolution being set by SDL is <= that, use the highest available refresh
rate <= the desktop refresh. That is, if the desktop is 800x600 at 80Hz, and
we’re setting 640x480, we can probably use any available refresh <= 80.
However, if we’re setting 1024x768, we can infer nothing, and should use
60Hz. (I havn’t tried this, so I can’t guarantee this would always work,
either.)On Sat, Jan 17, 2004 at 11:58:39PM +0100, Archibald wrote:


Glenn Maynard

Hi,

It will automatically choose the maximal frequency supported by monitor.
So if the monitor supports only 60 Hz (as my TFT :slight_smile: it will not even
try to set up higher frequency. So it is safe enough.

No, it’s not safe. It’s impossible to know the maximum frequency of the
monitor. A substantial number of monitor configurations are wrong, and
your program will think it can set a higher frequency than it really can.
This is a serious problem for SDL programs, which often are run on very
old, rickety systems.

I’ve found some information about 60 Hz:

Monitor flicker particularly affects people in the autism spectrum including people with
Asperger’s Syndrome. Monitor flicker can also provoke migraines.

you can read it here:
http://www.scn.org/help/monitor.html

How many user’s monitors does not support 85 Hz AND their monitor
driver is wrong to say about it? 3%, 5%?
Is it old 14" monitors and Windows95?

The way out is to provide programmer with SDL API that can change
monitor frequency. And programmer could decide - either use it or not.
And this api shall support non Windows environments (may be being
bogus).

for example:

int frequency;

SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO);
frequency = SDL_GetMaxRefreshRate(800, 600, 32, SDL_HWSURFACE|SDL_FULLSCREEN | SDL_DOUBLEBUF);
SDL_SetDefaultRefreshRate(frequency);
SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE| SDL_FULLSCREEN | SDL_DOUBLEBUF);

If frequency == 0 set up system default refresh rate.
By default this variable in SDL is 0, so nothing happens if programmer
have not changed it. It provide us with backward compatibility for
all applications.

And SetVideoMode uses default frequency that was set by programmer,
not by OS.

It is enough to add bogus SDL_GetMaxRefreshRate &
SD_SetDefaultRefreshRate for all video drivers and then step by step
fulfill them. (I’m ready to write such code for DirectX and WinDIB).

What do you say?

p.s. I’m really need such feature, it is related to a question - either
to use SDL for games or not.–
Best regards,
Dmitry Yakimov, ISDEF member
ActiveKitten.com

[Uhm, this is sdl at libsdl.org not sdl-request at libsdl.org!]

Dmitry Yakimov wrote:

Monitor flicker particularly affects people in the autism spectrum
including people with
Asperger’s Syndrome. Monitor flicker can also provoke migraines.

Wow, so Windows makes really ill. Maybe one could use that to sue MS
becauses they didn’t tell that 60Hz can screw you. No, really, TV
monitors usually run at 50Hz or 60Hz, so games for video consoles
always include such a warning in their manuals. I mean, Windows 95
wasn’t released yesterday, don’t you think people wouldn’t have
noticed by now that 60Hz is way too low with a CRT? Well, maybe
they’re masochists.

How many user’s monitors does not support 85 Hz AND their monitor
driver is wrong to say about it? 3%, 5%?
Is it old 14" monitors and Windows95?

How f*cking screwed is Windows? Hell, it’s trivial:

if (ddc_available()) {
use_ddc();
if (is_screwed(monitor) || is_screwed(user))
sue_monitor_or_graphics_card_vendor();
} else {
/* How many Windows (PC!!) users have such an old monitor?? */
use_60Hz_or_the_refresh_rate_configured_by_the_user();
if (is_screwed(monitor) || is_screwed(user))
blame_user();
}

The way out is to provide programmer with SDL API that can change
monitor frequency.

Sorry, but that’s really insane. Either, the OS (or the like) handles
this perfectly or the user has to correct the settings. (Hint:
sand dry, tearing or rectangular eyes imply wrong settings).

And programmer could decide - either use it or not.

Why would he? It’s not his job. Maybe you want an interface to fix
IRQ and DMA settings with SDL, too?

And this api shall support non Windows environments (may be being
bogus).

A nop should do the job there.

It provide us with backward compatibility for all applications.

If everyone can safely ignore those functions and you want to
implement it, go ahead, it’s your time.

p.s. I’m really need such feature, it is related to a question - either
to use SDL for games or not.

Shutter glasses?

[ I might be bashing someone here but you can be sure it’s not you. ]–
Christian
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 186 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20040118/0b9d0202/attachment.pgp

[…]

What do you say?

I’d say SDL should try to use the maximum allowed refresh rate, and
rely on the system configuration to be correct. I’ve seen very few
commercial games that have a user option for refresh rate, but that
doesn’t seem to be a problem.

As to tweaking, Windows and Linux lets users configure drivers to use
DDC and/or custom settings on a per-mode basis, and I’d guess most
other OSes do too. I wouldn’t want games to explicitly select their
refresh rate normally, as that just opens up the possibility of my
having to adjust my monitor several times for the same resolution.
(Different refresh rate means different mode to a monitor. Monitorns
can’t even tell the exact resolution; only the number of scan lines
and the line and frame frequency.) Annoying and pointless - and
sometimes impossible, when modes are so similar that they land in the
same preset on the monitor.

p.s. I’m really need such feature, it is related to a question -
either to use SDL for games or not.

Well, regardless of what changes you may need, if they aren’t going
into mainstream SDL, you still have the option of distributing your
game with a custom SDL lib. That’s why serious libraries, tools and
applications come with source code; to be as useful as possible.

Though maybe not as relevant to games(*), the source also comes in
very handy if you end up maintaining some software over a period of
many years. Proprietary libs and tools will normally be long since
dead and forgotten a few years after you picked them up.

Free your mind - the community is not like Microsoft! :wink:

(*) OTOH, Doom still seems to be alive after ten years…
I think the new improved engines with high resolutions
and OpenGL support have helped a great deal. People are
still developing and using Doom level editors!

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Sunday 18 January 2004 14.15, Dmitry Yakimov wrote:

Hi,

You can set desktop default refresh rate and this is done by most users (I
don’t know many win95/98 users which are working in 60Hz). After this, 99%
of applications automaticaly sets this refresh rate when opening a new
fullscreen.

No, in Win95/98 Direct Draw sets up by default 60 Hz no matter what
system settings are.

And all SDL apps on all Win95/98 (and on at least half Win2000/WinXP)
uses 60 Hz, no matter what default settings are.

That’s why this is the problem.

Most modern games don’t touch the refresh; that’s why tools exist to hack
the refresh list. SDL is in the 99.9% that isn’t doing it, because doing
so makes programs not work on some systems.

Most modern games touches the refresh rate, I say it as member of
swrus-games conference, I know dozens game authors and companies and
ALL of them changes refresh rate in their games because 60 Hz is no so
good for commercial game (and for user too).

The only potentially safe trick is to look at the desktop resolution, and if
the resolution being set by SDL is <= that, use the highest available refresh
rate <= the desktop refresh.

In Win95/98 it can’t be done in all cases :frowning:

The way out is to provide programmer with SDL API that can change
monitor frequency.
And programmer could decide - either use it or not.

Why would he? It’s not his job.

It is. His job is to write perfect program (game).

Maybe you want an interface to fix
IRQ and DMA settings with SDL, too?

No, this is done by OS.

I’d say SDL should try to use the maximum allowed refresh rate, and=20
rely on the system configuration to be correct. I’ve seen very few=20
commercial games that have a user option for refresh rate, but that=20
doesn’t seem to be a problem.

You are right, but sometimes user has got incorrect monitor drivers in
Windows, so we cannot know true maximum allowed refresh rate, but we
still can get list of supported refresh rates. For game it is OK (±
5% of users no matter), but for well known graphics library I suppose
it is unsuitable.

My patch (I posted it here) goes this way.

But now I prefer this API:

int frequency;

SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO);
frequency = SDL_GetMaxRefreshRate(800, 600, 32, SDL_HWSURFACE|SDL_FULLSCREEN | SDL_DOUBLEBUF);
SDL_SetDefaultRefreshRate(frequency);
SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE| SDL_FULLSCREEN | SDL_DOUBLEBUF);

This is optional in use, compatible with old programs and useful for
those who wants change refresh rate.

I ask you to add two bogus functions SDL_GetMaxRefreshRate and
SDL_SetDefaultRefreshRate for all SDL video drivers like this:

int SDL_GetMaxRefreshRate(int width, int height, int bpp, int flags) { return 0; }
void SetDefaultRefreshRate(int frequency) { };

Then we can step by step fulfill them.–
Best regards,
Dmitry Yakimov, ISDEF member
ActiveKitten.com

For game it is OK (± 5% of users no matter),

What a horrible mindset to have. Cover your mouth, it might be catching …

SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO);
frequency = SDL_GetMaxRefreshRate(800, 600, 32, SDL_HWSURFACE|SDL_FULLSCREEN | SDL_DOUBLEBUF);
SDL_SetDefaultRefreshRate(frequency);
SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE| SDL_FULLSCREEN | SDL_DOUBLEBUF);

This is optional in use, compatible with old programs and useful for
those who wants change refresh rate.

More generic would be

int frequencies[SDL_MAX_FREQS];
/* get all refreshes, sorted */
frequencies = SDL_GetAvailableRefreshRates( …, frequencies );

int max_refresh = 60;
for( int i = 0; frequencies[i]; ++i )
max_refresh = frequencies[i];On Sun, Jan 18, 2004 at 11:40:31PM +0300, Dmitry Yakimov wrote:


Glenn Maynard

It’s a massive pain to do so, though. I’ve done so for a long time,
for my own refresh rate hack and some other stuff. It’s less of a pain
in Windows, since most programs that use a library include their own
copy; it’s a real pain in Unix, where programs are expected to use the
system copy if at all possible, and setting up the build is annoying.
(I had to do this for a long time, for the alpha blit fix that was
merged in 1.2.6.)On Sun, Jan 18, 2004 at 05:34:52PM +0100, David Olofson wrote:

Well, regardless of what changes you may need, if they aren’t going
into mainstream SDL, you still have the option of distributing your
game with a custom SDL lib. That’s why serious libraries, tools and
applications come with source code; to be as useful as possible.


Glenn Maynard

Thank you. I’ve uploaded unified diff version:
http://activekitten.com/files/SDL_dx5video.diff

Thanks! I’ve tweaked your patch and applied it to CVS.
Can you test it to make sure I haven’t broken anything?

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Hi,

Thanks a lot! Now I (and many authors can use it without manual tweaking).
It looks OK, small notice - maybe it is better to change printf to
#ifdef DDRAW_DEBUG
fprintf(stderr, … );
#endif

I’ve compiled with help of MSVC 7.1.
imho it is better to set up the following options in Release configuration
for VC7:

  • Enable enchansed instruction set (SSE2)
  • Enable intrinsic functions
  • Runtime library Multi-threaded (/MT) (because not all computers does
    have msvcr71.dll, this dll to be honest ships only with MSVC 7.1 :slight_smile:

I now use TFT monitor, that can’t use more than 60 Hz, so, anybody,
please run hardware blitting in CVS version with double buffering in Windows with
enabled vSync and check FPS (it must be 85 (!)

(if you see more than 85 it means that you have not enabled vSync).

You can check fps with help of Fraps utility - http://www.fraps.com>> Thank you. I’ve uploaded unified diff version:

http://activekitten.com/files/SDL_dx5video.diff

Thanks! I’ve tweaked your patch and applied it to CVS.
Can you test it to make sure I haven’t broken anything?


Best regards,
Dmitry Yakimov, ISDEF member
ActiveKitten.com