I am currently trying to update parts of a texture. Following is the case:
I got raw pixel data in RGBA (size: 1000*1000
pixels). I create a Texture with the same Pixelformat and the same size with SDL_TEXTUREACCESS_STREAMING.
Now I get dirty rects from my applications on which parts of the raw pixels have been updates (at least a 16x16 rect).
The Texture has a pitch or 1000*4 = 4000 bytes
.
Then I lock the texture with SDL_LockTexture, get a pitch of 4000 (which is correct). Lets assume I lock the rect (X Y W H) 900, 900, 100, 100
. Then ill copy the raw pixeldata with:
memcpy(pixels, raw_pixels+(900*pitch)+900, pitch*100)
And this creates a SIGSEGV.
Am I allowed to copy this way to pixels (I mean only 100x100 pixels are releavant, rest can be whatever it wants, right?). Or am I thinking wrong here?