Charles Noon
Charles Noon

Reputation: 601

SDL 1.2.15 extension of surface issue

When I make a surface larger by manipulating the h and w members, I end up with strange results - the added space is filled with garbled versions of what was already on the surface. Is there some way I can avoid this / clear the added space (set it to alpha)?

enter image description here

Upvotes: 0

Views: 71

Answers (1)

HolyBlackCat
HolyBlackCat

Reputation: 96013

I only used SDL 2, but I think I know, what wrong with your code.

Pixel data of surface is a simple 1D array of pixels. Length of this array is equal to w*h. Accessing a pixel is implemented like this: pixeldata[y * w + x].

It means, you can't just change two members to change dimensions of the surface. It will result in out-of-bounds access to pixel data array when using this surface.

So, if you want to resize a surface, you should create a new surface and copy needed pixels to it.

Of course, it's possible to resize it manually, but you should not try to do it without a good reason.

Upvotes: 2

Related Questions