Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Global palettes bugs?
#6
"On the "blueish" color palette, the renderer is reading memory past the data of the palette itself, so you're getting random data. You colud be getting segmentation fault errors, too. For performance reasons the renderer doesn't compare palette bounds on each pixel, it assumes you provided a suitable palette. By using undersized palettes you're working outside of prerequisites, so unwanted effects are not a bug, just undefined behavior."

Hi! I think I have an idea for this problem.

No if-statements are necessary. I think you can just do something like myPalette[paletteIndex & (255 + (paletteIndex >= myPalette.getLength()))]

Explanation : We do a binary and between our index and (255 + (paletteIndex >= myPalette.getLength())
But if paletteIndex is equals or greater to the length of the palette, this expression will add 1 to 255. Supposing 255 is an unsigned char, it will overflow, causing to do paletteIndex & 0 which will result in 0. You'll then pick the 0th index.

If the expression is false, you will do paletteIndex & 255, which will give you the current palette index.

What do you think about this idea? Would it tax the performances a lot? Since it's branchless programming, I don't think it will hurt the branch prediction mechanism but I may be wrong.


There are some other solutions the programmer can do such as :
Sanitize the graphics, by that, I do mean "clipping each index under the palette length"
Or always using 256 colors palettes.
Reply


Messages In This Thread
Global palettes bugs? - by System64 - 05-11-2024, 05:22 AM
RE: Global palettes bugs? - by megamarc - 05-30-2024, 05:37 AM
RE: Global palettes bugs? - by System64 - 05-31-2024, 03:08 AM
RE: Global palettes bugs? - by megamarc - 05-31-2024, 07:15 AM
RE: Global palettes bugs? - by System64 - 05-31-2024, 09:00 AM
RE: Global palettes bugs? - by System64 - 07-22-2024, 10:06 PM
RE: Global palettes bugs? - by megamarc - 08-10-2024, 05:17 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)