Discussion:
crash in Imagmagick : what am I doing wrong?
Jouk Jansen
2011-10-10 07:17:40 UTC
Permalink
Hi All,

I'm running a program linked against ImageMagick SVN version 5365. However I
see some crashes in the routine below. The routine is designed to receive a
pixel map in pic_ and write that to an image file ins some format with the
specified filename. If I call the routine once it works OK. But now I'm
calling it many times with different filenames and pixelmaps. After 80 to 90
written files the routine stops writing the files, hangs a long time and
eventually crashes. In my home directory I find a rather large file called
python_tmpmagick-<random characters>.
It looks like some data is not reset properly. What did I forget to
deallocate/destroy?

Jouk
Code start<<<<<<<
#include <stdio.h>

#include <stdlib.h>

#include <memory.h>

#include <math.h>

#include <time.h>

#include <sys/types.h>

#include <stdarg.h>

#include <magick/api.h>

void
magick_write( char* filename , int* pic_ , int w_ , int h_ , char*
graph_type , int quality )
{
Image* imageData = (Image*) NULL;
ImageInfo imageInfo;
Quantum* pixels;
ExceptionInfo exception;
int i;

GetImageInfo( &imageInfo );
GetExceptionInfo( &exception );
imageInfo.dither = 0;
imageInfo.quality = quality;
imageInfo.colorspace = RGBColorspace;
imageData=AcquireImage( &imageInfo );
imageData->depth=8;
imageData->columns = w_;
imageData->rows = h_;
imageData->colors = 256;
imageData->matte = 0;
imageData->units=PixelsPerInchResolution;
imageData->x_resolution = imageData->y_resolution = 300;
imageData->page.width = 595;
imageData->page.height = 842;
imageData->page.x = imageData->page.y = 0;
AcquireImageColormap(imageData,imageData->colors , &exception );
imageData->storage_class = DirectClass;
pixels = GetAuthenticPixels( imageData , 0 , 0 , w_ , h_ , &exception );
for ( i=0; i < h_ * w_ ; i++ , pic_++ )
{
SetPixelRed( imageData , imageData->colormap[ *pic_ ].red , pixels );
SetPixelGreen( imageData , imageData->colormap[ *pic_ ].green , pixels
);
SetPixelBlue( imageData , imageData->colormap[ *pic_ ].blue , pixels );
pixels += GetPixelChannels( imageData );
}
SyncAuthenticPixels( imageData , &exception );
strcpy( imageData->magick, graph_type );
strcpy( imageData->filename, filename );
imageData->delay = 10;
WriteImage ( &imageInfo, imageData , &exception );
DestroyImage( imageData );
DestroyImageInfo( &imageInfo );
DestroyExceptionInfo( &exception );
}
Code end<<<<<<<
Pax, vel iniusta, utilior est quam iustissimum bellum.
(free after Marcus Tullius Cicero (106 b.Chr.-46 b.Chr.)
Epistularum ad Atticum 7.1.4.3)
------------------------------------------------------------------------------<
Jouk Jansen

***@hrem.nano.tudelft.nl

Technische Universiteit Delft tttttttttt uu uu ddddddd
Kavli Institute of Nanoscience tttttttttt uu uu dd dd
Nationaal centrum voor HREM tt uu uu dd dd
Lorentzweg 1 tt uu uu dd dd
2628 CJ Delft tt uu uu dd dd
Nederland tt uu uu dd dd
tel. 31-15-2782272 tt uuuuuuu ddddddd
------------------------------------------------------------------------------<
d***@imagemagick.org
2011-10-10 11:45:47 UTC
Permalink
Post by Jouk Jansen
I'm running a program linked against ImageMagick SVN version 5365.
The Subversion trunk is alpha level code. You probably want the stable
version of ImageMagick @ ImageMagick-6.7.3. If you do use ImageMagick-7.0.0-0,
use the MagickCore/MagickCore.h header rather than magick/api.h. Also check
to insure *pic_ is not negative or exceeds 256 for this line of code:

SetPixelRed( imageData , imageData->colormap[ *pic_ ].red ...

Finally, use gdb to identify the source line where the program faults.
Jouk Jansen
2011-10-11 07:45:03 UTC
Permalink
***@imagemagick.org
wrote on 10-OCT-2011 13:46:49.65
Post by Jouk Jansen
I'm running a program linked against ImageMagick SVN version 5365.
The Subversion trunk is alpha level code. You probably want the stable
I know, but it is part of testing the software. I'm running this on a
OpenVMS machine, but running the same program linked against a stable
version of Imagemagick on a linux system The program seems to behave
correctly.
If you do use ImageMagick-7.0.0-0,
use the MagickCore/MagickCore.h header rather than magick/api.h.
Good tip, I'll try this one
Also check
SetPixelRed( imageData , imageData->colormap[ *pic_ ].red ...
I'm prety sure its in the range from 0 to 255.
Finally, use gdb to identify the source line where the program faults.
When the program finally crashes is crashes at the line
SetPixelRed( imageData , imageData->colormap[ *pic_ ].red
but already before that the program stopped working correctly, which can be
seen by writeing this large file python-magick-xxxxx in my home directory.
So the line at which is crashes has probably no meaning at all

Jouk


Pax, vel iniusta, utilior est quam iustissimum bellum.
(free after Marcus Tullius Cicero (106 b.Chr.-46 b.Chr.)
Epistularum ad Atticum 7.1.4.3)
------------------------------------------------------------------------------<
Jouk Jansen

***@hrem.nano.tudelft.nl

Technische Universiteit Delft tttttttttt uu uu ddddddd
Kavli Institute of Nanoscience tttttttttt uu uu dd dd
Nationaal centrum voor HREM tt uu uu dd dd
Lorentzweg 1 tt uu uu dd dd
2628 CJ Delft tt uu uu dd dd
Nederland tt uu uu dd dd
tel. 31-15-2782272 tt uuuuuuu ddddddd
------------------------------------------------------------------------------<
Loading...