This may not be the place to ask this but people on this list are more
apt to understand the SDL_Surface structure than other forums. This is
probably more of a C/C++ behavior question but someone familiar with the
structures involved might give me a quicker answer. Please feel free to
contact me off-list if necessary.
The problem popped us as logos I’d been blitting to my screen surface
quit showing up. A debug session showed that the rectangles I was using
to tell it what portion of the screen to draw them were getting set to
zero, an indication that SDL_BlitSurface was having a problem with it.
This meant something else was messing up other factors. Here’s my
scenario and here’s what I found…
SCR_Object is a class that has as a member SDL_Surface *image and
SDL_Rect rect. Everything’s fine up to a point. I wrote a function
outside the class to position another surface against the first one and
centered on either top, bottom, left or right. It looks like this:
void SCR_SetDishPos (SCR_Object *dish, SCR_Object companion, Uint8
side)
{
SDL_Rect ctemp = companion.GetRect();
SDL_Rect dtemp = dish->GetRect();
switch (side) {
case right:
ctemp.x += ctemp.w;
ctemp.y += (ctemp.h - dtemp.h)/2;
break;
case top:
ctemp.x += (ctemp.w - dtemp.w)/2;
ctemp.y -= dtemp.h;
break;
case left:
ctemp.x -= dtemp.w;
ctemp.y += (ctemp.h - dtemp.h)/2;
break;
case bottom:
ctemp.x += (ctemp.w - dtemp.w)/2;
ctemp.y += ctemp.h;
break;
default:
break;
}
ctemp.h = dtemp.h;
ctemp.w = dtemp.w;
dish->SetRect(ctemp);
}
And a call to the function looks like this:
SCR_SetDishPos (&CVCDish, CVC, right);
The function calculates and (properly) sets the rectangle for CVCDish
to that it nests against the right side of the logo called CVC.
Everything about CVC is fine in the debug session up to the end of the
function. But when I return from the function (which returns nothing)
EVERYTHING that CVC.image points to is set to 0xFEEE. Every pair of
bytes pointed to by image is FEEE.
There’s nothing in the function or the call to the function that
references image. This happens with any “companion” object I pass to
the function. I can see that even a copy of the object can allow a
function to access the address of the image surface but there’s nothing
in the code that even remotely does that. I’ve checked the value of
image for each object and it isn’t that image, as a pointer, is getting
pointed elsewhere.
I can certainly rewrite the code in at least two other ways but I’d
rather try to nail this.
Help?
Lilith