www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/08/31/16:34:08

Xref: news2.mv.net comp.os.msdos.djgpp:8109
From: John Sabean <docmani AT eng DOT umd DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: djgpp/allegro - help! - quick question
Date: Wed, 28 Aug 1996 11:25:33 -0400
Organization: University of Maryland, College Park
Lines: 65
Message-ID: <322464ED.167EB0E7@eng.umd.edu>
References: <3223B9FC DOT 5C79 AT mbnet DOT mb DOT ca>
NNTP-Posting-Host: x-15.umd.edu
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Alex Demko wrote:
> 
> ¦PALETTE *new_truepal()
> ¦{
> ¦  PALETTE *pal = (PALETTE *)malloc(sizeof(PALETTE));
> ¦  unsigned char r,g,b,i=0;
> ¦  for (r=0; r<6; r++)
> ¦   for (g=0; g<6; g++)
> ¦    for (b=0; b<6; b++)
> ¦     {
> ¦     pal[i]->r=r*12;//causes GPF here
> ¦     pal[i]->g=g*12;
> ¦     pal[i]->b=b*12;
> ¦     pal[i]->filler=0;
> ¦     i++;
> ¦     }
> ¦  return pal;
> ¦}
> 
> After I use the above routine in my code, I get a GPF in the marked
> area. It won't GPF the first time it hits the marked code area, but
> it will interate the inner loop about 40 (actual number depends on
> phase of the moons) times, then GPFs. Am I dereferencing the
> array/struct wrong? Please help, this thing is killing me :)
> 
> The code compiled error free.
> 
> Thanks
> 

Perhaps since you've only allocated one palette structure and
you're trying to access more than one?

Look at the allegro.h file. You'll find the line:
>typedef RGB PALLETE[PAL_SIZE];

I always have a difficult time keeping typedef'd arrays and pointers
straight. It seems you might have this problem too :)
To avoid this confusion, I usually choose to work with the RGB structure
directly. I would have written the code as:

RGB *new_truepal()
{
	RGB *pal;
	unsigned char r,g,b,i = 0;

	pal = (RGB *)malloc(sizeof(RGB)*PAL_SIZE);

	for(r=0; r < 6; ++r)
		for(g = 0; g < 6; ++g)
			for(b = 0; b < 6; ++b){
				pal[i].r = r*12;
				pal[i].g = g*12;
				pal[i].b = b*12;
				pal[i].filler = 0;
				++i;
			}

	return(pal);
}


This gives you an RGB array that you can easily pass to any of
allegro's palette functions. And should accomplish what you're trying
to accomplish.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019