程序获取 EXC_BAD_ACCESS

发布于 2024-10-14 19:01:32 字数 3670 浏览 1 评论 0原文

编译没问题,但是程序在这个函数中停止了。我有 win 版本并且功能正常,但是当我为 Mac 制作版本时,它得到了这个异常:(

 int Reconstruct(int rez)
{ //here is program stopped!!!!

静态 SDL_Surface *projekce; 静态SDL_Surface *sc; 静态SDL_Surface *rek;

项目 = SDL_CreateRGBSurface(SDL_SWSURFACE,240,240, 32,0,0,0,0); sc = SDL_CreateRGBSurface(SDL_SWSURFACE, 400, 400, 32, 0, 0, 0, 0); // 创建两个无符号字节(字符)数组。每像素 4 字节 (RGBA) 无符号字符*像素[400 * 400 * 4]; 无符号字符 *pixelsbuf[400 * 400 * 4];

glGenTextures(1, &gl_texture);//生成一张纹理 glBindTexture(GL_TEXTURE_2D, gl_texture);// 设置纹理

// 设置纹理滤镜 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

整数角度 = 0; int 斯尼梅克 = 0; int i, j, k, l;// promene pro 循环

for(i=0;i<88;i++) {

char nazev[25] = "OUT/snimek"; itoa(snimek, CisloSnimku); strcat(nazev,CisloSnimku); strcat(nazev,".bmp"); rek = IMG_Load(nazev); 斯尼梅克++;

SDL_LockSurface(rek); SDL_LockSurface(项目);

//zkopiruj radek do snimku = vytvor simik pro rotaci

for(j=0;j<240;j++) { if(j == 0) PixV1 = 0; 别的 { PixV1 = getpixel(rek,j-1,rez); } if(j == 239) PixV3 = 0; 别的 { PixV3 = getpixel(rek,j+1,rez); } PixV2 = getpixel(rek,j,rez);

SDL_GetRGB(PixV1,rek->格式, &R, &G, &B); //Gs1 = ((R * 21) + (G * 61) + (B * 174)) / 256; //preved 做灰度专业蓝色 Gs1 = ((R * 11) + (G * 174) + (B * 71)) / 256; //preved 做灰度专业绿色 Gs1 = 255 - Gs1; //倒置 如果(Gs1<50)Gs1=1; SDL_GetRGB(PixV2,rek->格式, &R, &G, &B); //Gs2 = ((R * 21) + (G * 61) + (B * 174)) / 256; //preved 做灰度专业蓝色 Gs2 = ((R * 11) + (G * 174) + (B * 71)) / 256; //preved 做灰度专业绿色 Gs2 = 255 - Gs2; //倒置 如果(Gs2<50)Gs2=1; SDL_GetRGB(PixV3,rek->格式, &R, &G, &B); //Gs3 = ((R * 21) + (G * 61) + (B * 174)) / 256; //preved 做灰度专业蓝色 Gs3 = ((R * 11) + (G * 174) + (B * 71)) / 256; //preved 做灰度专业绿色 Gs3 = 255 - Gs3; //倒置 如果(Gs3<50)Gs3=1; //Gs = (Gs1*(1)) + (Gs2*(-4)) + (Gs3*(1)); //卷积​​好 //Gs = (Gs1*(-1)) + (Gs2*(3)) + (Gs3*(-1)); //卷积

​​ for(k=0;k<240;k++) { DrawPixel(projekce, j, k, Gs2, Gs2, Gs2); } SDL_UnlockSurface

(rek); SDL_UnlockSurface(项目);

gluBuild2DMipmaps(GL_TEXTURE_2D, 3, projekce->w, projekce->h, GL_RGBA, GL_UNSIGNED_BYTE, projekce->像素);
角度 += 360/88;
Atlantis_Display(角度);

/////////////////////////////////////////////////////////// //////////////////////////

glReadPixels(0, 0, 400, 400, GL_RGBA, GL_UNSIGNED_BYTE, Pixelsbuf);

/////////////////////////////////////////////////////////// ///////////////////////////

SDL_LockSurface(sc); SDL_LockSurface(最终);

G1=0; G = 0; R = 0; B=0;

对于(l=0;l<400;l++) { memcpy(像素+(400-l-1)*400*4, 像素buf+l*400*4, 400*4); sc->像素=像素;

for(j=0;j<400;j++) {

PixelValue = getpixel(sc, j, l); SDL_GetRGB(PixelValue, sc->format, &R, &G, &B); PixelValue = getpixel(final, j, l); SDL_GetRGB(PixelValue, final->format, &R1, &G1, &B1); //pom = ((R/2)+(B/2)+(G*2)); G1 += (G/90); DrawPixel(final, j, l, G1, G1, G1);

} SDL_UnlockSurface

(sc);

}

char fin[25] = "FIN/最终"; itoa(rez, CisloSnimku); strcat(fin,CisloSnimku); strcat(fin,".bmp"); SDL_SaveBMP(最终, fin); SDL_UnlockSurface(最终);

SDL_FreeSurface(最终); SDL_FreeSurface(sc); SDL_FreeSurface(项目); SDL_FreeSurface(rek); SDL_Quit(); 返回0; }

compilation is ok, but the program is stopped in this function. I have version for win and it function fine, but when i make version for Mac, it get this exception :(

 int Reconstruct(int rez)
{ //here is program stopped!!!!

static SDL_Surface *projekce; static SDL_Surface *sc; static SDL_Surface *rek;

projekce = SDL_CreateRGBSurface(SDL_SWSURFACE,240,240, 32,0,0,0,0); sc = SDL_CreateRGBSurface(SDL_SWSURFACE, 400, 400, 32, 0, 0, 0, 0); // Create two arrays of unsigned bytes (chars). 4 bytes per pixel (RGBA) unsigned char *pixels[400 * 400 * 4]; unsigned char *pixelsbuf[400 * 400 * 4];

glGenTextures(1, &gl_texture);// generate one texture glBindTexture(GL_TEXTURE_2D, gl_texture);// Set the texture

// Set the texture filters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

int angle = 0; int snimek = 0; int i, j, k, l;// promene pro cykly

for(i=0;i<88;i++) {

char nazev[25] = "OUT/snimek"; itoa(snimek, CisloSnimku); strcat(nazev,CisloSnimku); strcat(nazev,".bmp"); rek = IMG_Load(nazev); snimek++;

SDL_LockSurface(rek); SDL_LockSurface(projekce);

//zkopiruj radek do snimku = vytvor snimek pro rotaci

for(j=0;j<240;j++) { if(j == 0) PixV1 = 0; else { PixV1 = getpixel(rek,j-1,rez); } if(j == 239) PixV3 = 0; else { PixV3 = getpixel(rek,j+1,rez); } PixV2 = getpixel(rek,j,rez);

SDL_GetRGB(PixV1,rek->format, &R, &G, &B); //Gs1 = ((R * 21) + (G * 61) + (B * 174)) / 256; //preved do grayscale pro blue Gs1 = ((R * 11) + (G * 174) + (B * 71)) / 256; //preved do grayscale pro green Gs1 = 255 - Gs1; //invert if (Gs1 < 50) Gs1 = 1; SDL_GetRGB(PixV2,rek->format, &R, &G, &B); //Gs2 = ((R * 21) + (G * 61) + (B * 174)) / 256; //preved do grayscale pro blue Gs2 = ((R * 11) + (G * 174) + (B * 71)) / 256; //preved do grayscale pro green Gs2 = 255 - Gs2; //invert if (Gs2 < 50) Gs2 = 1; SDL_GetRGB(PixV3,rek->format, &R, &G, &B); //Gs3 = ((R * 21) + (G * 61) + (B * 174)) / 256; //preved do grayscale pro blue Gs3 = ((R * 11) + (G * 174) + (B * 71)) / 256; //preved do grayscale pro green Gs3 = 255 - Gs3; //invert if (Gs3 < 50) Gs3 = 1; //Gs = (Gs1*(1)) + (Gs2*(-4)) + (Gs3*(1)); //convolution GOOD //Gs = (Gs1*(-1)) + (Gs2*(3)) + (Gs3*(-1)); //convolution

for(k=0;k<240;k++) { DrawPixel(projekce, j, k, Gs2, Gs2, Gs2); } }

SDL_UnlockSurface(rek); SDL_UnlockSurface(projekce);

gluBuild2DMipmaps(GL_TEXTURE_2D, 3, projekce->w, projekce->h, GL_RGBA, GL_UNSIGNED_BYTE, projekce->pixels);
angle += 360/88;
Atlantis_Display(angle);

////////////////////////////////////////////////////////////////////////////

glReadPixels(0, 0, 400, 400, GL_RGBA, GL_UNSIGNED_BYTE, pixelsbuf);

////////////////////////////////////////////////////////////////////////////

SDL_LockSurface(sc); SDL_LockSurface(final);

G1 = 0; G = 0; R = 0; B = 0;

for(l=0;l<400;l++) { memcpy(pixels+(400-l-1)*400*4, pixelsbuf+l*400*4, 400*4); sc->pixels = pixels;

for(j=0;j<400;j++) {

PixelValue = getpixel(sc, j, l); SDL_GetRGB(PixelValue, sc->format, &R, &G, &B); PixelValue = getpixel(final, j, l); SDL_GetRGB(PixelValue, final->format, &R1, &G1, &B1); //pom = ((R/2)+(B/2)+(G*2)); G1 += (G/90); DrawPixel(final, j, l, G1, G1, G1);

}
}

SDL_UnlockSurface(sc);

}

char fin[25] = "FIN/final";
itoa(rez, CisloSnimku);
strcat(fin,CisloSnimku);
strcat(fin,".bmp");
SDL_SaveBMP(final, fin);
SDL_UnlockSurface(final);

SDL_FreeSurface(final);
SDL_FreeSurface(sc);
SDL_FreeSurface(projekce);
SDL_FreeSurface(rek);
SDL_Quit();
return 0;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

窝囊感情。 2024-10-21 19:01:32

以下代码非常可疑:

 unsigned char *pixels[400 * 400 * 4];
 unsigned char *pixelsbuf[400 * 400 * 4];

一方面,这些可能应该是 char 而不是 char *,但更大的问题是您在堆栈上分配巨大的数据结构(每个数组 2.5 MB,如所写)。我猜你已经超出了你的可用堆栈。相反,它们应该动态分配(并正确调整大小)。

The following code is highly suspect:

 unsigned char *pixels[400 * 400 * 4];
 unsigned char *pixelsbuf[400 * 400 * 4];

For one thing, those should probably be char and not char * but the bigger issue is that you are allocating enormous data structures on the stack (2.5 MB for each array, as written). I am guessing that you are exceeding your available stack. They should instead be dynamically allocated (and sized correctly).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文