2011-01-27 2 views
-2

la compilation est correcte, mais le programme est arrêté dans cette fonction. Je version pour gagner et fonctionner très bien, mais quand je fais version pour Mac, il arrive cette exception :(programme obtenir EXC_BAD_ACCESS

 
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);

}

nageoire char [25] = "FIN/finale"; 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; }

+3

formatez votre code s'il vous plaît. mettez-le en surbrillance et cliquez sur le bouton "{}". cela aidera d'autres personnes à le lire. – BlackBear

+1

Publiez une liste minimale complète qui démontre le problème. – genpfault

Répondre

2

Le code suivant est très suspect:

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

D'une part, ceux-ci devraient probablement être omble chevalier et non char * mais le plus gros problème est que vous allouez des structures de données énormes sur la pile (2,5 MB pour chaque tableau, comme écrit). Je devine que vous dépassez votre pile disponible. Ils devraient plutôt être alloués dynamiquement (et dimensionnés correctement).

+0

Par exemple, 'std :: vector pixels (400 * 400 * 4);' –

Questions connexes