Strange SDL_UpdateTexture() behaviour

I believe its not working because when you are updating a rect, the pixels pointer needs to be set to the first pixel of the rect. it looks like you are passing a pointer to all the pixels in the image so SDL is going to treat that as if it were the pixels for the rect only so you are going to end up with whatever was in the top left rect of the entire buffer.

Try adding an offset to the pointer something like (you probably want to think though this longer than i did)
Code:
pixels + (pitch * rect.y) + rect.x

It could be that im completely wrong also :slight_smile:

This sounds like exactly what I already tried explaining to you. I never promised my code would work (in fact i made a disclaimer to the contrary); I was merely attempting to demonstrate that you need to pass an offset from your pixels array that corresponds to the rect you are trying to update, otherwise you are copying the pixels from the top left of your buffer (it is top left in SDL right?) which are not the pixels you actually change. This is why passing NULL works, because then its updating a rect equal to your entire image which means the top left pixel of the rect to update is in fact the pixels pointer you are passing; unlike when you are trying to update the subrect.

I dont know how to explain it more clearly; I’m sorry.

guido.gonzato wrote:> This is increasingly looking like a bug in SDL_UpdateTexture().

I happened to make it work in a very strange way. Let’s modify the code as follows:

Code:

// NOT WORKING:
SDL_UpdateTexture (texture, &rect, pixels, pitch);

// WORKING - update the whole texture
// SDL_UpdateTexture(texture, NULL, pixels, pitch);

That is, let’s uncomment out the “not working” code and comment out the “working” line.

Compile the program then click around; no pixels will be displayed. But if you keep clicking and manage to hit the (0, 0) pixel, voila! From now on, pixels will be correctly refreshed.

I’m really puzzled. Hints/ideas?

Thanks,
Guido