GameDevCorn said:
BYTE* memory = 0;
Well, fair enough. so this is "memory1". I don't know what you think this does, but in CPP this sets “memory1” to be a null-pointer. That is, it points to nothing.
GameDevCorn said:
A SDLSurface named tmpSurf. It gets loaded from IMG_LOAD("black.png"). The tmpSurf has blk pixels.
It's at this point I do the surfacelock.
BYTE *tPix = (BYTE *)tmpSur→pixels
So tmpSurf is allocated and managed by SDL, and you setup a pointer into that space.
GameDevCorn said:
tPix = memory1
Then you change the pointer to point at whatever memory 1 points (ie nothing). That's fine.
You don't show how you did unlocking etc here. I assume you used tmpSurf. That of course works. That is, setting up a pointer to some address and then pointing it to some other address doesn't do anything with the previously pointed-at spot.
If you used tPix here rather than tmpSurf, perhaps SDL has a special case if the supplied pointer in null? (due to the previous assignment)
GameDevCorn said:
Or, tried memcpy(tPix, memory1, sizeof(memory1)).
This won't fly for 2 reasons. First “memory1” points at null, and you can't copy data from “I point at nothing”, so a crash is the logical answer if you attempt it anyway. Secondly, “sizeof(memory1)” queries the size of the pointer, which is either 4 or 8 bytes on most machines. It's likely not enough to contain all pixels in the loaded image file.
In particular a pointer is exactly just a pointer (a finger pointing at a memory address). It doesn't know what it points at, it has no size of the thing it points at. Basically, it's a simple integer, as explained in https://www.freecodecamp.org/news/pointers-in-c-are-not-as-difficult-as-you-think/
In addition, it also doesn't handle memory allocation, it's your job to make sure it points into space that the program is allowed to access. Read may perhaps work (or it may not), write will definitely cause a crash due to the OS that guards processes not to try modifying memory that they don't own.