In the SDL_Surface structure, is there
a way to calculate the bounds of the pixels
Member?
I need a quicker way of doing this, so my code doesn't catch seg-faults while running.
On my Linux Laptop, my code runs a segfault when I run it there. On my Samsung A04e (Termux+vnc) It runs fine; there is absolutely no problem.
This is the gdb session output messages : https://imgur.com/a/Y30J0Zq
The code that is causing the seg fault. Is In my custom wrapper for freetype2. For performance/RAM reasons, I did not use SDL_ttf/SDL2_ttf.
Read code here :
for( uy = 0; uy < bm.rows; ++uy ) {
for( ux = 0; ux < bm.width; ++ux ) {
bitmap_alpha = bm.buffer[ ( bm.pitch * uy ) + ux ];
if( bitmap_alpha != 0 ) {
color_ptr->a = bitmap_alpha;
if(( (x+ux) <= canvas->w ) && ((y+uy) <= canvas->h) ) {
Transparent_Color = B2D_CalculateNewPixelAlphaColor(canvas,x+ux,y+uy,color_ptr );
B2D_DrawQuickPixel_WithoutTransparency(canvas, x+ux, y+uy, &Transparent_Color);
}
color_ptr->a = original_alpha;
}
}
}
The code within B2D_CalculateNewPixelAlphaColor() that caused the bug.
if(xpos < 0)
xpos = 1;
if(ypos < 0)
ypos = 1;
if(ypos >= canvas->h)
ypos = canvas->h;
if(xpos >= canvas->w)
xpos = canvas->w;
END_SUB
/* Step 1 - Get the color of the pixel we intend to overwrite.*/
/* I need the bounds checking here in the pixel array: HERE SPECIFICALLY */
SDL_Color destination_color;
SDL_GetRGBA (((Uint32*)canvas->pixels)[(ypos)*(canvas->pitch>>2)+xpos], canvas->format, &destination_color.r,&destination_color.g, &destination_color.b,&destination_color.a);
There is nothing wrong with this code I wrote it in 2023, and it worked for years But just after I updated my distro last week... Nothing is working.
I am running low on time, and I'm quite busy. I want to shut the debugger up so I can finish writing my code and deploy it.
I need a way to perform a bounds check on the sdl_surface->pixels member. I looked online on GitHub, and found some of what I wanted in (src/video/SDL_Surface.c) (line 94 and Line 64)
The function called
bool SDL_CalculateSurfaceSize()
But ... I want to know if someone here on this platform knows something that I don't before I try something that may or may not work.
I need to know how much was allocated, So I can cache it in my local code, so I put an end to these annoyances.
EDIT After a reboot, recompile the bug is gone... but the question is still valid.
( bm.pitch * uy ) + uxmaybe it should be( bm.width * uy ) + ux?pixelspointer fromvoid *toUint32 *. That could be right, or it could be wrong. Presumably, the original type is declared asvoid *because the pointed-to elements can be of different type depending on the circumstances.bm.pitch * uymay well be right.