0
표면의 픽셀을 읽고 가장 밝은 픽셀의 인덱스를 다른 배열에 씁니다. gdb를 사용하여 픽셀 배열의 모든 값이 정확히 3/4이되고, 그 점에서 정확히 1020 픽셀 후에 segfaults가됩니다. 이 코드는 다음과 같습니다.표면의 SDL 픽셀은 0 3/4의 길이가됩니다.
void scanBrightPixels(int** write_to, int* pcount, SDL_Surface* image) {
SDL_PixelFormat* f = image->format;
SDL_LockSurface(image);
Uint32* pixels = (Uint32*) image->pixels;
SDL_UnlockSurface(image);
int lpcount = 0;
for (int i = 0; i < image->w * image->h/4 * 3; i++) {
Uint8 r, g, b;
Uint8 brightness;
SDL_GetRGB(pixels[i], f, &r, &g, &b); // this is where the segfault happens
brightness = (Uint8) ((r * 0.33) + (g * 0.5) + (b * 0.16));
if (brightness >= 251) {
(*write_to)[lpcount] = i;
lpcount++;
}
}
*pcount = lpcount;
}
이 함수는 std :: async에서도 호출됩니다. 어떤 아이디어?