LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Out-of-bounds pointer argument (before start of memory block)

Hi.
I am getting the following error code in an image analysis function
funtion call:
cpmResults = imaqMatchColorPattern(image, imageTemplate,  &cpmOptions, searchRect, &numMatchesFound); )
Error message:
FATAL RUN-TIME ERROR:   "ImageProcessing.c", line 156, col 77, thread id 0x00001240:   Out-of-bounds pointer argument (before start of memory block).

with cpmOptions highlighted

interupting and variable watching cpmOptions shows that every member looks ok!

I've tried to declare a MatchColorPatternOptions* and allocate its memory before copying the address of cpmOptions into it and pass the pointer, same result!

Does anybody have an idea?
I am using CVI 8.0 and WinXP

Thanks heaps!
0 Kudos
Message 1 of 8
(4,959 Views)
Hi DocEye,
Which version of NI Vision (also called Vision Development Module) are you using?

I think your problem is related to the arguments given for MatchColorPatternOptions(). The documentation for the function lists the same description for numRanges and for numMatchesRequested - "Number of valid matches expected." However, I believe the numRanges argument should actually be the length of the angleRanges array you also pass into the function; this is a documentation error, I think. This was reported to R&D (# 43933) for further investigation in December. Currently, the CAR (Corrective Action Request) is still open.

So, what values are you passing in to numRanges, numMatchesRequested, and how long is the angleRanges array? And what happens if your numRanges argument is changed to describe the length of the array?
0 Kudos
Message 2 of 8
(4,919 Views)
Hi and thanks for your effort to solve this.
I am using NI Vision 8.0 Development Module.
When I call the function
numMatchesRequested = 5
and numRanges = 2

The angleRange array is filled:
    for (i = 0 ; i < 2 ; i++)
    {
        angleRange[i].lower = angleRangeMin[i];
        angleRange[i].upper = angleRangeMax[i];
    }

They are getting the following values assigned:
cpmOptions.angleRanges[0].lower = -180.00
cpmOptions.angleRanges[0].upper = 180.00
cpmOptions.angleRanges[1].lower = 0
cpmOptions.angleRanges[1].upper = 0

I've played a little bit with the numRanges and numMatchesRequested (making them 1) but I am getting the same error message.

Thanks tons for your help and excellent support!



0 Kudos
Message 3 of 8
(4,897 Views)
Hi DocEye,
A colleague of mine also had a customer with a similar issue and he performed more testing on the issue using his computer, mine, and another. What we found was that the issue happened in CVI 8.0 and CVI 8.5, but not 8.1 for some reason. This was reported to R&D (107827) for further investigation. As a workaround, he found that you can set numRanges = 0 and the function should run. However, I am not sure at this time if that would also disable the ability to match for rotated patterns - I assume it would disable the ability. If you don't need to match for rotated patterns, I think that will get you sorted out for now.
0 Kudos
Message 4 of 8
(4,870 Views)

Hi, I am trying to make a simple program to turn a set of check boxes into a binary number and I am getting the same error as above. My function reads:

 

int CVICALLBACK set (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{
    switch (event)
    {
        case EVENT_COMMIT:
            int i;
            char hexa[9];
            char str[8];
            char num[2];
            for(i=0;i<8;i++){
                char *str="chan";
                Fmt(num,"%s<%i",i);
                strcat(str, num);
                if(strcmp(str,"1")==0)
                {
                    hexa[i]=1;
                }
                else
                {
                    hexa[i]=0;
                }
            }
                SetCtrlVal (panelHandle, PANEL_STRING, hexa);
                
            break;
    }
    return 0;
}


The code compiles, but once the executable is ran the following message is given:

 

FATAL RUN-TIME ERROR:   "active_channel.c", line 48, col 29, thread id 0x00001528:   Out-of-bounds pointer argument (before start of memory block).

 

The issue seems to be with num in the strcat line. In the debugging mode, the value given for num is the corect one.

 

Thanks for any help,

Humberto

0 Kudos
Message 5 of 8
(4,367 Views)

Hello Re_lambda,

what do you exactly intend to do with this code?

Here a few comments on it:

 

char hexa[9];
char str[8];
char num[2];

 

for (i = 0; i < 8; i++){
   char *str="chan";

   // Do you want to define a new variable or simply assign a value to 'str'? In the second case use strcpy instead


   Fmt(num,"%s<%i",i);     // 'num' will have values "0" through "7"
   strcat(str, num);       // 'str' will have values "chan0" through "chan7"

   if(strcmp(str,"1")==0)

   // This test will always fail as "chanx" is evidently different from "0" whichever is the value of x!
      hexa[i]=1;
   else
      hexa[i]=0;
   }

 

   SetCtrlVal (panelHandle, PANEL_STRING, hexa);

   // Regardless the result of the preceding loop, you will see nothing in the string control as neither '0' nor '1' are printable characters! Moreover, SetCtrlVal will stop at the first '0' found, as it is the standard string terminator in C


 

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 8
(4,351 Views)

Hi Roberto,

 

Thanks for the quick reply. In my GUI panel I have eight check boxes, with Constant names chan0 through chan7. I want to create a string (hexa) which will contain an 8-bit binary number from the check boxes. If the check box is checked it'll become a one, or a zero vice versa. You are right that my strcmp is incorrect. I have changed it, but I am still not sure I can achieve what I want from the if statement. 


            for(i=0;i<8;i++){
                char *str="chan";
                Fmt(num,"%s<%i",i);
                strcat(str, num);
                if(*str==1)
                {
                    hexa[i]=1;
                }
                else
                {
                    hexa[i]=0;
                }


For the if statement, I am looking to compare the value from the chanx constants (which should be one if the box is checked), and then translate this to a value in the binary number. I am still not able to get at least all zeroes in the binary because of the out-of-bounds error.

 

Thanks again for the help.

 

0 Kudos
Message 7 of 8
(4,345 Views)

Well, first of all, you are not reading actual checkbox values in any point in your loop... And you cannot address controls with their constant name only: you always need to use panel_control syntax. Nevertheless, panel_control is build up as a macro when the UIR is saved, and it's this macro you must use to address controls (you cannot use a string as the control ID parameter in a function call even if formatted in a proper way).

 

I normally operate via an array of control IDs, this way:

 

int   ctl[8];     // Array of control IDs

int   val = 0;    // Resulting value

char   msg[9];    // String to display the value in binary format


// Fill the array with control IDs

ctl[0] = PANEL_chan0;

ctl[1] = PANEL_chan1;

...

ctl[7] = PANEL_chan7;


for (i = 0; i < 8; i++) {

   GetCtrlVal (panelHandle, ctl[i], &hexa[i]);  // Read checkbox value

   val += (hexa[i] << i);    // Build the binary value

   msg[7 - i] = a[i] ? '1' : '0';   // Build up the string

}


SetCtrlVal (panelHandle, PANEL_STRING, msg);  // Display string



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 8 of 8
(4,333 Views)