# SDL\_CreateRGBSurface is black?

**URL:** <https://discourse.libsdl.org/t/sdl-creatergbsurface-is-black/17508>\
**Category:** SDL Development\
**Created:** [July 11, 2010, 9:20pm UTC](https://discourse.libsdl.org/t/sdl-creatergbsurface-is-black/17508 "2010-07-11T21:20:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mutable](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/dc4da7/32.png) [@mutable](https://discourse.libsdl.org/u/mutable)\
**Post date:** [July 11, 2010, 9:20pm UTC](https://discourse.libsdl.org/t/sdl-creatergbsurface-is-black/17508/1 "2010-07-11T21:20:23Z")

</div>

Hi i’m new here and my english isn’t good, but i have the following code:

Code:

SDL\_Surface \* tile = SDL\_CreateRGBSurface(  
SDL\_SWSURFACE,  
tilesize[0],  
tilesize[1],  
this.\_tileset.format.BitsPerPixel,  
0, 0, 0, 0  
);

for (ushort y = 0; y \< height; y++) {  
for (ushort x = 0; x \< width; x++) {  
SDL\_Rect rect = {  
cast(ushort) (x \* 16),  
cast(ushort) (y \* 16),  
16, 16  
};

```
	SDL_BlitSurface(this._tileset, &rect, tile, null);
	if (!tile) {
		writeln("Tile konnte nicht aus dem Tileset geladen werden");
		exit(0);
	}

	this._tiles ~= tile;
}

```

}

The tileset grafic is ok and the code give me no error, the lopp runs correct, but if i try to take one of the tiles to blit them on the screen, i get a black rectangle.  
How is that possible? I think that SDL\_CreateRGBSurface create the failure, but what think the others and can anyone help me?

---

<div class="post-metadata">

**Author:** ![mutable](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/dc4da7/32.png) [@mutable](https://discourse.libsdl.org/u/mutable)\
**Post date:** [July 11, 2010, 10:28pm UTC](https://discourse.libsdl.org/t/sdl-creatergbsurface-is-black/17508/2 "2010-07-11T22:28:06Z")

</div>

I have dissolved the problem, i have add simply  
Code:  
0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff

to SDL\_CreateRGBSurface.  
But now i can get the individual tile but not the total map.  
For this i have the following code:

Code:

SDL\_Surface \* map = SDL\_CreateRGBSurface(  
SDL\_SWSURFACE,  
cast(ushort) (5 \* 16),  
cast(ushort) (5 \* 16),  
32,  
0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff  
);

ushort gid = [std.conv.to](http://std.conv.to)!(ushort)(item\_child.tag.attr[“gid”]);  
SDL\_Surface \* tile = tileset.getTile(gid);  
if (!tile) {  
writefln(“Tile ‘%d’ konnte nicht geladen werden”, gid);  
exit(0);  
}

ushort[2] pos = [  
cast(ushort) (column \* 16),  
cast(ushort) (line \* 16)  
];  
SDL\_Rect rect = {  
pos[0], pos[1],  
16, 16  
};

SDL\_BlitSurface(map, null, tile, &rect);

column += 1;  
if (column \>= 5) {  
column = 0;  
line += 1;  
}

What’s now the problem? 😕

---

<div class="post-metadata">

**Author:** ![Brian\_Barrett](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/brian_barrett/32/427_2.png) [@Brian\_Barrett](https://discourse.libsdl.org/u/Brian_Barrett)\
**Post date:** [July 12, 2010, 2:40pm UTC](https://discourse.libsdl.org/t/sdl-creatergbsurface-is-black/17508/3 "2010-07-12T14:40:12Z")

</div>

Your code lacks error checking. Almost every SDL function can return an  
error. See the SDL documentation for the different function signatures and  
how to detect these errors ([http://www.libsdl.org/cgi/docwiki.cgi](http://www.libsdl.org/cgi/docwiki.cgi)) You  
should detect these and try obtain the value of “SDL\_GetError()”, which  
might hint at what is going on.

Regards,  
– Brian.On 11 July 2010 23:28, mutable wrote:

> What’s now the problem? 😕
