views:

903

answers:

4

We're maintaining an old video game that uses a full-screen 256-color graphics mode with DirectDraw. The problem is, some applications running in the background sometimes try to change the system palette while the game is running, which results in corrupted graphics.

We can (sometimes) detect when this happens by processing the WM_PALETTECHANGED message. A few update versions ago we added logging (just log the window title/class/process name), which helped users identify offending applications and close them. MSN Live Messenger was a common culprit.

The problem got worse when we found out that Windows Vista (and 7) does it "by itself". The WM_PALETTECHANGED parameters point towards CSRSS and the desktop window. In Vista, a workaround that often worked was to open any folder (Computer, Documents, etc.) and leave it open while running the game. Sounds ridiculous, but it worked - in most cases. In Windows 7, not even this workaround worked any more. Users found that stopping some services (Windows Update and the indexing service) also resolved the problem on some configurations.

Some time ago I just started trying random things in hope of finding a solution. I found that setting the GDI palette (using Create/SelectPalette) before setting the DirectDraw palette (using IDirectDrawPalette::SetEntries) would restore the palette after it became corrupted (WM_PALETTECHANGED handler). SetSystemPaletteUse and calling SetPalette on the primary surface helped some more. However, there is still perceivable flickering when an application tries to steal the palette, which is especially prominent during fades.

Question: is there a way to get a "real" exclusive palette, which completely disallows other applications changing the Windows palette as long as our game retains focus?

A: 

Apparently "an application should not call SetSystemPaletteUse, unless it has a maximized window and the input focus". Perhaps some other program is misbehaving. That description makes it sound very much like Microsoft hope all programs will cooperate and offer no way to compel them to do so. It's like being back on Windows 3.1. :)

Random suggestion: have you tried SetSystemPaletteUse with the SYSPAL_NOSTATIC256 parameter?

You could also see if your palette contains the 20 Windows reserved colours; if so, it means that any other palettised program that just uses Windows colours will not need to change the palette in order to render itself, as I understand it.

Kylotan
When the palette would get stolen, it would usually be the entire (or most of the visible) palette, so it probably wasn't an application setting SetSystemPaletteUse. We added a SetSystemPaletteUse(dc,SYSPAL_NOSTATIC256) call, and it helped in some situations, but hasn't resolved the main problem. Palette space is tight as it is, so we'd rather stay with our occasional flickering than repalletise game or user content.
CyberShadow
+3  A: 

What you can do is a 'simple' workaround. Since your game is an old game it is probably no match to current hardware, which is why this trick will work:

  • Blit everything to an offscreen buffer (memory)
  • convert the 8bit buffer to 16 bit(or 32 bit) using the current palette (so also done in memory)
  • copy the contents of the 16 bit(or 32bit) buffer to the backbuffer of the screen
  • flip the screenbuffer.

This will require minimal changes to your game, and will get rid of palette issues completely, though your game can still use all it's palette trickery

R

Toad
A: 

I don't know DirectX at all, but I'd suggest trying to do your rendering off-screen then converting to the display depth... I imagine you can get Direct2D to do all that for you...

Spudd86
+1  A: 

Someone actually found a registry entry fix for this, here:

http://forums.electronicarts.co.uk/command-conquer-past-games/284289-common-problems-tfd-updated-15-02-2010-a.html

Look for "scrambled colours" on that page and you'll get to the part with the fix you need.

Nyerguds
Thanks, posted a script for our users to test, let's see how it'll work for our game in practice.
CyberShadow
Yep, seems to work :) Thanks!
CyberShadow