I'm not seeing much, is bitmap->pixels a (u8*) and not a (u32*)?
The only things I could see cause a crash is accessing a bad pointer or writing out of memory.
If Flipped is fine and bitmap is correct, then the loop it self is doing the deed. I think you just need print some debug messages and find exactly what line it crashes on.
ARM Cores do not really care if (u8*) or (u32*) because they're all rounded to 4 bytes long when static variable is assigned except the hardware is limited to u8/u16/u32 read/writes or if you want your access to be width-fixed. But you may be getting there ..
Yes, i've just done sanity checks and function doesn't report me any problem.
Anyway even if i use memcpy, result are the same, console still crashes.
Code:Bitmap* bitmap = (Bitmap*)luaL_checkinteger(L, 1); if(!bitmap) return luaL_error(L, "Error loading image"); u8* flipped = (u8*)malloc(bitmap->width*bitmap->height*4); for (int y = 0; y < bitmap->height; y++){ memcpy(&flipped[y*bitmap->width*4], &bitmap->pixels[(bitmap->height - y - 1) * bitmap->width * 4], bitmap->width * 4); } free(bitmap->pixels); bitmap->pixels = flipped;
aside that, shouldnt :
Code:
for (int y = 0; y < bitmap->height; y++){
for (int x = 0; x < bitmap->width; x++){
*(u32*)(&(flipped[(x+y * bitmap->width)*4])) = *(u32*)&(bitmap->pixels[(x + (bitmap->height - y - 1) * bitmap->width)*4]);
}
}
be instead
Code:
for (int y = 0; y < bitmap->height/4; y++){
for (int x = 0; x < bitmap->width/4; x++){
*(u32*)(&(flipped[(x+y * bitmap->width)*4])) = *(u32*)&(bitmap->pixels[(x + (bitmap->height - y - 1) * bitmap->width)*4]);
}
}
Pretty sure you're allocating four times your currently drawn line, while your loop memory access should match the new boundary requirement that is already *4. So divided by four your get the required boundary step index access done by the loop