Well I made Tex and Bitmap no longer a global variable.
I also checked the debugger and it says the problem is this section of the code.
if((i + 1) % padWidth == 0)
{
i += offset;
}
*(pixelData + j + 2) = *(tempPixelData + i);
*(pixelData + j + 1) = *(tempPixelData + i + 1);
*(pixelData + j) = *(tempPixelData + i + 2);
j++;
I tried deleting that part of the code and it worked but it didn't show the texture.
Any idea what could be wrong?

Find content
Not Telling