I ran across something that doesn't quite make sense to me...
I was trying to pass a "Surface *" into a function which deletes the image and makes a new one. The program wasn't working right, so I stepped through. The pointer was passed, then the image created, but then the new pointer was not passed back out of the function.
I would have thought that anything with a * would be modifiable unless it has the const keyword. The only way I got it to work was by passing a "Surface **".
Is this something about the way a Surface is defined or am I just loosing it?
Here's some code to explain better:
This Works:
This doesn't work:
I was trying to pass a "Surface *" into a function which deletes the image and makes a new one. The program wasn't working right, so I stepped through. The pointer was passed, then the image created, but then the new pointer was not passed back out of the function.
I would have thought that anything with a * would be modifiable unless it has the const keyword. The only way I got it to work was by passing a "Surface **".
Is this something about the way a Surface is defined or am I just loosing it?
Here's some code to explain better:
This Works:
- Code:
void ScaleTheImg(DisplayDevice * display, Surface * originalimg, Surface ** scaledimg)
{
if(*scaledimg != NULL)
delete scaledimg;
static tempw, temph;
if( (tempw = originalimg->GetWidth() / rblit.scale) < 1) tempw = 1;
if( (temph = originalimg->GetHeight() / rblit.scale) < 1) temph = 1;
*scaledimg = display->CreateSurface(tempw ,temph);
Surface* screen = display->SetRenderTarget(*scaledimg);
Rect r;
r.Set(0, 0, tempw, temph);
display->BlitStretch(r, originalimg);
display->SetRenderTarget(screen);
(*scaledimg)->SetColorMask(Color(255,0,255));
}
This doesn't work:
- Code:
void ScaleTheImg(DisplayDevice * display, Surface * originalimg, Surface * scaledimg)
{
if(scaledimg != NULL)
delete scaledimg;
static tempw, temph;
if( (tempw = originalimg->GetWidth() / rblit.scale) < 1) tempw = 1;
if( (temph = originalimg->GetHeight() / rblit.scale) < 1) temph = 1;
scaledimg = display->CreateSurface(tempw ,temph);
Surface* screen = display->SetRenderTarget(scaledimg);
Rect r;
r.Set(0, 0, tempw, temph);
display->BlitStretch(r, originalimg);
display->SetRenderTarget(screen);
scaledimg->SetColorMask(Color(255,0,255));
}