LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Code with GetImagePixelPtr crashes


I need to do some code with the GetImgPixelPointer VI to access the image raw data directly.
I did that to avoid the imageToArray and ArrayToImg overhead.

The code crashes and I write a very simple version of the code, it still crashes.

The tiny C code just copies one image to the other image. It works well outside of the Labview but once it is in the Labview environment, the Labview crashes.
Anything wrong with my understanding of the GetImgPixelPointer VI ?

Could someone help me with this question?

I attached my Labview code and the small C code which is written as a DLL.

Thanks

0 Kudos
Message 1 of 4
(2,535 Views)
Are you at any point resizing any arrays or declaring new variables within your external code? If you don't use appropriate memory management functions from extcode.h, then LabVIEW will not be notified of these operations and it won't be able to deallocate this memory. It might also try to write over it when declaring its own variables. This is the most common cause for crashes when calling external code from LabVIEW.
Jarrod S.
National Instruments
0 Kudos
Message 2 of 4
(2,525 Views)
 I am not allocating any new memory or variables in the DLL code. All memories are allocated outside of the call and put in proper size.
I assume the memory of a image do not change if I do not change the size of the image from its original size.

The code is as simple as this:


short imgGen(unsigned char *LVTmplImg, unsigned char *LVgentImg,
    long LineWidthT, long LineWidthG, long imgWidth, long imgHeight)
    {

        unsigned char * timg[700], * gimg[700];
        unsigned char * pt = LVTmplImg;
        unsigned char * pg = LVgentImg;
        long i;

       if (imgHeight > 700)
            return 1;

        for (i=0; i<imgHeight; i++) {
            timg[i] = pt;
            pt += LineWidthT;
            gimg[i] = pg;
            pg += LineWidthG;
        }
       
        for (i=0; i<imgHeight; i++) {
            pg=gimg[i];
            pt=timg[i];
            memcpy (pg, pt, imgWidth*sizeof(unsigned char));             
        }
        return 0;
    }


Message Edited by mehmetg on 03-19-2006 01:23 AM

0 Kudos
Message 3 of 4
(2,517 Views)

It seems curious that IMAQGetImagePixelPtr.vi outputs an unsigned 32-bit integer for the pixel pointer, but you wire this into your DLL directly as a unsigned char *, a pointer to an 8-bit unsigned integer. LabVIEW should coerce the 32-bit value to an 8-bit value before passing it into the DLL, but at that point you're probably trying to access an invalid truncated pointer value. I can only imagine this would crash LabVIEW. Is there a reason you're doing this?

 

Message Edited by Jarrod S. on 03-20-200605:33 PM

Jarrod S.
National Instruments
0 Kudos
Message 4 of 4
(2,502 Views)