I don't really know what's wrong (mainly because I don't know what the line that gives me an error does).
I don't think I have to show you that much code. What I'm doing is that I'm trying to get the RGBA values of a pixel to see how great the Alpha value is. I'm using this to determine if there's a collision within their rectangles or not.
This is what I have:
bool Texture2D::GetPixelAlphaValue(Vector2 pixel)
{
int bpp = surface->format->BytesPerPixel;
Uint8* p = (Uint8*) surface->pixels + (int) pixel.y * surface->pitch + (int) pixel.x * bpp);
Uint32 pixelColor = *(Uint32*)p;
Uint8 red, green, blue, alpha;
SDL_GetRGBA(pixelColor, surface->format, &red, &green, &blue, &alpha);
return alpha > 250;
}
I'm pretty sure my collision is good up to this, what I do is I check if rectangle intersects, I create an rectangle of the intersection and then check every pixel within the intersect rectangle.
This results in once I have a pixel perfect collision in screen the game crashes and I get an arrow pointing at:
Uint32 pixelColor = *(Uint32*)p;
With the error:
Unhandled exception at 0x000393b4 in OpenGLSDLTest.exe: 0xC0000005: Access violation reading location 0x063b6fd0.
This is the line that I don't understand, could someone please explain what this line is doing and how I can solve this?
Kind regards
Markus