Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Using imgDisposeBuffer with VS 2005

I'm using IMAQ in VisualStudio 2005, writing C++ (CLR). Things work fine with IMAQ until I attempt release a buffer using the imgDisposeBuffer function. When I do that, DisposeBuffer returns status xbff600a0 which I believe means "The given buffer wan't created by the NI-IMAQ driver." This surprises me since the buffer was, in fact, allocated using imgCreateBuffer.

What are the possible causes for imgDisposeBuffer to return that status? Does this indicate memory corruption?

TIA -

James Crain

Code follows ----------------------
I allocate 6 or 7 buffers using imgCreateBuffer, fill them with calls to imgSnap, and then call imgDisposeBuffer. There are no buffer lists, rings or other advanced features being used. It's a very plain vanilla use of IMAQ.

Buffer allocation:

typedef uInt16*                PWORD;

mpBuffers = new PWORD[mBandCount];
for (i = 0; i < mBandCount && imgStatus == IMG_ERR_GOOD; i++)    {
    imgStatus = imgCreateBuffer (mSID, IMG_HOST_FRAME,
                                         lSize, (void **) &mpBuffers[i]);
}


Buffer use:

IMAQ_STATUS snapFrame (int Band)        {
    System::Int32    imgStatus = IMG_ERR_GOOD;

    imgStatus = imgSnap (mSID, (void **) &mpBuffers[Band]);
    return imgStatus;
}

Buffer disposal:

for (i = 0; i < mBandCount; i++)    {
    imgStatus = imgDisposeBuffer (mpBuffers[i]);
}
delete [] pBuffers;
0 Kudos
Message 1 of 3
(3,064 Views)
Hello James,

I noticed that you posted this exact question to another forum post found here:  http://forums.ni.com/ni/board/message?board.id=232&message.id=4467  Since that post has the most current information contained in it, please refer it for future reference.

Regards,
Luke H

0 Kudos
Message 2 of 3
(3,047 Views)

Luke

Thanks for the reply. What it turned out to be was a type difference between the way I had declared the function in my header file and the way I was calling it at runtime.

In case anyone else is interested, here are the details:

1. Function declaration:

typedef long  IMAQ_STATUS;

#define IMAQ_PREFIX [DllImport("Imaq.dll")]

IMAQ_PREFIX IMAQ_STATUS imgDisposeBuffer(void* bufferPtr);

2. Invocation that returns error (and does not release memory):

 imgStatus = imgDisposeBuffer (pBuffers[i]);

3. CAST, then invocation doesn't return error (and does release memory):

imgStatus = imgDisposeBuffer ((void *) pBuffers[i]);

0 Kudos
Message 3 of 3
(3,013 Views)