[SDL] RotoZoom is great, but...
Torsten Giebl
wizard at syntheticsw.com
Sat Sep 2 09:21:16 PDT 2006
Hello !
> void Visuals::DisplayBMPonScreenBufferRotoZoom(Sint8 spriteNumber, Sint16
> xScreenPos, Sint16 yScreenPos, double angle, double zoom) {
> SDL_Rect destinationRectangle;
>
>
> destinationRectangle.x = xScreenPos; destinationRectangle.y = yScreenPos;
>
>
> SDL_Surface *temp = SpriteBMP[spriteNumber];
> SDL_Surface *temp2 = rotozoomSurface(temp, angle, zoom, 0);
>
>
> temp->clip_rect.x = 0; temp->clip_rect.y = 0; temp->clip_rect.w = 640;
> temp->clip_rect.h = 480;
>
> temp2->clip_rect.x = 0; temp2->clip_rect.y = 0; temp2->clip_rect.w = 640;
> temp2->clip_rect.h = 480;
>
> destinationRectangle.w = temp2->w; destinationRectangle.h = temp2->h;
>
> destinationRectangle.x -= (temp2->w / 2); destinationRectangle.y -=
> (temp2->h / 2);
>
>
> SDL_BlitSurface(temp2, NULL, Screen, &destinationRectangle);
>
>
> SDL_FreeSurface(temp);
> SDL_FreeSurface(temp2);
> }
>
>
>
>
>
> Above compiles and runs, but crashes on 2nd call - any ideas ?
Yup, SDL_FreeSurface (temp) does delete
your original surface, as
> SDL_Surface *temp = SpriteBMP[spriteNumber];
does not copy the original surface from SpriteBMP [spriteNumber]
into temp, it just sets temp with the reference to SpriteBMP ...
Then the first time you free the original surface and
the 2nd time try to rotate a NULL surface.
CU
More information about the SDL
mailing list