SDL実行可能ファイルから3つのエラーコードを取得していますが、SDLの色を値で渡す場所にあるようで、理由がわかりません。
void Map::draw(SDL_Surface *surface, int level){
//the surface is locked
if ( SDL_MUSTLOCK(surface) )
SDL_LockSurface(surface);
long start= (long)level * this->xmax * this->ymax;
long end= (long)(level+1) * this->xmax * this->ymax;
for(long n=start; n<end; ++n){
Node *pn= this->nodes+n;
//exit(18); //exit code is 18
draw_pixel_nolock(surface, pn->location.x, pn->location.y, colors[pn->content]);
}
//the surface is unlocked
if ( SDL_MUSTLOCK(surface) )
SDL_UnlockSurface(surface);
}
そして、呼び出されるグラフィック関数は次のとおりです。
SDL_Color colors[]= { {0,0,0}, {0xFF,0,0}, {0,0xFF,0}, {0,0,0xFF} };
void PutPixel32_nolock(SDL_Surface * surface, int x, int y, Uint32 color)
{
Uint8 * pixel = (Uint8*)surface->pixels;
pixel += (y * surface->pitch) + (x * sizeof(Uint32));
*((Uint32*)pixel) = color;
}
void PutPixel24_nolock(SDL_Surface * surface, int x, int y, Uint32 color)
{
Uint8 * pixel = (Uint8*)surface->pixels;
pixel += (y * surface->pitch) + (x * sizeof(Uint8) * 3);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
pixel[0] = (color >> 24) & 0xFF;
pixel[1] = (color >> 16) & 0xFF;
pixel[2] = (color >> 8) & 0xFF;
#else
pixel[0] = color & 0xFF;
pixel[1] = (color >> 8) & 0xFF;
pixel[2] = (color >> 16) & 0xFF;
#endif
}
void PutPixel16_nolock(SDL_Surface * surface, int x, int y, Uint32 color)
{
Uint8 * pixel = (Uint8*)surface->pixels;
pixel += (y * surface->pitch) + (x * sizeof(Uint16));
*((Uint16*)pixel) = color & 0xFFFF;
}
void PutPixel8_nolock(SDL_Surface * surface, int x, int y, Uint32 color)
{
Uint8 * pixel = (Uint8*)surface->pixels;
pixel += (y * surface->pitch) + (x * sizeof(Uint8));
*pixel = color & 0xFF;
}
//this function draws a pixel of wanted color on a surface at (x,y) coordinate
void draw_pixel_nolock(SDL_Surface *surface, int x, int y, SDL_Color s_color)
{ exit(19);//exit code is 3
//SDL_MapRGB return a color map depending on bpp (definition)
Uint32 color = SDL_MapRGB(surface->format, s_color.r, s_color.g, s_color.b);
//byte per pixel
int bpp = surface->format->BytesPerPixel;
//here is checked the number of byte used by our surface
switch (bpp)
{
case 1: // 1 byte => 8-bpp
PutPixel8_nolock(surface, x, y, color);
break;
case 2: // 2 byte => 16-bpp
PutPixel16_nolock(surface, x, y, color);
break;
case 3: // 3 byte => 24-bpp
PutPixel24_nolock(surface, x, y, color);
break;
case 4: // 4 byte => 32-bpp
PutPixel32_nolock(surface, x, y, color);
break;
}
}
私がそこを出ると、コードはエラーコード18を返しますが、エラーコード19を返すことはなく、代わりにエラーコード3を返します。何がうまくいかない可能性がありますか?