I believe you're looking in the wrong place.
These kind of problems often come from memory corruptions, buffer overruns, etc.
I have seen that you're using a some (const char*)s and memcpy's in the code you posted and I tend to believe that you also use these in other parts of your code.
As I am sure you know, if they are not used correctly, they don't work. There is no middle way - you cannot use them just in part correctly.
So you could take a look again on all that.
Also, if you can, post the code where you're loading the image from disk.
Regards
Bookmarks