Cocoa app crash very large image file

Discussion in 'Mac Programming' started by wilbur07, Oct 16, 2008.

  1. wilbur07 macrumors newbie

    Joined:
    Jun 18, 2008
    #1
    I'm working with large files and it seems that if I use a big enough image file my app crashes with a "[application] quit unexpectedly" modal box.

    The problem is when I try to work with NSImage and get the file size for height and width dimensions. I haven't even gotten to the part where my app displays the image or allows manipulation of the image. The file I'm working with is 1.05 Gb and it is an EPS file.

    I've googled to try to find an answer and I got several methods to break up a file into chunks when reading it, eg:

    > NSFileHandle *fh = [NSFileHandle fileHandleForReadingAtPath:
    > @"BigFile.txt"];
    >
    > assert(fh != NULL);
    >
    > unsigned len = 0;
    >
    > do
    > {
    > NSData * data = [fh availableData];
    > len = [data length];
    >
    > printf("data len: %d offset: %lld\n", len, [fh offsetInFile]);
    >
    > // release the data before reading more
    > // or the consequences will be quite unpleasant
    >
    > [data release];
    >
    > } while (len != 0);

    but I can't figure out how to make this work with NSImage object. I don't think you can initialize an NSImage object with these chunks of data and then call size method to get the size of the image and then size.height and size.width to get the dimensions of the image.

    Can anybody show me how to handle large files with NSImage?
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    That code above will crash because you're using [data release] on an object that you don't own. Remove that line and see what happens.

    If you're running out of memory, put in an extra autorelease pool in the loop somewhere.
     

Share This Page