[SDL] Surface getting munged
Lilith Calbridge
lilith at dcccd.edu
Wed Jul 26 21:00:52 PDT 2006
Just ran a test and it never hits the default case.
Lilith
>>> On 7/26/2006 at 10:54 PM, in message
<001e01c6b130$4f3b7100$6501a8c0 at ALAN>,
Atrix2 at cox.net wrote:
> Lilith, if you haven't tested this yet, in your default case for your
switch
> I'd make it log to a file that it hit the default just to see if it's
ever
> getting an invalid value for the "side" parameter.
>
> -----Original Message-----
> From: sdl-bounces+atrix2=cox.net at libsdl.org
> [mailto:sdl-bounces+atrix2=cox.net at libsdl.org] On Behalf Of Lilith
Calbridge
> Sent: Wednesday, July 26, 2006 8:48 PM
> To: sdl at libsdl.org
> Subject: [SDL] Surface getting munged
>
> 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
>
>
>
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
>
>
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
More information about the SDL
mailing list