Im writing a project in Objective-C but I'm relying quite much on plain old C since there's OpenGL involved.
I have a data blob that I read to memory from a file in the following way:
NSString *path = [[NSBundle mainBundle] pathForResource:@"iPadTest" ofType:@""];
NSFileHandle *file = [NSFileHandle fileHandleForReadingAtPath:path];
data = [file readDataToEndOfFile];
currentImage = [ReadDataFiles getOrganizedImageData:data];
The last function gives me a structure where the data is a little more accessible but there is still three lengthy data blobs of image data. It begins like this:
ImageData *organizedImageData = malloc(sizeof(ImageData));
// IMAGE DIMENSIONS
UInt64 *rawData = (UInt64 *) data.bytes;
organizedImageData->imageDimensions.x = *rawData;
rawData++;
organizedImageData->imageDimensions.y = *rawData;
rawData++;
organizedImageData->imageDimensions.z = *rawData;
// IMAGE 1
rawData++;
organizedImageData->image1Data = (UInt8*)rawData;
// IMAGE 2
rawData++;
organizedImageData->image2Data = (UInt8*)rawData;
// etc...
The problem is that when the data reaches the OpenGL functions something else has written in the same memory. The result is different every time but the data is never persistent.
When I tell the debugger to pause when those adresses are beeing changed I end up in assembly code that I don't can make anything ou of.
How and where should i allocate the memory space so that the rest of the program doesn't fool with it?