Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Scavenger on Sun 03/10/2010 03:52:31

Title: GetPixel is returning -1?! [SOLVED]
Post by: Scavenger on Sun 03/10/2010 03:52:31
So I'm working on functions for my game (which I'm programming from the bottom up, as the last version had unworkable code.), and I need to judiciously use GetPixel since I don't want to use plugins this time. Once again, working in 8-bit. I am using 3.1.2 SP1, but I did compile it on 3.2, with no improvement.

As I was working on a colourisation function, I noticed I was getting a lot of strange crashes about "Array Out of Bounds: Range 0-255, not -1". So I tested it a bit and found out it wasn't my shoddy coding producing this result, but the GetPixel function itself.

I'm not sure quite what's causing it, and I'm pretty sure GetPixel isn't supposed to give values like that.

EDIT: The problem has been found and a workaround given. Quite a surprise!

I changed palette slot 254 to Magenta, which messed up the background colours. I have since reimported the background, but maybe that's what's going wrong.

Thanks, guys :) I am pretty hopeless without y'all.
Title: Re: GetPixel is returning -1?!
Post by: GarageGothic on Sun 03/10/2010 04:07:59
I'm guessing that GetPixel returns COLOR_TRANSPARENT (which is very likely defined as -1) for RGB(255,0,255) colored pixels no matter their position in the palette, so check whether the color value is COLOR_TRANSPARENT before using it as an array index.


int pal_index = Surface.GetPixel (i, j);
if (pal_index != COLOR_TRANSPARENT) {
 Surface.DrawingColor = _C8PaletteMap [pal_index];
 Surface.DrawPixel (i, j);
 }
Title: Re: GetPixel is returning -1?!
Post by: Scavenger on Sun 03/10/2010 15:00:03
It was returning COLOR_TRANSPARENT! Very odd, especially in an 8-Bit game - since there's already a transparent colour