# Clipping Question

This topic is 4666 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm sure this is a very simple thing to do, because it is. But I've researched and researched SDL commands for clipping, and I think I'm doing things right, but when I get down to run-time, I get a segmentation fault. So I'm obviously doing something wrong. Here's a simplified form of my situation: Let's say I have a 32x16 image with two 16x16 tiles in it, a tileset basically. Now, what I want to do is create a 16x16 sprite that uses 1/2 of the 32x16.
//So this is where I'm getting messed up.

SDL_Surface *tileset;
SDL_Surface *terrain;

// Ok so 16x32 tileset is loaded, now I want to blit the left side of that to the terrain surface.

srcRect.x = 0;
srcRect.y = 0;
srcRect.w = 16;
srcRect.h = 16;

SDL_BlitSurface(tileset, &srcRect, terrain, NULL);

// Now the left side of the 16x32 should be the new surface "terrain"
// And now I'm going to blit surface to screen.

SDL_BlitSurface(terrain, NULL, screen, positionRect);


Now, does anyone see any theory mishaps? I'm at a loss. The only thing left for me to try I guess is using SDL_CreateRGBSurface(..) on "terrain" before blitting the left side of "tileset" to "terrain". Maybe "terrain" has to be initialized first or somethin, who knows? Hopefully, you do. Thanks in Advance! toXic1337

##### Share on other sites
terrain is NULL (or even worse, it's uninitialized), so you're trying to blit to a NULL surface. You've got to create the terrain surface first.

1. 1
2. 2
3. 3
Rutin
17
4. 4
5. 5

• 14
• 9
• 10
• 12
• 17
• ### Forum Statistics

• Total Topics
632906
• Total Posts
3009155
• ### Who's Online (See full list)

There are no registered users currently online

×