I took this example from the documentation for SetPixel, i commented out Texture::Create and replaced it with Texture::Load but it crashes when doing memcpys but it doesn't if i don't load a texture and use Create instead. The texture loads fine, i'm able to display it.
Error:
HEAP[Test.debug.exe]: Heap block at 0655D900 modified at 0656192C past requested size of 4024
Test.debug.exe has triggered a breakpoint.
In App::Start
//texture = Texture::Create(256, 256);
texture = Texture::Load("mytexture.tex"); // texture is defined in App.h
//Create a buffer to store pixel data in
int datasize = texture->GetMipmapSize(0);
char* pixels = (char*)malloc(datasize);
//Get the pixel data from the texture and invert it
texture->GetPixels(pixels);
char r, g, b, a;
for (int x = 0; x<texture->GetWidth(); x++)
{
for (int y = 0; y<texture->GetHeight(); y++)
{
int p = (x*texture->GetWidth() + y) * 4;
memcpy(&r, pixels + p + 0, 1);
memcpy(&g, pixels + p + 1, 1);
memcpy(&b, pixels + p + 2, 1);
r = 255 - r;
g = 255 - g;
b = 255 - b;
memcpy(pixels + p + 0, &r, 1);
memcpy(pixels + p + 1, &g, 1);
memcpy(pixels + p + 2, &b, 1);
}
}
//Set the modified pixel data
texture->SetPixels(pixels);
free(pixels);
[c++] SetPixel/memcpy crash