Strange bug with cutLoadPGMf

I’ve run into a really strange bug with cutLoadPGMf. The image loads perfectly fine, but I get an error when attempting to free up the allocated memory:

float *h_f1 = NULL;

char *image_filename = "lena_bw.pgm";

char* image_path = cutFindFilePath(image_filename, argv[0]);

if (image_path == 0) {

        printf("Unable to source file file\n");

        exit(EXIT_FAILURE);

    }

CUT_SAFE_CALL(cutLoadPGMf(image_path, &h_f1, &width, &height));

free(h_f1);

I get a heap corruption error on the last line. This occurs when I use my own custom PGM files with the loader. Even weirder, the simpleTextures example works just fine for me, but when I try to load the lena_bw.pgm file from that sample in my own code, I get a “DEBUG ASSERTION” error at the cutLoadPGMf line.

Absolutely no idea what could be happening, the code looks identical to me. The other strange thing is the exact same code worked just fine in Linux :blink:

Any help would be greatly appreciated!

There’s a note in cutil.h:

“If a NULL pointer is passed to this function and it is initialized within Cutil then cutFree() has to be used to deallocate the memory.”

I’m guessing that’s the problem.

edit: looking at simpleTexture, they don’t use cutFree, but hey, give it a shot anyway.

Awesome, that did the trick! I wonder why it works in Linux and the simpleTextures XP demo but not with my own code?

Go figure :)