SDL: warum bekomm ich hier eine zugriffsverltzung?



  • SDL_Surface* halfScaleSurface(SDL_Surface *from)
    {
    	SDL_Surface *to = SDL_CreateRGBSurface( SDL_SWSURFACE, from->w/2, from->h/2, from->format->BitsPerPixel, from->format->Rmask, from->format->Gmask, from->format->Bmask, from->format->Amask );
    	Uint32 *spixels = (Uint32*)from->pixels;
    	Uint32 *tpixels = (Uint32*)to->pixels;
    	int r,g,b;
    	Uint8 rt,gt,bt;
    	for(int x = 0; x < from->w-1; x+=2)
    	{
    		for(int y = 0; y < from->h-1; y+=2)
    		{
    			r=0;
    			g=0;
    			b=0;
    			SDL_GetRGB(spixels[ ( y * from->w ) + x ], from->format,&rt,&gt,&bt);
    			r+=rt;
    			g+=gt;
    			b+=bt;
    			y+=1;
    			SDL_GetRGB(spixels[ ( y * from->w ) + x ], from->format,&rt,&gt,&bt); //DIESE zeile gibt mir jedesmal eine zugriffsverletzung! und zwar lade ich ein bild mit 1024x1024 pixeln, und in zeile 768 (+1) bekomm ich den fehler?!
    			r+=rt;
    			g+=gt;
    			b+=bt;
    			x+=1;
    			SDL_GetRGB(spixels[ ( y * from->w ) + x ], from->format,&rt,&gt,&bt);
    			r+=rt;
    			g+=gt;
    			b+=bt;
    			y-=1;
    			SDL_GetRGB(spixels[ ( y * from->w ) + x ], from->format,&rt,&gt,&bt);
    			r+=rt;
    			g+=gt;
    			b+=bt;
    			x-=1;
    			r/=4;
    			g/=4;
    			b/=4;
    
    			tpixels[ ( (y/2) * to->w ) + (x/2) ] = SDL_MapRGB(to->format, r, g, b);
    		}
    	}
    	return to;
    }
    


  • Das kann dir wohl nur dein Debugger sagen, d.h. überprüf einfach mal die Werte der ganzen Variablen: x, y, from->w ...
    Du greifst anscheinend auf einen falschen Index zu.


Anmelden zum Antworten