Memory allocation error [ SOLVED ]
Posted: 2014-08-26T11:18:13-07:00
I have a c++ program that processes an image and does several things with it, in the following order:
- if needed, resizes or extents it to 48 pixels high
- flattens it if it has a matte
- creates a copy of the resized image so I have two variables to work with, a thumbnail_Img and process_Img
- writes the thumbnail_Img to disk
- reads the process_Img pixel by pixel and writes out a binary file containing individual RGB values for each pixel
- creates an Arc image from process_Img
- writes that Arc image to disk
Now, when I run this against a bunch of images in a folder, it works fine if I do each image individually, so in bash if I do something like this, it works great:
However, if I were to run it as a wildcard, it fails:
But notice how in the middle of the failures, one of them processed correctly (one before last.) I also notice that it's always failing during the thumbnail writing process. So this makes me wonder if there's something I need to be clearing, some memory space, or variable ... Can anyone suggest what I should start looking for, possibly changing, or adding test code to figure out where or what's causing the failure?
- if needed, resizes or extents it to 48 pixels high
- flattens it if it has a matte
- creates a copy of the resized image so I have two variables to work with, a thumbnail_Img and process_Img
- writes the thumbnail_Img to disk
- reads the process_Img pixel by pixel and writes out a binary file containing individual RGB values for each pixel
- creates an Arc image from process_Img
- writes that Arc image to disk
Now, when I run this against a bunch of images in a folder, it works fine if I do each image individually, so in bash if I do something like this, it works great:
Code: Select all
$ for file in * ; do ./getpx $file ; done
Processing 001.png : RESIZING: 2880 x 1800 -> 77 x 48 +MTLW+ 6 | Amps: 0.23 (side), 0.91 (total)
Processing 002.jpg : RESIZING: 400 x 400 -> 48 x 48 -MTLW+ 8 | Amps: 0.62 (side), 2.50 (total)
Processing 003.jpg : RESIZING: 1280 x 960 -> 64 x 48 -MTLW+ 8 | Amps: 0.28 (side), 1.13 (total)
Processing bluediag.gif : RESIZING: 400 x 160 -> 120 x 48 -MTLW+ 4 | Amps: 1.11 (side), 4.43 (total)
Processing cc02.bmp : OK! 44 x 48 -MTLW+10 | Amps: 1.06 (side), 4.25 (total)
Processing celtic1.png : RESIZING: 600 x 558 -> 52 x 48 +MTLW+ 8 | Amps: 0.64 (side), 2.57 (total)
Processing celtic.bmp : OK! 102 x 48 -MTLW+ 4 | Amps: 1.07 (side), 4.30 (total)
Code: Select all
$ ./getpx *
Processing 001.png : RESIZING: 2880 x 1800 -> 77 x 48 +MTLW+ 6 | Amps: 0.23 (side), 0.91 (total)
Processing 002.jpg : RESIZING: 400 x 400 -> 48 x 48 +MCaught Magick++ exception: getpx: memory allocation failed `002-thumb.png' @ error/png.c/WriteOnePNGImage/8866
Processing 003.jpg : RESIZING: 1280 x 960 -> 64 x 48 +MCaught Magick++ exception: getpx: memory allocation failed `003-thumb.png' @ error/png.c/WriteOnePNGImage/8866
Processing cc02.bmp : OK! 44 x 48 +MCaught Magick++ exception: getpx: memory allocation failed `cc02-thumb.png' @ error/png.c/WriteOnePNGImage/8866
Processing bluediag.gif : RESIZING: 400 x 160 -> 120 x 48 +MCaught Magick++ exception: getpx: memory allocation failed `bluediag-thumb.png' @ error/png.c/WriteOnePNGImage/8866
Processing celtic1.png : RESIZING: 600 x 558 -> 52 x 48 +MTLW+ 8 | Amps: 2.31 (side), 9.25 (total)
Processing celtic.bmp : OK! 102 x 48 +MCaught Magick++ exception: getpx: memory allocation failed `celtic-thumb.png' @ error/png.c/WriteOnePNGImage/8866